Search in sources :

Example 66 with ResourceInfo

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

the class DataSourceDefinitionDeployer method registerDSDReferredByApplication.

private void registerDSDReferredByApplication(String appName, DataSourceDefinitionDescriptor dsd) {
    // DSD is bound to JNDI only when it is not already deployed.
    if (!dsd.isDeployed()) {
        CommonResourceProxy proxy = dataSourceDefinitionProxyProvider.get();
        ResourceNamingService resourceNamingService = resourceNamingServiceProvider.get();
        proxy.setDescriptor(dsd);
        String dsdName = dsd.getName();
        if (dsdName.startsWith(JAVA_APP_SCOPE_PREFIX)) {
            dsd.setResourceId(appName);
        }
        if (dsdName.startsWith(JAVA_GLOBAL_SCOPE_PREFIX) || dsdName.startsWith(JAVA_APP_SCOPE_PREFIX)) {
            ResourceInfo resourceInfo = new ResourceInfo(dsdName, appName, null);
            try {
                resourceNamingService.publishObject(resourceInfo, proxy, true);
                dsd.setDeployed(true);
            } catch (NamingException e) {
                _logger.log(Level.WARNING, "dsd.registration.failed", new Object[] { appName, dsdName, e });
            }
        }
    }
}
Also used : CommonResourceProxy(org.glassfish.javaee.services.CommonResourceProxy) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ResourceNamingService(org.glassfish.resourcebase.resources.naming.ResourceNamingService) NamingException(javax.naming.NamingException)

Example 67 with ResourceInfo

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

the class JdbcResourceDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void undeployResource(Object resource) throws Exception {
    JdbcResource jdbcRes = (JdbcResource) resource;
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcRes);
    deleteResource(jdbcRes, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

Example 68 with ResourceInfo

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

the class JdbcResourceDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
@Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
    JdbcResource jdbcRes = (JdbcResource) resource;
    ResourceInfo resourceInfo = new ResourceInfo(jdbcRes.getJndiName(), applicationName, moduleName);
    deleteResource(jdbcRes, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

Example 69 with ResourceInfo

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

the class JdbcResourceDeployer method checkAndDeletePool.

/**
 * Checks if no more resource-refs to resources exists for the
 * JDBC connection pool and then deletes the pool
 *
 * @param cr Jdbc Resource Config bean
 * @throws Exception if unable to access configuration/undeploy resource.
 * @since 8.1 pe/se/ee
 */
private void checkAndDeletePool(JdbcResource cr) throws Exception {
    String poolName = cr.getPoolName();
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(cr);
    PoolInfo poolInfo = new PoolInfo(poolName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
    Resources resources = (Resources) cr.getParent();
    // Its possible that the JdbcResource here is a DataSourceDefinition. Ignore optimization.
    if (resources != null) {
        try {
            boolean poolReferred = JdbcResourcesUtil.createInstance().isJdbcPoolReferredInServerInstance(poolInfo);
            if (!poolReferred) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("Deleting JDBC pool [" + poolName + " ] as there are no more " + "resource-refs to the pool in this server instance");
                }
                JdbcConnectionPool jcp = (JdbcConnectionPool) ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, poolName);
                // Delete/Undeploy Pool
                runtime.getResourceDeployer(jcp).undeployResource(jcp);
            }
        } catch (Exception ce) {
            _logger.warning(ce.getMessage());
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("Exception while deleting pool [ " + poolName + " ] : " + ce);
            }
            throw ce;
        }
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) Resources(com.sun.enterprise.config.serverbeans.Resources) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException)

Example 70 with ResourceInfo

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

the class JdbcResourcesUtil method isJdbcPoolReferredInServerInstance.

/**
 * Determines if a JDBC connection pool is referred in a
 * server-instance via resource-refs
 * @param poolInfo pool-name
 * @return boolean true if pool is referred in this server instance as well enabled, false
 * otherwise
 */
public boolean isJdbcPoolReferredInServerInstance(PoolInfo poolInfo) {
    Collection<JdbcResource> jdbcResources = getRuntime().getResources(poolInfo).getResources(JdbcResource.class);
    for (JdbcResource resource : jdbcResources) {
        ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(resource);
        // Have to check isReferenced here!
        if ((resource.getPoolName().equalsIgnoreCase(poolInfo.getName())) && ResourcesUtil.createInstance().isReferenced(resourceInfo) && ResourcesUtil.createInstance().isEnabled(resource)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("pool " + poolInfo + "resource " + resourceInfo + " referred " + ResourcesUtil.createInstance().isReferenced(resourceInfo));
                _logger.fine("JDBC resource " + resource.getJndiName() + "refers " + poolInfo + "in this server instance and is enabled");
            }
            return true;
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("No JDBC resource refers [ " + poolInfo + " ] in this server instance");
    }
    return false;
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

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