Search in sources :

Example 1 with ResourcePool

use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.

the class JdbcPoolMonitoringExtension method registerConnectionPool.

/**
 * Register the jdbc connection pool Stats Provider object to the
 * monitoring framework under the specific application name monitoring
 * sub tree.
 *
 * @param appName
 * @return
 */
@Override
public ConnectionPoolAppProbeProvider registerConnectionPool(PoolInfo poolInfo, String appName) {
    ConnectionPoolAppProbeProvider probeAppProvider = null;
    ResourcePool pool = runtime.getConnectionPoolConfig(poolInfo);
    if (pool instanceof JdbcConnectionPool) {
        probeAppProvider = new JdbcConnPoolAppProbeProvider();
        JdbcConnPoolAppStatsProvider jdbcPoolAppStatsProvider = new JdbcConnPoolAppStatsProvider(poolInfo, appName);
        StatsProviderManager.register("jdbc-connection-pool", PluginPoint.SERVER, "resources/" + ConnectorsUtil.escapeResourceNameForMonitoring(poolInfo.getName()) + "/" + appName, jdbcPoolAppStatsProvider);
        jdbcPoolAppStatsProviders.add(jdbcPoolAppStatsProvider);
    }
    return probeAppProvider;
}
Also used : JdbcConnPoolAppStatsProvider(org.glassfish.jdbc.pool.monitor.JdbcConnPoolAppStatsProvider) ConnectionPoolAppProbeProvider(com.sun.enterprise.resource.pool.monitor.ConnectionPoolAppProbeProvider) JdbcConnPoolAppProbeProvider(org.glassfish.jdbc.pool.monitor.JdbcConnPoolAppProbeProvider) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool)

Example 2 with ResourcePool

use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.

the class ConnectionPoolStatsProviderBootstrap method poolCreated.

/**
 * When a pool is created (or initialized) the pool should be registered
 * to the  StatsProviderManager. Also, the pool lifecycle
 * listener needs to be registered for this pool to track events on change
 * of any monitoring attributes.
 * @param poolInfo
 */
public void poolCreated(PoolInfo poolInfo) {
    if (logger.isLoggable(Level.FINEST)) {
        logger.finest("Pool created : " + poolInfo);
    }
    if (runtime.isServer()) {
        ResourcePool pool = runtime.getConnectionPoolConfig(poolInfo);
        Collection<ConnectionPoolMonitoringExtension> extensions = habitat.getAllServices(ConnectionPoolMonitoringExtension.class);
        for (ConnectionPoolMonitoringExtension extension : extensions) {
            extension.registerPool(poolInfo);
        }
        if (pool instanceof ConnectorConnectionPool) {
            registerCcPool(poolInfo);
        }
    /*else if (poolInfo.getName().contains(ConnectorConstants.DATASOURCE_DEFINITION_JNDINAME_PREFIX)){
                registerJdbcPool(poolInfo);
            }*/
    }
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) ConnectionPoolMonitoringExtension(com.sun.enterprise.connectors.ConnectionPoolMonitoringExtension)

Example 3 with ResourcePool

use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.

the class ConnectionPoolStatsProviderBootstrap method registerCcPool.

/**
 * Register connector connection pool to the StatsProviderManager.
 * Add the pool lifecycle listeners for the pool to receive events on
 * change of any of the monitoring attribute values.
 * Finally, add this provider to the list of connector connection pool
 * providers maintained.
 * @param poolInfo
 */
