Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package com.sun.enterprise.connectors;
 
 
 import  javax.resource.spi.ManagedConnectionFactory;
 import java.util.*;
This is an registry class which holds various objects in hashMaps, hash tables, and vectors. These objects are updated and queried during various funtionalities of rar deployment/undeployment, resource creation/destruction Ex. of these objects are ResourcesAdapter instances, security maps for pool managed connection factories. It follows singleton pattern. i.e only one instance at any point of time.

Author(s):
Binod P.G and Srikanth P
 
 
 public class ConnectorRegistry {
 
     static final Logger _logger = LogDomains.getLogger(ConnectorRegistry.class.);
 
     protected static final ConnectorRegistry connectorRegistryInstance = new ConnectorRegistry();

    
resourceAdapters keeps track of all active resource adapters in the connector runtime. String:resourceadapterName Vs ActiveResourceAdapter
 
     protected final Map<StringActiveResourceAdapterresourceAdapters;
 
     protected final Map<PoolInfoPoolMetaDatafactories;
     protected final Map<StringResourceAdapterConfigresourceAdapterConfig;
     protected final Map<StringConnectorApplicationrarModules;
     protected final Map<StringValidatorbeanValidators;
     protected final Set<ResourceInforesourceInfos;
     protected final Set<PoolInfotransparentDynamicReconfigPools;
     protected final Map<StringObjectlocks;

    
Return the ConnectorRegistry instance

Returns:
ConnectorRegistry instance which is a singleton
 
     public static ConnectorRegistry getInstance() {
         if(.isLoggable(.)) {
            .fine("returning the connector registry");
        }
        return ;
    }

    
Protected constructor. It is protected as it follows singleton pattern.
    protected ConnectorRegistry() {
         = Collections.synchronizedMap(new HashMap<StringActiveResourceAdapter>());
         = Collections.synchronizedMap(new HashMap<PoolInfoPoolMetaData>());
         = Collections.synchronizedMap(new HashMap<StringConnectorApplication>());
         = Collections.synchronizedMap(new HashMap<StringValidator>());
         = new HashSet<ResourceInfo>();
         = new HashMap<StringObject>();
        if(.isLoggable(.)) {
            .log(."initialized the connector registry");
        }
    }

    
Adds the object implementing ActiveResourceAdapter interface to the registry.

Parameters:
rarModuleName RarName which is the key
rar ActiveResourceAdapter instance which is the value.
    public void addActiveResourceAdapter(String rarModuleName,
                                         ActiveResourceAdapter rar) {
        .put(rarModuleNamerar);
        if (.isLoggable(.)) {
            .log(.,
                    "Added the active resource adapter to connector registry",
                    rarModuleName);
        }
    }

    
get the map of factories (proxy to actual factory) using the resource.

Parameters:
resourceInfo resource-name
Returns:
Map of factories
        Map<DynamicallyReconfigurableResourceBooleanmap = .get(resourceInfo);
        //TODO synchronization
        if(map == null){
            map = new HashMap<DynamicallyReconfigurableResourceBoolean>();
            .put(resourceInfomap);
        }
        return map;
    }

    
remove and invalidate factories (proxy to actual factory) using the resource.

Parameters:
resourceInfo resource-name
Returns:
boolean indicating whether the factories are invalidated or not
    public boolean removeResourceFactories(ResourceInfo resourceInfo){
        boolean mapRemoved = false;
        Map<DynamicallyReconfigurableResourceBooleanmap = .remove(resourceInfo);
        if(map != null){
            for(DynamicallyReconfigurableResource resource : map.keySet()){
                resource.setInvalid();
            }
            map.clear();
            mapRemoved = true;
        }
        return mapRemoved;
    }

    
Add resourceInfo that is deployed for book-keeping purposes.

Parameters:
resourceInfo Resource being deployed.
    public void addResourceInfo(ResourceInfo resourceInfo){
        if(resourceInfo != null){
            synchronized (){
                .add(resourceInfo);
            }
        }
    }

    
Remove ResourceInfo from registry. Called when resource is disabled/undeployed.

