Search in sources :

Example 1 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class ResourceAdapterAdminServiceImpl method createActiveResourceAdapter.

/**
 * Creates Active resource Adapter which abstracts the rar module. During
 * the creation of ActiveResourceAdapter, default pools and resources also
 * are created.
 *
 * @param connectorDescriptor object which abstracts the connector deployment descriptor
 *                            i.e rar.xml and sun-ra.xml.
 * @param moduleName          Name of the module
 * @param moduleDir           Directory where rar module is exploded.
 * @param loader              Classloader to use
 * @throws ConnectorRuntimeException if creation fails.
 */
public void createActiveResourceAdapter(ConnectorDescriptor connectorDescriptor, String moduleName, String moduleDir, ClassLoader loader) throws ConnectorRuntimeException {
    synchronized (_registry.getLockObject(moduleName)) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir);
        }
        ActiveResourceAdapter activeResourceAdapter = _registry.getActiveResourceAdapter(moduleName);
        if (activeResourceAdapter != null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "rardeployment.resourceadapter.already.started", moduleName);
            }
            return;
        }
        // TODO V3 works fine ?
        if (loader == null) {
            try {
                loader = connectorDescriptor.getClassLoader();
            } catch (Exception ex) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "No classloader available with connector descriptor");
                }
                loader = null;
            }
        }
        ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
        ModuleDescriptor moduleDescriptor = null;
        Application application = null;
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " loader :: " + loader);
        }
        // (standalone + embedded)
        if (loader == null && ConnectorsUtil.belongsToSystemRA(moduleName)) {
            if (connectorRuntime.isServer()) {
                loader = connectorRuntime.getSystemRARClassLoader(moduleName);
            }
        } else {
            connectorDescriptor.setClassLoader(null);
            moduleDescriptor = connectorDescriptor.getModuleDescriptor();
            application = connectorDescriptor.getApplication();
            connectorDescriptor.setModuleDescriptor(null);
            connectorDescriptor.setApplication(null);
        }
        try {
            activeResourceAdapter = connectorRuntime.getActiveRAFactory().createActiveResourceAdapter(connectorDescriptor, moduleName, loader);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " adding to registry " + activeResourceAdapter);
            }
            _registry.addActiveResourceAdapter(moduleName, activeResourceAdapter);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("ResourceAdapterAdminServiceImpl:: createActiveRA " + moduleName + " at " + moduleDir + " env =server ? " + (connectorRuntime.isServer()));
            }
            if (connectorRuntime.isServer()) {
                // Update RAConfig in Connector Descriptor and bind in JNDI
                // so that ACC clients could use RAConfig
                updateRAConfigInDescriptor(connectorDescriptor, moduleName);
                String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("ResourceAdapterAdminServiceImpl :: createActiveRA " + moduleName + " at " + moduleDir + " publishing descriptor " + descriptorJNDIName);
                }
                _runtime.getNamingManager().publishObject(descriptorJNDIName, connectorDescriptor, true);
                activeResourceAdapter.setup();
                if (System.getSecurityManager() != null) {
                    String securityWarningMessage = connectorRuntime.getSecurityPermissionSpec(moduleName);
                    // To i18N.
                    if (securityWarningMessage != null) {
                        _logger.log(Level.WARNING, securityWarningMessage);
                    }
                }
            }
        } catch (NullPointerException npEx) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
            cre.initCause(npEx);
            _logger.log(Level.SEVERE, "rardeployment.nullPointerException", moduleName);
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        } catch (NamingException ne) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
            cre.initCause(ne);
            _logger.log(Level.SEVERE, "rardeployment.jndi_publish_failure");
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        } finally {
            if (moduleDescriptor != null) {
                connectorDescriptor.setModuleDescriptor(moduleDescriptor);
                connectorDescriptor.setApplication(application);
                connectorDescriptor.setClassLoader(loader);
            }
        }
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) NamingException(javax.naming.NamingException) ActiveResourceAdapter(com.sun.enterprise.connectors.ActiveResourceAdapter) ConnectorApplication(com.sun.enterprise.connectors.module.ConnectorApplication) Application(com.sun.enterprise.deployment.Application) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 2 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class ResourceAdapterAdminServiceImpl method createActiveResourceAdapter.

