/** Releases all instances bound to this dispatcher instance. */ public void cleanup() { // clean up ObjectFactory ObjectFactory objectFactory = getContainer().getInstance(ObjectFactory.class); if (objectFactory == null) { if (LOG.isWarnEnabled()) { LOG.warn( "Object Factory is null, something is seriously wrong, no clean up will be performed"); } } if (objectFactory instanceof ObjectFactoryDestroyable) { try { ((ObjectFactoryDestroyable) objectFactory).destroy(); } catch (Exception e) { // catch any exception that may occurred during destroy() and log it LOG.error( "exception occurred while destroying ObjectFactory [#0]", e, objectFactory.toString()); } } // clean up Dispatcher itself for this thread instance.set(null); // clean up DispatcherListeners if (!dispatcherListeners.isEmpty()) { for (DispatcherListener l : dispatcherListeners) { l.dispatcherDestroyed(this); } } // clean up all interceptors by calling their destroy() method Set<Interceptor> interceptors = new HashSet<Interceptor>(); Collection<PackageConfig> packageConfigs = configurationManager.getConfiguration().getPackageConfigs().values(); for (PackageConfig packageConfig : packageConfigs) { for (Object config : packageConfig.getAllInterceptorConfigs().values()) { if (config instanceof InterceptorStackConfig) { for (InterceptorMapping interceptorMapping : ((InterceptorStackConfig) config).getInterceptors()) { interceptors.add(interceptorMapping.getInterceptor()); } } } } for (Interceptor interceptor : interceptors) { interceptor.destroy(); } // Clear container holder when application is unloaded / server shutdown ContainerHolder.clear(); // cleanup action context ActionContext.setContext(null); // clean up configuration configurationManager.destroyConfiguration(); configurationManager = null; }