FileDocCategorySizeDatePackage
ConnectorServiceImpl.javaAPI DocGlassfish v2 API19184Fri May 04 22:34:24 BST 2007com.sun.enterprise.connectors

ConnectorServiceImpl

public class ConnectorServiceImpl extends Object implements ConnectorConstants
This is the base class for all the connector services. It defines the enviroment of execution (client or server), and holds the reference to connector runtime for inter service method invocations.
author
Srikanth P

Fields Summary
static Logger
_logger
protected static final ConnectorRegistry
_registry
private boolean
debug
protected static int
environment
Constructors Summary
public ConnectorServiceImpl()
Default Constructor


             

      
    
Methods Summary
public booleancheckAccessibility(java.lang.String rarName, java.lang.ClassLoader loader)
Check whether ClassLoader is permitted to access this resource adapter. If the RAR is deployed and is not a standalone RAR, then only ClassLoader that loader the archive should be able to access it. Otherwise everybody can access the RAR.

param
rarName Resource adapter module name.
param
loader ClassLoader to verify.

        ActiveResourceAdapter ar = _registry.getActiveResourceAdapter(rarName);
        if (ar != null && loader != null) { // If RA is deployed
	    ClassLoader rarLoader = ar.getClassLoader();
	    //If the RAR is not standalone.
	    if (rarLoader != null && (!(rarLoader instanceof ConnectorClassLoader))) {
		ClassLoader parent = loader;
		while (true) {
		    if (parent.equals(rarLoader)) {
                        return true;
		    }

                    final ClassLoader temp = parent;
                    Object obj = AccessController.doPrivileged( new PrivilegedAction() {
                        public Object run() {
		            return temp.getParent();
                        }
                    });

                    if (obj == null) {
                        break;
                    } else {
                        parent = (ClassLoader) obj;
                    }
                }
		// If no parent matches return false;
                return false;
	    }
	}
	return true;
    
public booleancheckAndLoadPoolResource(java.lang.String poolName)


       ResourcesUtil resutil = ResourcesUtil.createInstance(); 
       DeferredResourceConfig defResConfig = resutil.getDeferredPoolConfig(
                                poolName); 
       return loadResourcesAndItsRar(defResConfig);
    
public booleancheckAndLoadResource(java.lang.String resname)
Internal API to lazily load Connector/JDBC/JMS and other resources on first lookup. All dependent resources and related infrastructure are also loaded.

        //Resolve actual JNDI name. Connector and JDBC connection Pools are 
        //internally reserve prefixed while binding in JNDI. 
        //The Connector backend OTOH uses the actual JNDI name for all checks. 
        //So unmap the transformation here before proceeding to load the resource 
        //and its dependents
        resname = ConnectorAdminServiceUtils.getOriginalResourceName(resname); 
        _logger.fine("ConnectorServiceImpl :: checkAndLoadResource resolved to " +
                "load " + resname);

        ResourcesUtil resutil = ResourcesUtil.createInstance(); 
        DeferredResourceConfig defResConfig = resutil.getDeferredResourceConfig(
                                        resname); 
        return loadResourcesAndItsRar(defResConfig);
    
public voidcreate()
These two methods are NOP. They will be used for future enhancements.


    
public voiddestroy()


    
public ConnectorDescriptorgetConnectorDescriptor(java.lang.String rarName)
Obtains the connector Descriptor pertaining to rar. If ConnectorDescriptor is present in registry, it is obtained from registry and returned. Else it is explicitly read from directory where rar is exploded.

param
rarName Name of the rar
return
ConnectorDescriptor pertaining to rar.

        
        if(rarName == null) {
            return null;
        }
        ConnectorDescriptor desc = null;
        desc = _registry.getDescriptor(rarName);
        if(desc != null) {
            return desc;
        }
        String moduleDir = null;
        ResourcesUtil resUtil = ResourcesUtil.createInstance();

        //If the RAR is embedded try loading the descriptor directly
        //using the applicationarchivist
        if (rarName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) != -1){
            try {
                desc = loadConnectorDescriptorForEmbeddedRAR(rarName);
                if (desc != null) return desc;
            } catch (ConnectorRuntimeException e) {
                throw e;
            }
        }
        
        if(resUtil.belongToSystemRar(rarName)){
            ResourceInstaller installer = 
                       Switch.getSwitch().getResourceInstaller();
            moduleDir = installer.getSystemModuleLocation(rarName);
        } else {
            moduleDir = resUtil.getLocation(rarName);
        }
        if (moduleDir != null) {
            desc = ConnectorDDTransformUtils.getConnectorDescriptor(moduleDir);
        } else {
            _logger.log(Level.SEVERE,
                   "rardeployment.no_module_deployed", rarName);
        }
        return desc;
    