/**
 * Creates Active resource Adapter which abstracts the rar module. During
 * the creation of ActiveResourceAdapter, default pools and resources also
 * are created.
 *
 * @param moduleDir  Directory where rar module is exploded.
 * @param moduleName Name of the module
 * @throws ConnectorRuntimeException if creation fails.
 */
public void createActiveResourceAdapter(String moduleDir, String moduleName, ClassLoader loader) throws ConnectorRuntimeException {
    synchronized (_registry.getLockObject(moduleName)) {
        ActiveResourceAdapter activeResourceAdapter = _registry.getActiveResourceAdapter(moduleName);
        if (activeResourceAdapter != null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "rardeployment.resourceadapter.already.started", moduleName);
            }
            return;
        }
        if (ConnectorsUtil.belongsToSystemRA(moduleName)) {
            moduleDir = ConnectorsUtil.getSystemModuleLocation(moduleName);
        }
        ConnectorDescriptor connectorDescriptor = ConnectorDDTransformUtils.getConnectorDescriptor(moduleDir, moduleName);
        if (connectorDescriptor == null) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to obtain the connectorDescriptor");
            _logger.log(Level.SEVERE, "rardeployment.connector_descriptor_notfound", moduleName);
            _logger.log(Level.SEVERE, "", cre);
            throw cre;
        }
        createActiveResourceAdapter(connectorDescriptor, moduleName, moduleDir, loader);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ActiveResourceAdapter(com.sun.enterprise.connectors.ActiveResourceAdapter)

Example 3 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class AdminObjectConfigParserImpl method getAdminObject.

private AdminObject getAdminObject(ConnectorDescriptor desc, String adminObjectInterface, String adminObjectClass) throws ConnectorRuntimeException {
    if (desc == null || adminObjectInterface == null) {
        throw new ConnectorRuntimeException("Invalid arguments");
    }
    Set adminObjectSet = desc.getAdminObjects();
    if (adminObjectSet == null || adminObjectSet.size() == 0) {
        return null;
    }
    AdminObject adminObject = null;
    Iterator iter = adminObjectSet.iterator();
    Properties mergedVals = null;
    boolean adminObjectFound = false;
    while (iter.hasNext()) {
        adminObject = (AdminObject) iter.next();
        if (adminObjectInterface.equals(adminObject.getAdminObjectInterface()) && (adminObjectClass == null || adminObjectClass.equals(adminObject.getAdminObjectClass()))) {
            adminObjectFound = true;
            break;
        }
    }
    if (!adminObjectFound) {
        StringManager localStrings = StringManager.getManager(AdminObjectConfigParserImpl.class);
        String msg = localStrings.getString("no_adminobject_interface_found_in_raxml", adminObjectInterface);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, msg);
        }
        throw new ConnectorRuntimeException(msg);
    }
    return adminObject;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 4 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class ConnectorObjectFactory method getObjectInstance.

