Search in sources :

Example 6 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class PingConnectionPool method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    boolean status = false;
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = "java:module/";
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = "java:app/";
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        return;
    }
    PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
    try {
        status = connRuntime.pingConnectionPool(poolInfo);
        if (status) {
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(localStrings.getLocalString("ping.connection.pool.fail", "Ping Connection Pool for {0} Failed", poolInfo));
        }
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("ping.connection.pool.fail", "Ping Connection Pool for {0} Failed", poolInfo));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ActionReport(org.glassfish.api.ActionReport)

Example 7 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class ConnectorConnPoolStatsProvider method decrementNumConnFreeEvent.

/**
 * Decrement numconnfree event
 * @param poolName
 */
@ProbeListener(JCA_PROBE_LISTENER + "decrementNumConnFreeEvent")
public void decrementNumConnFreeEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName, @ProbeParam("moduleName") String moduleName) {
    // handle the num conn free decrement event
    PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
    if (this.poolInfo.equals(poolInfo)) {
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("Decrement Num Connections Free event received - poolName = " + poolName);
        }
        // Decrement counter
        synchronized (numConnFree) {
            long numConnFreeSafe = (numConnFree.getCurrent() - 1 >= 0) ? numConnFree.getCurrent() - 1 : 0;
            numConnFree.setCurrent(numConnFreeSafe);
        }
    }
}
Also used : PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ProbeListener(org.glassfish.external.probe.provider.annotations.ProbeListener)

Example 8 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class ConnectorConnPoolStatsProvider method connectionRequestServedEvent.

/**
 * Event that a connection request is served in timeTakenInMillis.
 *
 * @param poolName
 * @param timeTakenInMillis
 */
@ProbeListener(JCA_PROBE_LISTENER + "connectionRequestServedEvent")
public void connectionRequestServedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName, @ProbeParam("moduleName") String moduleName, @ProbeParam("timeTakenInMillis") long timeTakenInMillis) {
    PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
    if (this.poolInfo.equals(poolInfo)) {
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("Connection request served event received - " + "poolName = " + poolName);
        }
        connRequestWaitTime.setCurrent(timeTakenInMillis);
        totalConnRequestWaitTime.increment(timeTakenInMillis);
    }
}
Also used : PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ProbeListener(org.glassfish.external.probe.provider.annotations.ProbeListener)

Example 9 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo 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 10 with PoolInfo

use of org.glassfish.resourcebase.resources.api.PoolInfo in project Payara by payara.

the class PoolManagerImpl method killFreeConnectionsInPools.

public void killFreeConnectionsInPools() {
    Iterator pools = poolTable.values().iterator();
    logFine("Killing all free connections in pools");
    while (pools.hasNext()) {
        ResourcePool pool = (ResourcePool) pools.next();
        if (pool != null) {
            PoolInfo poolInfo = pool.getPoolStatus().getPoolInfo();
            try {
                if (poolInfo != null) {
                    ResourcePool poolToKill = poolTable.get(poolInfo);
                    if (poolToKill != null) {
                        pool.emptyFreeConnectionsInPool();
                    }
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.fine("Now killing free connections in pool : " + poolInfo);
                    }
                }
            } catch (Exception e) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("Error killing pool : " + poolInfo + " :: " + (e.getMessage() != null ? e.getMessage() : " "));
                }
            }
        }
    }
}
Also used : PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) InvocationException(org.glassfish.api.invocation.InvocationException) RetryableUnavailableException(javax.resource.spi.RetryableUnavailableException)

Aggregations

PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)52 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)17 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)15 NamingException (javax.naming.NamingException)10 JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)9 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)7 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)7 ProbeListener (org.glassfish.external.probe.provider.annotations.ProbeListener)7 ResourceException (javax.resource.ResourceException)6 Property (org.jvnet.hk2.config.types.Property)5 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)4 Resources (com.sun.enterprise.config.serverbeans.Resources)4 ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)4 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)4 ArrayList (java.util.ArrayList)4 JdbcResource (org.glassfish.jdbc.config.JdbcResource)4 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)3 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)3 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)3 ActionReport (org.glassfish.api.ActionReport)3