Search in sources :

Example 1 with ConnectorRegistry

use of com.sun.enterprise.connectors.ConnectorRegistry 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)

Example 2 with ConnectorRegistry

use of com.sun.enterprise.connectors.ConnectorRegistry 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 3 with ConnectorRegistry

use of com.sun.enterprise.connectors.ConnectorRegistry in project Payara by payara.

the class InboundRecoveryHandler method createActiveResourceAdapter.

private void createActiveResourceAdapter(String rarModuleName) throws ConnectorRuntimeException {
    ConnectorRuntime cr = connectorRuntimeProvider.get();
    ConnectorRegistry creg = ConnectorRegistry.getInstance();
    if (creg.isRegistered(rarModuleName))
        return;
    if (ConnectorAdminServiceUtils.isEmbeddedConnectorModule(rarModuleName)) {
        cr.createActiveResourceAdapterForEmbeddedRar(rarModuleName);
    } else {
        String moduleDir;
        if (ConnectorsUtil.belongsToSystemRA(rarModuleName)) {
            moduleDir = ConnectorsUtil.getSystemModuleLocation(rarModuleName);
        } else {
            moduleDir = configBeansUtilities.getLocation(rarModuleName);
        }
        ClassLoader loader = cr.createConnectorClassLoader(moduleDir, null, rarModuleName);
        cr.createActiveResourceAdapter(moduleDir, rarModuleName, loader);
    }
}
Also used : ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) ConnectorRuntime(com.sun.appserv.connectors.internal.api.ConnectorRuntime)

Example 4 with ConnectorRegistry

use of com.sun.enterprise.connectors.ConnectorRegistry in project Payara by payara.

the class InboundRecoveryHandler method recoverInboundTransactions.

private void recoverInboundTransactions(List<XAResource> xaresList) {
    List<Application> applications = deployedApplications.getApplications();
    try {
        _logger.log(Level.INFO, "Recovery of Inbound Transactions started.");
        if (applications.size() == 0) {
            _logger.log(Level.FINE, "No applications deployed.");
            return;
        }
        // List of CMT enabled MDB descriptors on the application server instance.
        List<EjbDescriptor> xaEnabledMDBList = new ArrayList<EjbDescriptor>();
        // Done so as to initialize connectors-runtime before loading inbound active RA. need a better way ?
        ConnectorRuntime cr = connectorRuntimeProvider.get();
        for (Application application : applications) {
            Vector ejbDescVec = getEjbDescriptors(application, appsRegistry);
            for (int j = 0; j < ejbDescVec.size(); j++) {
                EjbDescriptor desc = (EjbDescriptor) ejbDescVec.elementAt(j);
                // add it to the list of xaEnabledMDBList.
                if (desc instanceof EjbMessageBeanDescriptor && desc.getTransactionType().equals(EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
                    xaEnabledMDBList.add(desc);
                    _logger.log(Level.FINE, "Found a CMT MDB: " + desc.getEjbClassName());
                }
            }
        }
        if (xaEnabledMDBList.size() == 0) {
            _logger.log(Level.FINE, "Found no CMT MDBs in all applications");
            return;
        }
        ConnectorRegistry creg = ConnectorRegistry.getInstance();
        // for each RA (key in the map) get the list (value) of MDB Descriptors
        Map<String, List<EjbDescriptor>> mappings = createRAEjbMapping(xaEnabledMDBList);
        // For each RA
        for (Map.Entry entry : mappings.entrySet()) {
            String raMid = (String) entry.getKey();
            List<EjbDescriptor> respectiveDesc = mappings.get(raMid);
            try {
                createActiveResourceAdapter(raMid);
            } catch (Exception ex) {
                _logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", raMid);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, ex.toString(), ex);
                }
            }
            ActiveInboundResourceAdapter activeInboundRA = (ActiveInboundResourceAdapter) creg.getActiveResourceAdapter(raMid);
            // assert activeInboundRA instanceof ActiveInboundResourceAdapter;
            boolean isSystemJmsRA = false;
            if (ConnectorsUtil.isJMSRA(activeInboundRA.getModuleName())) {
                isSystemJmsRA = true;
            }
            javax.resource.spi.ResourceAdapter resourceAdapter = activeInboundRA.getResourceAdapter();
            // activationSpecList represents the ActivationSpec[] that would be
            // sent to the getXAResources() method.
            ArrayList<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
            try {
                for (int i = 0; i < respectiveDesc.size(); i++) {
                    try {
                        // Get a MessageBeanDescriptor from respectiveDesc ArrayList
                        EjbMessageBeanDescriptor descriptor = (EjbMessageBeanDescriptor) respectiveDesc.get(i);
                        // to be updated J2EE 1.4 style props.
                        if (isSystemJmsRA) {
                            // XXX: Find out the pool descriptor corres to MDB and update
                            // MDBRuntimeInfo with that.
                            activeInboundRA.updateMDBRuntimeInfo(descriptor, null);
                        }
                        // Get the ActivationConfig Properties from the MDB Descriptor
                        Set activationConfigProps = RARUtils.getMergedActivationConfigProperties(descriptor);
                        // get message listener type
                        String msgListenerType = descriptor.getMessageListenerType();
                        // start resource adapter and get ActivationSpec class for
                        // the given message listener type from the ConnectorRuntime
                        ActivationSpec aspec = (ActivationSpec) (Class.forName(cr.getActivationSpecClass(raMid, msgListenerType), false, resourceAdapter.getClass().getClassLoader()).newInstance());
                        aspec.setResourceAdapter(resourceAdapter);
                        // Populate ActivationSpec class with ActivationConfig properties
                        SetMethodAction sma = new SetMethodAction(aspec, activationConfigProps);
                        sma.run();
                        activationSpecList.add(aspec);
                    } catch (Exception e) {
                        _logger.log(Level.WARNING, "error.creating.activationspec", e.getMessage());
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, e.toString(), e);
                        }
                    }
                }
                // Get XA resources from RA.
                ActivationSpec[] activationSpecArray = activationSpecList.toArray(new ActivationSpec[activationSpecList.size()]);
                XAResource[] xar = resourceAdapter.getXAResources(activationSpecArray);
                // Add the resources to the xaresList which is used by the RecoveryManager
                if (xar != null) {
                    for (int p = 0; p < xar.length; p++) {
                        xaresList.add(xar[p]);
                    }
                }
            // Catch UnsupportedOperationException if a RA does not support XA
            // which is fine.
            } catch (UnsupportedOperationException uoex) {
                _logger.log(Level.FINE, uoex.getMessage());
            // otherwise catch the unexpected exception
            } catch (Exception e) {
                _logger.log(Level.SEVERE, "exception.during.inbound.resource.acqusition", e);
            }
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, "exception.during.inbound.recovery", e);
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) Vector(java.util.Vector) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) XAResource(javax.transaction.xa.XAResource) EjbMessageBeanDescriptor(com.sun.enterprise.deployment.EjbMessageBeanDescriptor) ActivationSpec(javax.resource.spi.ActivationSpec) Application(com.sun.enterprise.config.serverbeans.Application) HashMap(java.util.HashMap) Map(java.util.Map) ConnectorRuntime(com.sun.appserv.connectors.internal.api.ConnectorRuntime) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Example 5 with ConnectorRegistry