public java.lang.StringgetDefaultPoolName(java.lang.String jndiName)
Returns the generated default poolName of JMS resources.

jndiName
jndi of the resources for which pool is to be created,
return
generated poolname

        //This is called by the JMS Deployers alone
        return jndiName;
    
public java.lang.StringgetDefaultPoolName(java.lang.String moduleName, java.lang.String connectionDefName)
Returns the generated default connection poolName for a connection definition.

moduleName
rar module name
connectionDefName
connection definition name
return
generated connection poolname

        return moduleName+POOLNAME_APPENDER+connectionDefName;
    
public java.lang.StringgetDefaultResourceName(java.lang.String moduleName, java.lang.String connectionDefName)
Returns the generated default connector resource for a connection definition.

moduleName
rar module name
connectionDefName
connection definition name
return
generated default connector resource name

        //Construct the default resource name as
        // <JNDIName_of_RA>#<connectionDefnName>
        String resourceJNDIName = ConnectorAdminServiceUtils.
                    getReservePrefixedJNDINameForResource(moduleName);
        return resourceJNDIName + RESOURCENAME_APPENDER + connectionDefName;
    
public static intgetEnviron()
Returns the execution environment.

return
ConnectorConstants.SERVER if execution environment is appserv runtime else it returns ConnectorConstants.CLIENT

        return environment;
    
protected ConnectorRuntimegetRuntime()

        return ConnectorRuntime.getRuntime();
    
public voidifSystemRarLoad(java.lang.String rarName)

        ResourcesUtil resUtil = ResourcesUtil.createInstance();
        if(resUtil.belongToSystemRar(rarName)){
            loadDeferredResourceAdapter(rarName);
        }
    
public static voidinitialize(int environ)
Initializes the execution environment. If the execution environment is appserv runtime it is set to ConnectorConstants.SERVER else it is set ConnectorConstants.CLIENT

param
environment set to ConnectorConstants.SERVER if execution environment is appserv runtime else set to ConnectorConstants.CLIENT

        environment = environ;
    
public voidinitializeConnectorMonitoring()
Initialize the monitoring listeners for connection pools, work management and message end point factory related stats

        Switch.getSwitch().getPoolManager().initializeMonitoring();
        initializeWorkMgmtAndEndPointMonitoring();
    
private voidinitializeWorkMgmtAndEndPointMonitoring()
Initialize the monitoring listeners for connection pools, work management and message end point factory related stats

        try {
            final ConnectorWorkMonitoringLevelListener cwmll 
                        = new ConnectorWorkMonitoringLevelListener();
            //@todo Do for Connector EPF Monitoring as well
        
            AccessController.doPrivileged(new PrivilegedAction() {
                public Object run() {
                    ServerContext ctxt = ApplicationServer.getServerContext();
                    if (ctxt != null) {
                        MonitoringRegistry monitoringRegistry_ 
                            = ctxt.getMonitoringRegistry();
                        //@todo: for EFT level listeners 
                        monitoringRegistry_.registerMonitoringLevelListener(cwmll, 
                                        MonitoredObjectType.CONNECTOR_WORKMGMT);
                                        
/*                        monitoringRegistry_.registerMonitoringLevelListener(
                                        ccpPoolMonitoringLevelListener_,
                                        MonitoredObjectType.CONNECTOR_CONN_POOL );
*/
                }
                return null;
            }    
            });
    
            _logger.log( Level.FINE, "poolmon.init_monitoring_registry");
        } catch(Exception e) {
            _logger.log( Level.INFO, "poolmon.error_registering_listener", 
            e);
        }
    
public static booleanisServer()
Checks whether the executing environment is application server

return
true if execution environment is server false if it is client

        if(getEnviron() == SERVER) {
            return true;
        } else {
            return false;
        }
    
