FileDocCategorySizeDatePackage
ConnectorResourceAdminServiceImpl.javaAPI DocGlassfish v2 API10623Fri Jun 01 05:56:50 BST 2007com.sun.enterprise.connectors

ConnectorResourceAdminServiceImpl

public class ConnectorResourceAdminServiceImpl extends ConnectorServiceImpl implements ConnectorAdminService
This is connector resource admin service. It creates and deletes the connector resources.
author
Srikanth P

Fields Summary
Constructors Summary
public ConnectorResourceAdminServiceImpl()
Default constructor

         super();
     
Methods Summary
public voidcreateConnectorResource(java.lang.String jndiName, java.lang.String poolName, java.lang.String resourceType)
Creates the connector resource on a given connection pool

param
jndiName JNDI name of the resource to be created
poolName
PoolName to which the connector resource belongs.
resourceType
Resource type Unused.
throws
ConnectorRuntimeException If the resouce creation fails.


        String errMsg = "rardeployment.jndi_lookup_failed";
        String name = poolName;
        try {
	    ConnectorConnectionPool connectorConnectionPool = null;
            String jndiNameForPool = ConnectorAdminServiceUtils.
                getReservePrefixedJNDINameForPool(poolName);
            InitialContext ic = new InitialContext();
            try {
                connectorConnectionPool = 
                    (ConnectorConnectionPool) ic.lookup(jndiNameForPool);
            } catch(NamingException ne) {
                checkAndLoadPoolResource(poolName);
            }

            connectorConnectionPool = 
                    (ConnectorConnectionPool) ic.lookup(jndiNameForPool);
            ConnectorDescriptorInfo cdi = connectorConnectionPool.
                getConnectorDescriptorInfo();

            javax.naming.Reference ref=new  javax.naming.Reference( 
                   connectorConnectionPool.getConnectorDescriptorInfo().
                   getConnectionFactoryClass(), 
                   "com.sun.enterprise.naming.factory.ConnectorObjectFactory",
                   null);
            StringRefAddr addr = new StringRefAddr("poolName",poolName);
            ref.add(addr);
            addr = new StringRefAddr("rarName", cdi.getRarName() );
            ref.add(addr);

            errMsg = "Failed to bind connector resource in JNDI";
            name = jndiName;
            Switch.getSwitch().getNamingManager().publishObject(
                          jndiName,ref,true);
            //To notify that a connector resource rebind has happened.
            ConnectorResourceNamingEventNotifier.getInstance().
                    notifyListeners(
                            new ConnectorNamingEvent(
                                    jndiName,ConnectorNamingEvent.EVENT_OBJECT_REBIND));

        } catch(NamingException ne) {
            ConnectorRuntimeException cre = 
                  new ConnectorRuntimeException(errMsg);
            cre.initCause(ne);
            _logger.log(Level.SEVERE,errMsg, name); 
            _logger.log(Level.SEVERE,"", cre); 
            throw cre;
        }
    
public voiddeleteConnectorResource(java.lang.String jndiName)
Deletes the connector resource.

param
jndiName JNDI name of the resource to delete.
throws
ConnectorRuntimeException if connector resource deletion fails.


        try {
            InitialContext ic = new InitialContext();
            ic.unbind(jndiName);
        } catch(NamingException ne) {
            ResourcesUtil resUtil = ResourcesUtil.createInstance();
            if(resUtil.resourceBelongsToSystemRar(jndiName)) {
                return;
            }
            if(ne instanceof  NameNotFoundException){
                _logger.log(Level.FINE,
                    "rardeployment.connectorresource_removal_from_jndi_error",
                    jndiName);
                _logger.log(Level.FINE,"", ne);
                return;
            }
            ConnectorRuntimeException cre =  new ConnectorRuntimeException(
                            "Failed to delete connector resource from jndi");
            cre.initCause(ne);
            _logger.log(Level.SEVERE,
                    "rardeployment.connectorresource_removal_from_jndi_error",
                    jndiName);
            _logger.log(Level.SEVERE,"", cre);
            throw cre;
        }
    
public ConnectorNamingEventNotifiergetResourceRebindEventNotifier()
Gets Connector Resource Rebind Event notifier.

return
ConnectorNamingEventNotifier

        return ConnectorResourceNamingEventNotifier.getInstance();
    
private java.lang.StringgetValidSuffix(java.lang.String name)

        if (name != null) {
            for (String validSuffix : ConnectorConstants.JNDI_SUFFIX_VALUES) {
                if (name.endsWith(validSuffix)) {
                    return validSuffix;
                }
            }
        }
        return null;
    
public booleanisValidJndiSuffix(java.lang.String suffix)
If the suffix is one of the valid context return true. Return false, if that is not the case.

        if (suffix != null) {
            for (String validSuffix : ConnectorConstants.JNDI_SUFFIX_VALUES) {
                if (validSuffix.equals(suffix)) {
                    return true;
                }
            }
        }

        return false;
    
public java.lang.Objectlookup(java.lang.String name)
Look up the JNDI name with appropriate suffix. Suffix can be either __pm or __nontx.

        Hashtable ht = null;
        String suffix = getValidSuffix(name); 
        if (suffix != null) {
            ht = new Hashtable();
            ht.put(ConnectorConstants.JNDI_SUFFIX_PROPERTY, suffix);
            name = name.substring(0, name.lastIndexOf(suffix));
        }
        InitialContext ic = new InitialContext(ht);
        return ic.lookup(name);
    
protected java.lang.ObjectlookupDataSourceInDAS(java.lang.String jndiName)
Get a wrapper datasource specified by the jdbcjndi name This API is intended to be used in the DAS. The motivation for having this API is to provide the CMP backend/ JPA-Java2DB a means of acquiring a connection during the codegen phase. If a user is trying to deploy an JPA-Java2DB app on a remote server, without this API, a resource reference has to be present both in the DAS and the server instance. This makes the deployment more complex for the user since a resource needs to be forcibly created in the DAS Too. This API will mitigate this need.

param
jndiName the jndi name of the resource
return
DataSource representing the resource.

        MyDataSource myDS = new MyDataSource();
        myDS.setJndiName(jndiName);
        return myDS;