use of com.sun.enterprise.connectors.ConnectorRegistry in project Payara by payara.

the class ConnectorDeployer method registerBeanValidator.

private void registerBeanValidator(String rarName, ReadableArchive archive, ClassLoader classLoader) {
    ClassLoader contextCL = null;
    try {
        contextCL = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        Validator beanValidator = null;
        ValidatorFactory validatorFactory = null;
        try {
            List<String> mappingsList = getValidationMappingDescriptors(archive);
            if (mappingsList.size() > 0) {
                GenericBootstrap bootstrap = Validation.byDefaultProvider();
                Configuration config = bootstrap.configure();
                InputStream inputStream = null;
                try {
                    for (String fileName : mappingsList) {
                        inputStream = archive.getEntry(fileName);
                        config.addMapping(inputStream);
                    }
                    validatorFactory = config.buildValidatorFactory();
                    ValidatorContext validatorContext = validatorFactory.usingContext();
                    beanValidator = validatorContext.getValidator();
                } catch (IOException e) {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "Exception while processing xml files for detecting " + "bean-validation-mapping", e);
                    }
                } finally {
                    try {
                        if (inputStream != null) {
                            inputStream.close();
                        }
                    } catch (Exception e) {
                    // ignore ?
                    }
                }
            }
        } catch (Exception e) {
            Object[] params = new Object[] { rarName, e };
            _logger.log(Level.WARNING, "error.processing.xml.for.bean.validation.mapping", params);
        }
        if (beanValidator == null) {
            validatorFactory = Validation.byDefaultProvider().configure().buildValidatorFactory();
            beanValidator = validatorFactory.getValidator();
        }
        ConnectorRegistry registry = ConnectorRegistry.getInstance();
        registry.addBeanValidator(rarName, beanValidator);
    } finally {
        Thread.currentThread().setContextClassLoader(contextCL);
    }
}
Also used : DelegatingClassLoader(org.glassfish.internal.api.DelegatingClassLoader) GenericBootstrap(javax.validation.bootstrap.GenericBootstrap) ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) PropertyVetoException(java.beans.PropertyVetoException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Aggregations

ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)8 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)4 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)3 ConnectorRuntime (com.sun.appserv.connectors.internal.api.ConnectorRuntime)2 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)2 ArrayList (java.util.ArrayList)2 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)2 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)2 Application (com.sun.enterprise.config.serverbeans.Application)1 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)1 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)1 Resources (com.sun.enterprise.config.serverbeans.Resources)1 ConnectionManagerImpl (com.sun.enterprise.connectors.ConnectionManagerImpl)1 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)1 SetMethodAction (com.sun.enterprise.connectors.util.SetMethodAction)1 ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)1 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)1 ResourcePool (com.sun.enterprise.resource.pool.ResourcePool)1