public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception {
    Reference ref = (Reference) obj;
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "ConnectorObjectFactory: " + ref + " Name:" + name);
    }
    PoolInfo poolInfo = (PoolInfo) ref.get(0).getContent();
    String moduleName = (String) ref.get(1).getContent();
    ResourceInfo resourceInfo = (ResourceInfo) ref.get(2).getContent();
    if (getRuntime().isACCRuntime() || getRuntime().isNonACCRuntime()) {
        ConnectorDescriptor connectorDescriptor = null;
        String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
        Context ic = new InitialContext(env);
        connectorDescriptor = (ConnectorDescriptor) ic.lookup(descriptorJNDIName);
        try {
            getRuntime().createActiveResourceAdapter(connectorDescriptor, moduleName, null);
        } catch (ConnectorRuntimeException e) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Failed to look up ConnectorDescriptor from JNDI", moduleName);
            }
            NamingException ne = new NamingException("Failed to look up ConnectorDescriptor from JNDI");
            ne.setRootCause(e);
            throw ne;
        }
    }
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    if (!getRuntime().checkAccessibility(moduleName, loader)) {
        String msg = localStrings.getString("cof.no_access_to_embedded_rar", moduleName);
        throw new NamingException(msg);
    }
    Object cf = null;
    try {
        ManagedConnectionFactory mcf = getRuntime().obtainManagedConnectionFactory(poolInfo, env);
        if (mcf == null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Failed to create MCF ", poolInfo);
            }
            throw new ConnectorRuntimeException("Failed to create MCF");
        }
        boolean forceNoLazyAssoc = false;
        String jndiName = name.toString();
        if (jndiName.endsWith(ConnectorConstants.PM_JNDI_SUFFIX)) {
            forceNoLazyAssoc = true;
        }
        String derivedJndiName = ConnectorsUtil.deriveJndiName(jndiName, env);
        ConnectionManagerImpl mgr = (ConnectionManagerImpl) getRuntime().obtainConnectionManager(poolInfo, forceNoLazyAssoc, resourceInfo);
        mgr.setJndiName(derivedJndiName);
        mgr.setRarName(moduleName);
        String logicalName = (String) env.get(GlassfishNamingManager.LOGICAL_NAME);
        if (logicalName != null) {
            mgr.setLogicalName(logicalName);
        }
        mgr.initialize();
        cf = mcf.createConnectionFactory(mgr);
        if (cf == null) {
            String msg = localStrings.getString("cof.no.resource.adapter");
            throw new RuntimeException(new ConfigurationException(msg));
        }
        if (getRuntime().isServer() || getRuntime().isEmbedded()) {
            ConnectorRegistry registry = ConnectorRegistry.getInstance();
            if (registry.isTransparentDynamicReconfigPool(poolInfo)) {
                Resources resources = getRuntime().getResources(poolInfo);
                ResourcePool resourcePool = null;
                if (resources != null) {
                    resourcePool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolInfo.getName());
                    if (resourcePool != null) {
                        ResourceDeployer deployer = getRuntime().getResourceDeployer(resourcePool);
                        if (deployer != null && deployer.supportsDynamicReconfiguration() && ConnectorsUtil.isDynamicReconfigurationEnabled(resourcePool)) {
                            Object o = env.get(ConnectorConstants.DYNAMIC_RECONFIGURATION_PROXY_CALL);
                            if (o == null || Boolean.valueOf(o.toString()).equals(false)) {
                                // TODO use list ? (even in the ResourceDeployer API)
                                Class[] classes = deployer.getProxyClassesForDynamicReconfiguration();
                                Class[] proxyClasses = new Class[classes.length + 1];
                                for (int i = 0; i < classes.length; i++) {
                                    proxyClasses[i] = classes[i];
                                }
                                proxyClasses[proxyClasses.length - 1] = DynamicallyReconfigurableResource.class;
                                cf = getProxyObject(cf, proxyClasses, resourceInfo);
                            }
                        }
                    }
                }
            }
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Connection Factory:" + cf);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return cf;
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectionManagerImpl(com.sun.enterprise.connectors.ConnectionManagerImpl) Reference(javax.naming.Reference) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) InitialContext(javax.naming.InitialContext) ConfigurationException(javax.naming.ConfigurationException) NamingException(javax.naming.NamingException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConfigurationException(javax.naming.ConfigurationException) ResourceDeployer(org.glassfish.resourcebase.resources.api.ResourceDeployer) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) NamingException(javax.naming.NamingException) Resources(com.sun.enterprise.config.serverbeans.Resources) ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry)

Example 5 with ConnectorRuntimeException

use of com.sun.appserv.connectors.internal.api.ConnectorRuntimeException in project Payara by payara.

the class JdbcConnectionPoolDeployer method handlePoolRecreation.

