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);
}
}
Aggregations