Parameters:
resourceInfo ResourceInfo
Returns:
boolean indicating whether resource exists and removed.
    public boolean removeResourceInfo(ResourceInfo resourceInfo){
        boolean removed = false;
        if(resourceInfo != null){
            synchronized (){
                removed = .remove(resourceInfo);
            }
        }
        return removed;
    }

    
indicates whether the resource is deployed (enabled)

Parameters:
resourceInfo resource-info
Returns:
boolean indicating whether the resource is deployed.
    public boolean isResourceDeployed(ResourceInfo resourceInfo){
        boolean isDeployed = false;
        if(resourceInfo != null){
            isDeployed = .contains(resourceInfo);
        }
        return isDeployed;
    }

    
Add PoolInfo that has transparent-dynamic-reconfiguration enabled .

Parameters:
poolInfo Pool being deployed.
    public void addTransparentDynamicReconfigPool(PoolInfo poolInfo){
        if(poolInfo != null){
            synchronized (){
                .add(poolInfo);
            }
        }
    }

    
Remove ResourceInfo from registry. Called when resource is disabled/undeployed.

Parameters:
poolInfo poolInfo
Returns:
boolean indicating whether the pool exists and removed.
    public boolean removeTransparentDynamicReconfigPool(PoolInfo poolInfo){
        boolean removed = false;
        if(poolInfo != null){
            synchronized (){
                removed = .remove(poolInfo);
            }
        }
        return removed;
    }

    
indicates whether the pool has transparent-dynamic-reconfiguration property enabled

Parameters:
poolInfo poolInfo
Returns:
boolean false if pool is not deployed
    public boolean isTransparentDynamicReconfigPool(PoolInfo poolInfo){
        boolean isDeployed = false;
        if(poolInfo != null){
            isDeployed = .contains(poolInfo);
        }
        return isDeployed;
    }

    
Removes the object implementing ActiveResourceAdapter interface from the registry. This method is called whenever an active connector module is removed from the Connector runtime. [eg. undeploy/recreate etc]

Parameters:
rarModuleName RarName which is the key
Returns:
true if successfully removed false if deletion fails.
    public boolean removeActiveResourceAdapter(String rarModuleName) {
        Object o = .remove(rarModuleName);
        if (o == null) {
            if(.isLoggable(.)) {
                .fine("Failed to remove the resource adapter from connector registry" +
                    rarModuleName);
            }
            return false;
        } else {
            if(.isLoggable(.)) {
                .fine("removed the active resource adapter from connector registry" +
                    rarModuleName);
            }
            return true;
        }
    }

    
Retrieves the object implementing ActiveResourceAdapter interface from the registry. Key is the rarName.

Parameters:
rarModuleName Rar name. It is the key
Returns:
object implementing ActiveResourceAdapter interface
            String rarModuleName) {
        if (rarModuleName != null) {
            if(.isLoggable(.)) {
                .fine(
                    "returning/found the resource adapter from connector registry " +
                            rarModuleName);
            }
            return .get(rarModuleName);
        } else {
            if(.isLoggable(.)) {
                .fine(
                    "resource-adapter not found in connector registry. Returning null");
            }
            return null;
        }
    }

    
lock object that will be used by ResourceAdapterAdminService to avoid multiple calls to create ActiveRA for same resource-adapter

Parameters:
rarName resource-adapter name
Returns:
lock object for the resource-adapter
    public Object getLockObject(String rarName) {
        if (rarName == null) {
            return null;
        }
        Object lock;
        synchronized () {
            lock = .get(rarName);
            if (lock == null) {
                lock = new Object();
                .put(rarNamelock);
                if (.isLoggable(.)) {
                    .fine("added lock-object [ " + lock + " ] for rar : " + rarName);
                }
            }
        }
        return lock;
    }

    
removes the lock-object used for creating the ActiveRA for a particular RAR

Parameters:
rarName resource-adapter
    public void removeLockObject(String rarName) {
        if (rarName == null) {
            return;
        }
        synchronized () {
            Object lock = .remove(rarName);
            if (.isLoggable(.)) {
                .fine("removed lock-object [ " + lock + " ] for rar : " + rarName);
            }
        }
    }


    
Adds the bean validator to the registry.

