Search in sources :

Example 1 with ResourceBeforeDestroyed

use of org.apache.openejb.assembler.classic.event.ResourceBeforeDestroyed in project tomee by apache.

the class Assembler method doResourceDestruction.

private void doResourceDestruction(final String name, final String className, final Object jndiObject) {
    final ResourceBeforeDestroyed event = new ResourceBeforeDestroyed(jndiObject, name);
    SystemInstance.get().fireEvent(event);
    final Object object = event.getReplacement() == null ? jndiObject : event.getReplacement();
    if (object instanceof ResourceAdapterReference) {
        final ResourceAdapterReference resourceAdapter = (ResourceAdapterReference) object;
        try {
            logger.info("Stopping ResourceAdapter: " + name);
            if (logger.isDebugEnabled()) {
                logger.debug("Stopping ResourceAdapter: " + className);
            }
            if (resourceAdapter.pool != null && ExecutorService.class.isInstance(resourceAdapter.pool)) {
                ExecutorService.class.cast(resourceAdapter.pool).shutdownNow();
            }
            resourceAdapter.ra.stop();
        } catch (final Throwable t) {
            logger.fatal("ResourceAdapter Shutdown Failed: " + name, t);
        }
    } else if (object instanceof ResourceAdapter) {
        final ResourceAdapter resourceAdapter = (ResourceAdapter) object;
        try {
            logger.info("Stopping ResourceAdapter: " + name);
            if (logger.isDebugEnabled()) {
                logger.debug("Stopping ResourceAdapter: " + className);
            }
            resourceAdapter.stop();
        } catch (final Throwable t) {
            logger.fatal("ResourceAdapter Shutdown Failed: " + name, t);
        }
    } else if (DataSourceFactory.knows(object)) {
        logger.info("Closing DataSource: " + name);
        try {
            DataSourceFactory.destroy(object);
        } catch (final Throwable t) {
        //Ignore
        }
    } else if (object instanceof ConnectorReference) {
        final ConnectorReference cr = (ConnectorReference) object;
        try {
            final ConnectionManager cm = cr.getConnectionManager();
            if (cm != null && cm instanceof AbstractConnectionManager) {
                ((AbstractConnectionManager) cm).doStop();
            }
        } catch (final Exception e) {
            logger.debug("Not processing resource on destroy: " + className, e);
        }
    } else if (DestroyableResource.class.isInstance(object)) {
        try {
            DestroyableResource.class.cast(object).destroyResource();
        } catch (final RuntimeException e) {
            logger.error(e.getMessage(), e);
        }
    } else if (logger.isDebugEnabled() && !DataSource.class.isInstance(object)) {
        logger.debug("Not processing resource on destroy: " + className);
    }
}
Also used : DestroyableResource(org.apache.openejb.api.resource.DestroyableResource) AbstractConnectionManager(org.apache.geronimo.connector.outbound.AbstractConnectionManager) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) DataSource(javax.sql.DataSource) AbstractConnectionManager(org.apache.geronimo.connector.outbound.AbstractConnectionManager) ConnectionManager(javax.resource.spi.ConnectionManager) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) ExecutorService(java.util.concurrent.ExecutorService) ResourceAdapter(javax.resource.spi.ResourceAdapter) ResourceBeforeDestroyed(org.apache.openejb.assembler.classic.event.ResourceBeforeDestroyed) ConnectorReference(org.apache.openejb.core.ConnectorReference)

Aggregations

IOException (java.io.IOException)1 InvalidObjectException (java.io.InvalidObjectException)1 ObjectStreamException (java.io.ObjectStreamException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 DefinitionException (javax.enterprise.inject.spi.DefinitionException)1 DeploymentException (javax.enterprise.inject.spi.DeploymentException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1 ConnectionManager (javax.resource.spi.ConnectionManager)1 ResourceAdapter (javax.resource.spi.ResourceAdapter)1 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)1 DataSource (javax.sql.DataSource)1 ValidationException (javax.validation.ValidationException)1