private void handlePoolRecreation(final ConnectorConnectionPool connConnPool) throws ConnectorRuntimeException {
    debug("[DRC] Pool recreation required");
    final long reconfigWaitTimeout = connConnPool.getDynamicReconfigWaitTimeout();
    PoolInfo poolInfo = new PoolInfo(connConnPool.getName(), connConnPool.getApplicationName(), connConnPool.getModuleName());
    final ResourcePool oldPool = runtime.getPoolManager().getPool(poolInfo);
    if (reconfigWaitTimeout > 0) {
        oldPool.blockRequests(reconfigWaitTimeout);
        if (oldPool.getPoolWaitQueue().getQueueLength() > 0 || oldPool.getPoolStatus().getNumConnUsed() > 0) {
            Runnable thread = new Runnable() {

                @Override
                public void run() {
                    try {
                        // poll every 5 seconds
                        long numSeconds = 5000L;
                        long steps = reconfigWaitTimeout / numSeconds;
                        if (steps == 0) {
                            waitForCompletion(steps, oldPool, reconfigWaitTimeout);
                        } else {
                            for (long i = 0; i < steps; i++) {
                                waitForCompletion(steps, oldPool, reconfigWaitTimeout);
                                if (oldPool.getPoolWaitQueue().getQueueLength() == 0 && oldPool.getPoolStatus().getNumConnUsed() == 0) {
                                    debug("wait-queue is empty and num-con-used is 0");
                                    break;
                                }
                            }
                        }
                        handlePoolRecreationForExistingProxies(connConnPool);
                        PoolWaitQueue reconfigWaitQueue = oldPool.getReconfigWaitQueue();
                        debug("checking reconfig-wait-queue for notification");
                        if (reconfigWaitQueue.getQueueContents().size() > 0) {
                            for (Object o : reconfigWaitQueue.getQueueContents()) {
                                debug("notifying reconfig-wait-queue object [ " + o + " ]");
                                synchronized (o) {
                                    o.notify();
                                }
                            }
                        }
                    } catch (InterruptedException ie) {
                        if (_logger.isLoggable(Level.FINEST)) {
                            _logger.log(Level.FINEST, "Interrupted while waiting for all existing clients to return connections to pool", ie);
                        }
                    }
                    if (_logger.isLoggable(Level.FINEST)) {
                        _logger.finest("woke-up after giving time for in-use connections to return, " + "WaitQueue-Length : [" + oldPool.getPoolWaitQueue().getQueueContents() + "], " + "Num-Conn-Used : [" + oldPool.getPoolStatus().getNumConnUsed() + "]");
                    }
                }
            };
            Callable c = Executors.callable(thread);
            ArrayList list = new ArrayList();
            list.add(c);
            try {
                execService.invokeAll(list);
            } catch (Exception e) {
                Object[] params = new Object[] { connConnPool.getName(), e };
                _logger.log(Level.WARNING, "exception.redeploying.pool.transparently", params);
            }
        } else {
            handlePoolRecreationForExistingProxies(connConnPool);
        }
    } else if (oldPool.getReconfigWaitTime() > 0) {
        // reconfig is being switched off, invalidate proxies
        Collection<BindableResource> resources = JdbcResourcesUtil.getResourcesOfPool(runtime.getResources(oldPool.getPoolInfo()), oldPool.getPoolInfo().getName());
        ConnectorRegistry registry = ConnectorRegistry.getInstance();
        for (BindableResource resource : resources) {
            ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(resource);
            registry.removeResourceFactories(resourceInfo);
        }
        // recreate the pool now.
        recreatePool(connConnPool);
    } else {
        recreatePool(connConnPool);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ArrayList(java.util.ArrayList) ResourcePool(com.sun.enterprise.resource.pool.ResourcePool) Callable(java.util.concurrent.Callable) MissingResourceException(java.util.MissingResourceException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Collection(java.util.Collection) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) PoolWaitQueue(com.sun.enterprise.resource.pool.waitqueue.PoolWaitQueue)

Aggregations

ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)71 NamingException (javax.naming.NamingException)16 URISyntaxException (java.net.URISyntaxException)13 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)13 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)10 PrivilegedActionException (java.security.PrivilegedActionException)9 ExecutionException (java.util.concurrent.ExecutionException)8 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)8 MultiException (org.glassfish.hk2.api.MultiException)8 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)7 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)7 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)7 ActiveResourceAdapter (com.sun.enterprise.connectors.ActiveResourceAdapter)5 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)5 IOException (java.io.IOException)5 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)4 JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)4 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)3