Search in sources :

Example 1 with ConnectorNamingEvent

use of com.sun.appserv.connectors.internal.spi.ConnectorNamingEvent in project Payara by payara.

the class ConnectorResourceAdminServiceImpl method createConnectorResource.

/**
 * Creates the connector resource on a given connection pool
 *
 * @param resourceInfo     JNDI name of the resource to be created
 * @param poolInfo     PoolName to which the connector resource belongs.
 * @param resourceType Resource type Unused.
 * @throws ConnectorRuntimeException If the resouce creation fails.
 */
public void createConnectorResource(ResourceInfo resourceInfo, PoolInfo poolInfo, String resourceType) throws ConnectorRuntimeException {
    try {
        ConnectorConnectionPool ccp = null;
        String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
        try {
            ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
        } catch (NamingException ne) {
            // Probably the pool is not yet initialized (lazy-loading), try doing a lookup
            try {
                checkAndLoadPool(poolInfo);
                ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
            } catch (NamingException e) {
                Object[] params = new Object[] { poolInfo, e };
                _logger.log(Level.SEVERE, "unable.to.lookup.pool", params);
            }
        }
        if (ccp == null) {
            ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
        }
        ConnectorDescriptorInfo cdi = ccp.getConnectorDescriptorInfo();
        javax.naming.Reference ref = new javax.naming.Reference(cdi.getConnectionFactoryClass(), "com.sun.enterprise.resource.naming.ConnectorObjectFactory", null);
        RefAddr addr = new SerializableObjectRefAddr(PoolInfo.class.getName(), poolInfo);
        ref.add(addr);
        addr = new StringRefAddr("rarName", cdi.getRarName());
        ref.add(addr);
        RefAddr resAddr = new SerializableObjectRefAddr(ResourceInfo.class.getName(), resourceInfo);
        ref.add(resAddr);
        try {
            namingService.publishObject(resourceInfo, ref, true);
            _registry.addResourceInfo(resourceInfo);
        } catch (NamingException ne) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException(ne.getMessage());
            cre.initCause(ne);
            Object[] params = new Object[] { resourceInfo, cre };
            _logger.log(Level.SEVERE, "rardeployment.resource_jndi_bind_failure", params);
            throw cre;
        }
        /*

            ConnectorObjectFactory cof = new ConnectorObjectFactory(jndiName, ccp.getConnectorDescriptorInfo().
                    getConnectionFactoryClass(), cdi.getRarName(), poolName);

            _runtime.getNamingManager().publishObject(jndiName, cof, true);
*/
        // To notify that a connector resource rebind has happened.
        ConnectorResourceNamingEventNotifier.getInstance().notifyListeners(new ConnectorNamingEvent(resourceInfo.toString(), ConnectorNamingEvent.EVENT_OBJECT_REBIND));
    } catch (NamingException ne) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException(ne.getMessage());
        cre.initCause(ne);
        Object[] params = new Object[] { resourceInfo, cre };
        _logger.log(Level.SEVERE, "rardeployment.jndi_lookup_failed", params);
        throw cre;
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorConnectionPool(com.sun.enterprise.connectors.ConnectorConnectionPool) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) ConnectorNamingEvent(com.sun.appserv.connectors.internal.spi.ConnectorNamingEvent) RefAddr(javax.naming.RefAddr) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) StringRefAddr(javax.naming.StringRefAddr) StringRefAddr(javax.naming.StringRefAddr) ConnectorDescriptorInfo(com.sun.enterprise.connectors.ConnectorDescriptorInfo) NamingException(javax.naming.NamingException) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Aggregations

ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 ConnectorNamingEvent (com.sun.appserv.connectors.internal.spi.ConnectorNamingEvent)1 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)1 ConnectorDescriptorInfo (com.sun.enterprise.connectors.ConnectorDescriptorInfo)1 NamingException (javax.naming.NamingException)1 RefAddr (javax.naming.RefAddr)1 StringRefAddr (javax.naming.StringRefAddr)1 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)1 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)1 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)1