Search in sources :

Example 1 with ResourceInfo

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

the class ConnectionPoolHealthCheck method doCheck.

@Override
public HealthCheckResult doCheck() {
    HealthCheckResult result = new HealthCheckResult();
    Collection<JdbcResource> allJdbcResources = getAllJdbcResources();
    for (JdbcResource resource : allJdbcResources) {
        ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(resource);
        JdbcConnectionPool pool = JdbcResourcesUtil.createInstance().getJdbcConnectionPoolOfResource(resourceInfo);
        PoolInfo poolInfo = ResourceUtil.getPoolInfo(pool);
        if (getOptions().getPoolName() != null) {
            if (getOptions().getPoolName().equals(poolInfo.getName())) {
                evaluatePoolUsage(result, poolInfo);
            }
        } else {
            evaluatePoolUsage(result, poolInfo);
        }
    }
    return result;
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) HealthCheckResult(fish.payara.nucleus.healthcheck.HealthCheckResult) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 2 with ResourceInfo

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

the class AdminObjectResourceDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
    final AdminObjectResource aor = (AdminObjectResource) resource;
    ResourceInfo resourceInfo = new ResourceInfo(aor.getJndiName(), applicationName, moduleName);
    deleteAdminObjectResource(aor, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource)

Example 3 with ResourceInfo

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

the class AdminObjectResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
public synchronized void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
    final AdminObjectResource aor = (AdminObjectResource) resource;
    String jndiName = aor.getJndiName();
    ResourceInfo resourceInfo = new ResourceInfo(jndiName, applicationName, moduleName);
    createAdminObjectResource(aor, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource)

Example 4 with ResourceInfo

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

the class AdminObjectResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
public synchronized void deployResource(Object resource) throws Exception {
    final AdminObjectResource aor = (AdminObjectResource) resource;
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(aor);
    createAdminObjectResource(aor, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource)

Example 5 with ResourceInfo

use of org.glassfish.resourcebase.resources.api.ResourceInfo 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)

Aggregations

ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)81 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)15 NamingException (javax.naming.NamingException)14 JdbcResource (org.glassfish.jdbc.config.JdbcResource)9 Test (org.junit.Test)9 ContextServiceImpl (org.glassfish.enterprise.concurrent.ContextServiceImpl)8 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)7 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)6 RefAddr (javax.naming.RefAddr)5 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)5 Resources (com.sun.enterprise.config.serverbeans.Resources)4 ResourceException (javax.resource.ResourceException)4 ContextService (org.glassfish.concurrent.config.ContextService)4 ManagedThreadFactory (org.glassfish.concurrent.config.ManagedThreadFactory)4 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)4 CustomResource (org.glassfish.resources.config.CustomResource)4 MailResource (org.glassfish.resources.javamail.config.MailResource)4 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)3 ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)3 ManagedScheduledExecutorService (org.glassfish.concurrent.config.ManagedScheduledExecutorService)3