private void registerCcPool(PoolInfo poolInfo) {
    if (poolManager.getPool(poolInfo) != null) {
        getProbeProviderUtil().createJcaProbeProvider();
        // Found in the pool table (pool has been initialized/created)
        ConnectorConnPoolStatsProvider ccPoolStatsProvider = new ConnectorConnPoolStatsProvider(poolInfo, logger);
        StatsProviderManager.register("connector-connection-pool", PluginPoint.SERVER, ConnectorsUtil.getPoolMonitoringSubTreeRoot(poolInfo, true), ccPoolStatsProvider);
        PoolLifeCycleListenerRegistry registry = registerPool(poolInfo, getProbeProviderUtil().getJcaProbeProvider());
        ccPoolStatsProvider.setPoolRegistry(registry);
        ccStatsProviders.add(ccPoolStatsProvider);
        if (!ConnectorsUtil.isApplicationScopedResource(poolInfo)) {
            ResourcesUtil resourcesUtil = ResourcesUtil.createInstance();
            ResourcePool pool = resourcesUtil.getPoolConfig(poolInfo);
            Resources resources = resourcesUtil.getResources(poolInfo);
            String raName = resourcesUtil.getRarNameOfResource(pool, resources);
            ConnectorConnPoolStatsProvider connectorServicePoolStatsProvider = new ConnectorConnPoolStatsProvider(poolInfo, logger);
            String dottedNamesHierarchy = null;
            String monitoringModuleName = null;
            if (ConnectorsUtil.isJMSRA(raName)) {
                monitoringModuleName = ConnectorConstants.MONITORING_JMS_SERVICE_MODULE_NAME;
                dottedNamesHierarchy = ConnectorConstants.MONITORING_JMS_SERVICE + ConnectorConstants.MONITORING_SEPARATOR + ConnectorConstants.MONITORING_CONNECTION_FACTORIES + ConnectorConstants.MONITORING_SEPARATOR + ConnectorsUtil.escapeResourceNameForMonitoring(poolInfo.getName());
            } else {
                monitoringModuleName = ConnectorConstants.MONITORING_CONNECTOR_SERVICE_MODULE_NAME;
                dottedNamesHierarchy = ConnectorConstants.MONITORING_CONNECTOR_SERVICE_MODULE_NAME + ConnectorConstants.MONITORING_SEPARATOR + raName + ConnectorConstants.MONITORING_SEPARATOR + ConnectorsUtil.escapeResourceNameForMonitoring(poolInfo.getName());
            }
            StatsProviderManager.register(monitoringModuleName, PluginPoint.SERVER, dottedNamesHierarchy, connectorServicePoolStatsProvider);
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Registered pool-monitoring stats [ " + dottedNamesHierarchy + " ]  " + "for [ " + raName + " ] with monitoring-stats-registry.");
            }
            /* no need to create multiple probe provider instances, one per pool will
                   work for multiple stats providers 
                PoolLifeCycleListenerRegistry poolLifeCycleListenerRegistry = registerPool(
                        poolInfo, getProbeProviderUtil().getJcaProbeProvider());
                */
            connectorServicePoolStatsProvider.setPoolRegistry(registry);
            ccStatsProviders.add(connectorServicePoolStatsProvider);
        }
    }
}
Also used : PoolLifeCycleListenerRegistry(com.sun.enterprise.resource.pool.PoolLifeCycleListenerRegistry) ResourcesUtil(com.sun.enterprise.connectors.util.ResourcesUtil) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 4 with ResourcePool

use of com.sun.enterprise.config.serverbeans.ResourcePool 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 ResourcePool

use of com.sun.enterprise.config.serverbeans.ResourcePool in project Payara by payara.

the class AppSpecificConnectorClassLoaderUtil method getModuleScopedResource.

private <T> Resource getModuleScopedResource(String name, String moduleName, Class<T> type, ApplicationInfo appInfo) {
    Resource foundRes = null;
    if (appInfo != null) {
        com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
        Resources resources = null;
        if (app != null) {
            Module module = null;
            List<Module> modules = app.getModule();
            for (Module m : modules) {
                if (ConnectorsUtil.getActualModuleName(m.getName()).equals(moduleName)) {
                    module = m;
                    break;
                }
            }
            if (module != null) {
                resources = appInfo.getTransientAppMetaData(module.getName() + "-resources", Resources.class);
            }
        }
        if (resources != null) {
            boolean bindableResource = BindableResource.class.isAssignableFrom(type);
            boolean poolResource = ResourcePool.class.isAssignableFrom(type);
            boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
            boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
            Iterator itr = resources.getResources().iterator();
            while (itr.hasNext()) {
                String resourceName = null;
                Resource res = (Resource) itr.next();
                if (bindableResource && res instanceof BindableResource) {
                    resourceName = ((BindableResource) res).getJndiName();
                } else if (poolResource && res instanceof ResourcePool) {
                    resourceName = ((ResourcePool) res).getName();
                } else if (rac && res instanceof ResourceAdapterConfig) {
                    resourceName = ((ResourceAdapterConfig) res).getName();
                } else if (workSecurityMap && res instanceof WorkSecurityMap) {
                    resourceName = ((WorkSecurityMap) res).getName();
                }
                if (resourceName != null) {
                    if (!(resourceName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
                        resourceName = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + resourceName;
                    }
                    if (!(name.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
                        name = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + name;
                    }
                    if (name.equals(resourceName)) {
                        foundRes = res;
                        break;
                    }
                }
            }
        }
    }
    return foundRes;
}
Also used : AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module)

Aggregations

ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)12 Resources (com.sun.enterprise.config.serverbeans.Resources)5 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)4 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)3 Resource (com.sun.enterprise.config.serverbeans.Resource)3 Iterator (java.util.Iterator)2 NamingException (javax.naming.NamingException)2 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)2 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)2 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)2 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)2 ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)2 WorkSecurityMap (org.glassfish.connectors.config.WorkSecurityMap)2 JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)2 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Module (com.sun.enterprise.config.serverbeans.Module)1 Server (com.sun.enterprise.config.serverbeans.Server)1 ConnectionManagerImpl (com.sun.enterprise.connectors.ConnectionManagerImpl)1 ConnectionPoolMonitoringExtension (com.sun.enterprise.connectors.ConnectionPoolMonitoringExtension)1