Parameters:
rarModuleName RarName which is the key
validator to be added to registry
    public void addBeanValidator(String rarModuleNameValidator validator){
        .put(rarModuleNamevalidator);
        if(.isLoggable(.)) {
            .log(."Added the bean validator for RAR [ "+rarModuleName+" ] to connector registry");
        }
    }

    
Retrieves the bean validator of a resource-adapter from the registry. Key is the rarName.

Parameters:
rarModuleName Rar name. It is the key
Returns:
bean validator
    public Validator getBeanValidator(String rarModuleName){
        if (rarModuleName != null) {
            if(.isLoggable(.)) {
                .fine(
                    "returning/found the validator for RAR [ "+rarModuleName+" ] from connector registry");
            }
            return .get(rarModuleName);
        } else {
            if(.isLoggable(.)) {
                .fine(
                    "bean validator for RAR not found in connector registry.Returning null");
            }
            return null;
        }
    }

    
Removes the bean validator of a resource-adapter from the registry. This method is called whenever an active connector module is removed from the Connector runtime. [eg. undeploy/recreate etc]

Parameters:
rarModuleName RarName which is the key
Returns:
true if successfully removed false if deletion fails.
    public boolean removeBeanValidator(String rarModuleName) {
        Object o = .remove(rarModuleName);
        if (o == null) {
            if(.isLoggable(.)) {
                .fine("Failed to remove the bean validator for RAR [ "+rarModuleName+" ] from connector registry");
            }
            return false;
        } else {
            if(.isLoggable(.)) {
                .fine("removed the active bean validator for RAR [ "+rarModuleName +" ] from connector registry");
            }
            return true;
        }
    }

    
Checks if the MCF pertaining to the pool is instantiated and present in the registry. Each pool has its own MCF instance.

Parameters:
poolInfo Name of the pool
Returns:
true if the MCF is found. false if MCF is not found
    public boolean isMCFCreated(PoolInfo poolInfo) {
        boolean created = .containsKey(poolInfo);
        if(.isLoggable(.)) {
            .fine("isMCFCreated " + poolInfo + " - " + created);
        }
        return created;
    }


    
Remove MCF instance pertaining to the poolName from the registry.

Parameters:
poolInfo Name of the pool
Returns:
true if successfully removed. false if removal fails.
    public boolean removeManagedConnectionFactory(PoolInfo poolInfo) {
        if (.remove(poolInfo) == null) {
            if (.isLoggable(.)) {
                .log(.,
                        "Failed to remove the MCF from connector registry."poolInfo);
            }
            return false;
        } else {
            if(.isLoggable(.)) {
                .fine("removeMCF " + poolInfo + " - " + !.containsKey(poolInfo));
            }
            return true;
        }
    }

    
Add MCF instance pertaining to the poolName to the registry.

Parameters:
poolInfo Name of the pool
pmd MCF instance to be added.
    public void addManagedConnectionFactory(PoolInfo poolInfo,
                                            PoolMetaData pmd) {
        .put(poolInfopmd);
        if(.isLoggable(.)) {
            .fine("Added MCF to connector registry for: " + poolInfo);
        }
    }

    
Retrieve MCF instance pertaining to the poolName from the registry.

Parameters:
poolInfo Name of the pool
Returns:
factory MCF instance retrieved.
    public ManagedConnectionFactory getManagedConnectionFactory(
            PoolInfo poolInfo) {
        if (poolInfo != null) {
            if(.isLoggable(.)) {
                .log(.,
                    "Returning the MCF from connector registry."poolInfo);
            }
            PoolMetaData pmd = .get(poolInfo);
            if (pmd != null) {
                return pmd.getMCF();
            }
        }
        return null;
    }

    
Checks whether the rar is already deployed i.e registered with connector registry

Parameters:
rarModuleName rar Name.
Returns:
true if rar is registered false if rar is not registered.
    public boolean isRegistered(String rarModuleName) {
        if(.isLoggable(.)) {
            .log(.,
                "Checking for MCF presence in connector registry."rarModuleName);
        }
        return .containsKey(rarModuleName);
    }

    
Gets the connector descriptor pertaining the rar

