List of usage examples for org.springframework.web.context ConfigurableWebApplicationContext close
@Override
void close();
From source file:org.red5.server.winstone.WinstoneApplicationContext.java
public void stop() { log.debug("stop"); try {// w ww . j a v a2 s. c o m Object o = context.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (o != null) { log.debug("Spring context for {} was found", context.getContextName()); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) o; //close the red5 app if (appCtx.isRunning()) { log.debug("Context was running, attempting to stop"); appCtx.stop(); } if (appCtx.isActive()) { log.debug("Context is active, attempting to close"); appCtx.close(); } } else { log.warn("Spring context for {} was not found", context.getContextName()); } } catch (Exception e) { log.error("Could not stop spring context", e); } context.destroy(); }
From source file:org.red5.server.undertow.UndertowApplicationContext.java
/** * Stop the application and servlet contexts. *///from w ww.j av a2 s. c o m public void stop() { log.debug("stop"); try { Deployment deployment = manager.getDeployment(); ServletContextImpl servlet = deployment.getServletContext(); Object o = servlet.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (o != null) { log.debug("Spring context for {} was found", deployment.getDeploymentInfo().getContextPath()); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) o; // close the red5 app if (appCtx.isRunning()) { log.debug("Context was running, attempting to stop"); appCtx.stop(); } if (appCtx.isActive()) { log.debug("Context is active, attempting to close"); appCtx.close(); } } else { log.warn("Spring context for {} was not found", deployment.getDeploymentInfo().getContextPath()); } } catch (Exception e) { log.error("Could not stop spring context", e); } manager.undeploy(); }
From source file:org.red5.server.tomcat.TomcatApplicationContext.java
public void stop() { log.debug("stop"); try {/*from w w w . ja v a 2 s .com*/ ServletContext servlet = context.getServletContext(); Object o = servlet.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (o != null) { log.debug("Spring context for {} was found", context.getName()); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) o; //close the red5 app if (appCtx.isRunning()) { log.debug("Context was running, attempting to stop"); appCtx.stop(); } if (appCtx.isActive()) { log.debug("Context is active, attempting to close"); appCtx.close(); } } else { log.warn("Spring context for {} was not found", context.getName()); } } catch (Exception e) { log.error("Could not stop spring context", e); } context.getParent().removeChild(context); if (context instanceof StandardContext) { StandardContext ctx = (StandardContext) context; try { //stop the tomcat context ctx.stop(); } catch (Exception e) { log.error("Could not stop context", e); } finally { try { ctx.destroy(); } catch (Exception e) { log.error("Could not destroy context", e); } } } }
From source file:org.red5.server.war.RootContextLoaderServlet.java
/** * Clearing the in-memory configuration parameters, we will receive * notification that the servlet context is about to be shut down *///from w w w.j av a 2 s . co m @Override public void contextDestroyed(ServletContextEvent sce) { synchronized (instance) { logger.info("Webapp shutdown"); // XXX Paul: grabbed this from // http://opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won%27t+let+go // in hopes that we can clear all the issues with J2EE containers // during shutdown try { ServletContext ctx = sce.getServletContext(); // if the ctx being destroyed is root then kill the timer if (ctx.getContextPath().equals("/ROOT")) { timer.cancel(); } else { // remove from registered list registeredContexts.remove(ctx); } // prepare spring for shutdown Introspector.flushCaches(); // dereg any drivers for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();) { Driver driver = (Driver) e.nextElement(); if (driver.getClass().getClassLoader() == getClass().getClassLoader()) { DriverManager.deregisterDriver(driver); } } // shutdown jmx JMXAgent.shutdown(); // shutdown spring Object attr = ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (attr != null) { // get web application context from the servlet context ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) attr; ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); // for (String scope : factory.getRegisteredScopeNames()) { // logger.debug("Registered scope: " + scope); // } try { for (String singleton : factory.getSingletonNames()) { logger.debug("Registered singleton: " + singleton); factory.destroyScopedBean(singleton); } } catch (RuntimeException e) { } factory.destroySingletons(); ctx.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); applicationContext.close(); } instance.getContextLoader().closeWebApplicationContext(ctx); } catch (Throwable e) { e.printStackTrace(); } finally { // http://jakarta.apache.org/commons/logging/guide.html#Classloader_and_Memory_Management // http://wiki.apache.org/jakarta-commons/Logging/UndeployMemoryLeak?action=print LogFactory.release(Thread.currentThread().getContextClassLoader()); } } }
From source file:org.red5.server.war.MainServlet.java
/** * Clearing the in-memory configuration parameters, we will receive * notification that the servlet context is about to be shut down */// w w w . j ava 2 s . c o m public void contextDestroyed(ServletContextEvent sce) { logger.info("Webapp shutdown"); // XXX Paul: grabbed this from // http://opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won%27t+let+go // in hopes that we can clear all the issues with J2EE containers during // shutdown try { // prepare spring for shutdown Introspector.flushCaches(); // dereg any drivers for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();) { Driver driver = (Driver) e.nextElement(); if (driver.getClass().getClassLoader() == getClass().getClassLoader()) { DriverManager.deregisterDriver(driver); } } // shutdown jmx JMXAgent.shutdown(); // shutdown spring // get web application context from the servlet context ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) servletContext .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); if (factory.containsSingleton("default.context")) { for (String scope : factory.getRegisteredScopeNames()) { logger.debug("Registered scope: " + scope); } for (String singleton : factory.getSingletonNames()) { logger.debug("Registered singleton: " + singleton); // factory.destroyScopedBean(singleton); } factory.destroySingletons(); } servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); applicationContext.close(); // http://jakarta.apache.org/commons/logging/guide.html#Classloader_and_Memory_Management // http://wiki.apache.org/jakarta-commons/Logging/UndeployMemoryLeak?action=print // LogFactory.release(Thread.currentThread().getContextClassLoader()); } catch (Throwable e) { // may get a java.lang.StackOverflowError when shutting appcontext // down in jboss e.printStackTrace(); } }
From source file:org.red5.server.war.WarLoaderServlet.java
/** * Clearing the in-memory configuration parameters, we will receive * notification that the servlet context is about to be shut down *//*from w w w. j a v a 2 s . c o m*/ @Override public void contextDestroyed(ServletContextEvent sce) { synchronized (servletContext) { logger.info("Webapp shutdown"); // XXX Paul: grabbed this from // http://opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won%27t+let+go // in hopes that we can clear all the issues with J2EE containers // during shutdown try { ServletContext ctx = sce.getServletContext(); // prepare spring for shutdown Introspector.flushCaches(); // dereg any drivers for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();) { Driver driver = (Driver) e.nextElement(); if (driver.getClass().getClassLoader() == getClass().getClassLoader()) { DriverManager.deregisterDriver(driver); } } // shutdown jmx JMXAgent.shutdown(); // shutdown the persistence thread FilePersistenceThread persistenceThread = FilePersistenceThread.getInstance(); if (persistenceThread != null) { persistenceThread.shutdown(); } // shutdown spring Object attr = ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (attr != null) { // get web application context from the servlet context ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) attr; ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); // for (String scope : factory.getRegisteredScopeNames()) { // logger.debug("Registered scope: " + scope); // } try { for (String singleton : factory.getSingletonNames()) { logger.debug("Registered singleton: " + singleton); factory.destroyScopedBean(singleton); } } catch (RuntimeException e) { } factory.destroySingletons(); ctx.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); applicationContext.close(); } getContextLoader().closeWebApplicationContext(ctx); // org.apache.commons.logging.LogFactory.releaseAll(); // org.apache.log4j.LogManager.getLoggerRepository().shutdown(); // org.apache.log4j.LogManager.shutdown(); } catch (Throwable e) { e.printStackTrace(); } } }