private ConnectorDescriptorloadConnectorDescriptorForEmbeddedRAR(java.lang.String rarName)

        //If the RAR is embedded try loading the descriptor directly
        //using the applicationarchivist
        try {
            String appName = rarName.substring(0, rarName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER));
            String actualRarName = rarName.substring(rarName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) + 1);
            String appDeployLocation = ResourcesUtil.createInstance().getApplicationDeployLocation(appName);
            
            FileArchive in = new FileArchive();
            in.open(appDeployLocation);
            ApplicationArchivist archivist = new ApplicationArchivist();
            Application application = (Application) archivist.open(in);
            //get all RAR descriptors and try searching for this embedded RAR
            Set s = application.getRarDescriptors();
            for (Iterator iter = s.iterator(); iter.hasNext();) {
                ConnectorDescriptor element = (ConnectorDescriptor) iter.next();
                //Strip ".rar" from deployname before using it.
                String rardescname = element.getDeployName().substring(
                                0, element.getDeployName().indexOf(".rar"));
                if(rardescname.equals(actualRarName)){
                    return element;
                }
            }
        } catch (SAXParseException e) {
            ConnectorRuntimeException crex = new ConnectorRuntimeException("" +
                    "SAXParseException while trying to load connector descriptor for embedded RAR");
            crex.initCause(e);
            throw crex;
        } catch (IOException e) {
            ConnectorRuntimeException crex = new ConnectorRuntimeException("" +
            "SAXParseException while trying to load connector descriptor for embedded RAR");
            crex.initCause(e);
            throw crex;
        }
        return null;
        
    
public voidloadDeferredResourceAdapter(java.lang.String rarName)

       try {
           ManagerFactory.getSAConnectorModulesManager().
           loadOneSystemApp(rarName, true);
       } catch (Exception e) {
           ConnectorRuntimeException ce = 
           new ConnectorRuntimeException(e.getMessage());
           ce.initCause(e);
           throw ce;
       }
    
public voidloadDeferredResources(ConfigBean[] resourcesToLoad)

        if(resourcesToLoad == null || resourcesToLoad.length == 0) {
            return;
        }
        String resourceType = null;
        ResourceDeployer deployer = null;
        ResourcesUtil resourceUtil = ResourcesUtil.createInstance(); 
        for(int i=0;i<resourcesToLoad.length;++i) {
            if(resourcesToLoad[i] == null) {
                continue;
            } else if (resourceUtil.isEnabled(resourcesToLoad[i])) {
                resourceType = resourceUtil.getResourceType(resourcesToLoad[i]);
                ResourceDeployerFactory factory = new ResourceDeployerFactory();
                deployer = factory.getResourceDeployer(resourceType);
                if(deployer != null) {
                    deployer.deployResource(resourcesToLoad[i]);
                }
            }
        }
    
public booleanloadResourcesAndItsRar(DeferredResourceConfig defResConfig)

       if(defResConfig != null) {
           try {
               loadDeferredResources(defResConfig.getResourceAdapterConfig());
               String rarName = defResConfig.getRarName();
               loadDeferredResourceAdapter(rarName);
               final ConfigBean[] resToLoad = defResConfig.getResourcesToLoad();
               AccessController.doPrivileged(new PrivilegedAction() {
                   public Object run() {
                       try {
                           loadDeferredResources(resToLoad);
                       } catch(Exception ex) {
                           _logger.log( Level.SEVERE,
                                "failed to load resources/ResourceAdapter");
                           _logger.log(Level.SEVERE,"" ,ex);
                       }
                       return null;
                   }
               });
           } catch(Exception ex) {
               _logger.log(
                  Level.SEVERE,"failed to load resources/ResourceAdapter");
               _logger.log(Level.SEVERE,"" ,ex);
               return false;
           }
           return true;
       }
       return false;
    
public voidswitchOnMatching(java.lang.String rarName, java.lang.String poolName)
Matching will be switched off in the pool, by default. This will be switched on if the connections with different resource principals reach the pool.

param
poolName Name of the pool to switchOn matching.
param
rarName Name of the resource adater.

        // At present it is applicable to only JDBC resource adapters
        // Later other resource adapters also become applicable.
        if (rarName.equals(ConnectorRuntime.JDBCDATASOURCE_RA_NAME) ||
            rarName.equals(ConnectorRuntime.JDBCCONNECTIONPOOLDATASOURCE_RA_NAME) ||
            rarName.equals(ConnectorRuntime.JDBCXA_RA_NAME)) {
           
             PoolManager poolMgr = Switch.getSwitch().getPoolManager();
             boolean result = poolMgr.switchOnMatching(poolName);            
             if (result == false) {
                 try {
                     getRuntime().switchOnMatchingInJndi(poolName);                    
                 } catch (ConnectorRuntimeException cre) {
                     // This will never happen.
                 }
             }
        }