Parameters:
rarModuleName rarName
Returns:
ConnectorDescriptor which represents the ra.xml
    public ConnectorDescriptor getDescriptor(String rarModuleName) {
        ActiveResourceAdapter ar = null;
        if (rarModuleName != null) {
            ar = .get(rarModuleName);
        }
        if (ar != null) {
            if(.isLoggable(.)) {
                .log(.,
                    "Found/returing Connector descriptor in connector registry.",
                    rarModuleName);
            }
            return ar.getDescriptor();
        } else {
            if(.isLoggable(.)) {
                .log(.,
                    "Couldnot find Connector descriptor in connector registry.",
                    rarModuleName);
            }
            return null;
        }
    }

    
Gets the runtime equivalent of policies enforced by the Security Maps pertaining to a pool from the Pool's Meta Data.

Parameters:
poolInfo pool information
Returns:
runtimeSecurityMap in the form of HashMap of HashMaps (user and groups).
See also:
SecurityMapUtils.processSecurityMaps( SecurityMap[])
        if(poolInfo != null) {
            if(.isLoggable(.)) {
                .log(."Returing the security map from connector registry."poolInfo);
            }
            PoolMetaData pmd = .get(poolInfo);
            return pmd.getRuntimeSecurityMap();
        } else {
            return null;
        }
    }

    
Get the resource adapter config properties object registered with registry against the rarName.

Parameters:
rarName Name of the rar
Returns:
ResourceAdapter configuration object
        if (rarName != null) {
            if(.isLoggable(.)) {
                .log(.,
                    "Returing the resourceadapter Config from registry."rarName);
            }
            return .get(rarName);
        } else {
            return null;
        }
    }

    
Add the resource adapter config properties object to registry against the rarName.

Parameters:
rarName Name of the rar
raConfig ResourceAdapter configuration object
    public void addResourceAdapterConfig(String rarName,
                                         ResourceAdapterConfig raConfig) {
        if (rarName != null) {
            if(.isLoggable(.)) {
                .log(.,
                    "Adding the resourceAdapter Config to connector registry.",
                    rarName);
            }
            .put(rarNameraConfig);
        }
    }

    
Remove the resource adapter config properties object from registry

Parameters:
rarName Name of the rar
Returns:
true if successfully deleted false if deletion fails
    public boolean removeResourceAdapterConfig(String rarName) {
        if (.remove(rarName) == null) {
            if(.isLoggable(.)) {
                .log(.,
                    "failed to remove the resourceAdapter config from registry.",
                    rarName);
            }
            return false;
        } else {
            if(.isLoggable(.)) {
                .log(.,
                    "Removed the resourceAdapter config map from registry.",
                    rarName);
            }
            return true;
        }
    }

    
Returns all Active Resource Adapters in the connector runtime.

Returns:
All active resource adapters in the connector runtime
        ActiveResourceAdapter araArray[]  = new ActiveResourceAdapter[this..size()];
        return this..values().toArray(araArray);
    }
    public PoolMetaData getPoolMetaData(PoolInfo poolInfo) {
        return .get(poolInfo);
    }

    
register a connector application (rarModule) with the registry

Parameters:
rarModule resource-adapter module
    public void addConnectorApplication(ConnectorApplication rarModule){
        .put(rarModule.getModuleName(), rarModule);
    }

    
retrieve a connector application (rarModule) from the registry

Parameters:
rarName resource-adapter name
Returns:
ConnectorApplication app
        return .get(rarName);
    }

    
remove a connector application (rarModule) from the registry

Parameters:
rarName resource-adapter module
    public void removeConnectorApplication(String rarName){
        .remove(rarName);
    }

    
get the list of resource-adapters that support this message-listener-type

Parameters:
messageListener message-listener class-name
Returns:
List of resource-adapters
    public List<StringgetConnectorsSupportingMessageListener(String messageListener){
        List<Stringrars = new ArrayList<String>();
        for(ActiveResourceAdapter ara : .values()){
            ConnectorDescriptor desc = ara.getDescriptor();
            if(desc.getInBoundDefined()){
                if(desc.getInboundResourceAdapter().getMessageListener(messageListener) != null){
                    rars.add(ara.getModuleName());
                }
            }
        }
        return rars;
    }
New to GrepCode? Check out our FAQ X