use of org.apache.openejb.assembler.classic.event.ContainerSystemPreDestroy in project tomee by apache.
the class Assembler method destroy.
@Override
public void destroy() {
final ReentrantLock l = lock;
l.lock();
try {
final SystemInstance systemInstance = SystemInstance.get();
systemInstance.fireEvent(new ContainerSystemPreDestroy());
try {
EjbTimerServiceImpl.shutdown();
} catch (final Exception e) {
logger.warning("Unable to shutdown scheduler", e);
} catch (final NoClassDefFoundError ncdfe) {
// no-op
}
logger.debug("Undeploying Applications");
final Assembler assembler = this;
final List<AppInfo> deployedApps = new ArrayList<>(assembler.getDeployedApplications());
// if an app relies on the previous one it surely relies on it too at undeploy time
Collections.reverse(deployedApps);
for (final AppInfo appInfo : deployedApps) {
try {
assembler.destroyApplication(appInfo.path);
} catch (final UndeployException e) {
logger.error("Undeployment failed: " + appInfo.path, e);
} catch (final NoSuchApplicationException e) {
// Ignore
}
}
final Iterator<ObjectName> it = containerObjectNames.iterator();
final MBeanServer server = LocalMBeanServer.get();
while (it.hasNext()) {
try {
server.unregisterMBean(it.next());
} catch (final Exception ignored) {
// no-op
}
it.remove();
}
try {
remoteResourceMonitor.unregister();
} catch (final Exception ignored) {
// no-op
}
NamingEnumeration<Binding> namingEnumeration = null;
try {
namingEnumeration = containerSystem.getJNDIContext().listBindings("openejb/Resource");
} catch (final NamingException ignored) {
// no resource adapters were created
}
destroyResourceTree("", namingEnumeration);
try {
containerSystem.getJNDIContext().unbind("java:global");
} catch (final NamingException ignored) {
// no-op
}
systemInstance.removeComponent(OpenEjbConfiguration.class);
systemInstance.removeComponent(JtaEntityManagerRegistry.class);
systemInstance.removeComponent(TransactionSynchronizationRegistry.class);
systemInstance.removeComponent(EjbResolver.class);
systemInstance.removeComponent(ThreadSingletonService.class);
systemInstance.fireEvent(new AssemblerDestroyed());
systemInstance.removeObservers();
if (DestroyableResource.class.isInstance(this.securityService)) {
DestroyableResource.class.cast(this.securityService).destroyResource();
}
if (DestroyableResource.class.isInstance(this.transactionManager)) {
DestroyableResource.class.cast(this.transactionManager).destroyResource();
}
for (final Container c : this.containerSystem.containers()) {
if (DestroyableResource.class.isInstance(c)) {
// TODO: should we use auto closeable there?
DestroyableResource.class.cast(c).destroyResource();
}
}
SystemInstance.reset();
} finally {
l.unlock();
}
}
Aggregations