List of usage examples for org.springframework.context.support AbstractApplicationContext isActive
@Override public boolean isActive()
From source file:com.brienwheeler.apps.main.ContextMain.java
private List<AbstractApplicationContext> findOrLaunchContext(String contextSpecList) { // check to see if we've already figured this out List<AbstractApplicationContext> resultingContexts = contextAliasMap.get(contextSpecList); if (resultingContexts != null) return resultingContexts; // circular dependency detection if (contextsResolving.contains(contextSpecList)) throw new ResourceMapError("circular dependency: " + contextSpecList); String originalContextSpecList = contextSpecList; contextsResolving.add(originalContextSpecList); try {/*from w ww . j av a 2 s . c om*/ // create container for eventual results resultingContexts = new ArrayList<AbstractApplicationContext>(); // first check to see if it has a properties prefix and process/strip it from spec string // do this before looking for comma separated list below so that a comma-separated list // within the properties prefix gets handled correctly if (contextSpecList.startsWith(PROPSPEC_PREFIX)) { int specEnd = contextSpecList.indexOf(PROPSPEC_SUFFIX); if (specEnd == -1) throw new ResourceMapError("unterminated property spec in " + contextSpecList); String propertySpecList = contextSpecList.substring(PROPSPEC_PREFIX.length(), specEnd); contextSpecList = contextSpecList.substring(specEnd + PROPSPEC_SUFFIX.length()).trim(); loadPropertySpec(propertySpecList); } // if the list has more than one spec string, split then recurse for first spec and remaining spec list int comma = contextSpecList.indexOf(","); if (comma != -1) { String currentSpec = contextSpecList.substring(0, comma).trim(); resultingContexts.addAll(findOrLaunchContext(currentSpec)); String remainingSpecList = contextSpecList.substring(comma + 1).trim(); resultingContexts.addAll(findOrLaunchContext(remainingSpecList)); contextAliasMap.put(contextSpecList, resultingContexts); return resultingContexts; } // be robust against a properties spec with no context -- user might do something like this: // properties[props1],context1,properties[props2],context2 // in any case, an empty contextSpecList implies no further action if (contextSpecList.isEmpty()) { return resultingContexts; } // ok, contextSpecList has just one spec string in it. Possibly alias or location. // check context map and recurse if present if (contextMap != null) { String resolvedSpecList = contextMap.getProperty(contextSpecList); if (resolvedSpecList != null) { resultingContexts.addAll(findOrLaunchContext(resolvedSpecList)); contextAliasMap.put(contextSpecList, resultingContexts); return resultingContexts; } } // not an alias, must be a location at this point AbstractApplicationContext context = new SmartClassPathXmlApplicationContext(contextSpecList); synchronized (contextLaunchOrder) { // this allows a context to close itself during its startup (schematool does this) if (context.isActive()) contextLaunchOrder.add(context); context.addApplicationListener(this); } resultingContexts.add(context); contextAliasMap.put(contextSpecList, resultingContexts); return resultingContexts; } finally { contextsResolving.remove(originalContextSpecList); } }
From source file:com.brienwheeler.apps.main.ContextMain.java
@Override public void onApplicationEvent(ContextClosedEvent event) { final AbstractApplicationContext context = (AbstractApplicationContext) event.getApplicationContext(); boolean waitAndSignal = false; synchronized (contextLaunchOrder) { contextLaunchOrder.remove(context); // if that was the last context and it self-terminated if (contextLaunchOrder.size() == 0 && !shuttingDown) waitAndSignal = true;/*from ww w. ja v a2 s . com*/ } if (waitAndSignal) { // since the ContextClosedEvent actually comes at the start of the close process, // start a background thread to monitor the state of the context and signal // the thread waiting in onRun() when it is finished closing. new Thread() { @Override public void run() { while (context.isActive()) { try { Thread.sleep(100L); } catch (InterruptedException e) { log.error("interrupted while waiting for last context to finish shutdown"); Thread.currentThread().interrupt(); } } synchronized (contextLaunchOrder) { contextLaunchOrder.notifyAll(); } } }.start(); } }
From source file:org.red5.server.winstone.WinstoneLoader.java
/** * Shut server down./*from w w w.j a va 2s . c o m*/ */ public void shutdown() { log.info("Shutting down Winstone context"); //run through the applications and ensure that spring is told //to commence shutdown / disposal AbstractApplicationContext absCtx = (AbstractApplicationContext) LoaderBase.getApplicationContext(); if (absCtx != null) { log.debug("Using loader base application context for shutdown"); //get all the app (web) contexts and shut them down first Map<String, IApplicationContext> contexts = LoaderBase.getRed5ApplicationContexts(); if (contexts.isEmpty()) { log.info("No contexts were found to shutdown"); } for (Map.Entry<String, IApplicationContext> entry : contexts.entrySet()) { //stop the context log.debug("Calling stop on context: {}", entry.getKey()); entry.getValue().stop(); } if (absCtx.isActive()) { log.debug("Closing application context"); absCtx.close(); } } else { log.error("Error getting Spring bean factory for shutdown"); } try { //stop Winstone embedded.shutdown(); //kill the jvm System.exit(0); } catch (Exception e) { log.warn("Winstone could not be stopped", e); throw new RuntimeException("Winstone could not be stopped"); } }
From source file:org.red5.server.undertow.UndertowLoader.java
/** * Shut server down.//from w ww .j a v a 2 s . c om */ @Override public void destroy() throws Exception { log.info("Shutting down Undertow context"); // run through the applications and ensure that spring is told to commence shutdown / disposal AbstractApplicationContext absCtx = (AbstractApplicationContext) LoaderBase.getApplicationContext(); if (absCtx != null) { log.debug("Using loader base application context for shutdown"); // get all the app (web) contexts and shut them down first Map<String, IApplicationContext> contexts = LoaderBase.getRed5ApplicationContexts(); if (contexts.isEmpty()) { log.info("No contexts were found to shutdown"); } for (Map.Entry<String, IApplicationContext> entry : contexts.entrySet()) { // stop the context log.debug("Calling stop on context: {}", entry.getKey()); entry.getValue().stop(); } if (absCtx.isActive()) { log.debug("Closing application context"); absCtx.close(); } } else { log.error("Error getting Spring bean factory for shutdown"); } try { // stop undertow server.stop(); } catch (Exception e) { log.warn("Undertow could not be stopped", e); throw new RuntimeException("Undertow could not be stopped"); } }
From source file:org.red5.server.tomcat.TomcatLoader.java
/** * Shut server down./* w w w .j av a 2s . com*/ */ public void shutdown() { log.info("Shutting down Tomcat context"); //run through the applications and ensure that spring is told //to commence shutdown / disposal AbstractApplicationContext absCtx = (AbstractApplicationContext) LoaderBase.getApplicationContext(); if (absCtx != null) { log.debug("Using loader base application context for shutdown"); //get all the app (web) contexts and shut them down first Map<String, IApplicationContext> contexts = LoaderBase.getRed5ApplicationContexts(); if (contexts.isEmpty()) { log.info("No contexts were found to shutdown"); } for (Map.Entry<String, IApplicationContext> entry : contexts.entrySet()) { //stop the context log.debug("Calling stop on context: {}", entry.getKey()); entry.getValue().stop(); } if (absCtx.isActive()) { log.debug("Closing application context"); absCtx.close(); } } else { log.error("Error getting Spring bean factory for shutdown"); } //shutdown jmx JMXAgent.shutdown(); try { //stop tomcat embedded.stop(); //kill the jvm System.exit(0); } catch (Exception e) { log.warn("Tomcat could not be stopped", e); throw new RuntimeException("Tomcat could not be stopped"); } }
From source file:org.jahia.services.SpringContextSingleton.java
private void multicastEvent(ApplicationEvent event, AbstractApplicationContext ctx) { if (!ctx.isActive()) { return;/*ww w . ja v a 2 s . com*/ } if (ctx.containsBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) { ((ApplicationEventMulticaster) ctx .getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) .multicastEvent(event); } else { // fall back to publishEvent() ctx.publishEvent(event); } }
From source file:org.jumpmind.symmetric.ClientSymmetricEngine.java
@Override public synchronized boolean start() { if (this.springContext instanceof AbstractApplicationContext) { AbstractApplicationContext ctx = (AbstractApplicationContext) this.springContext; try {/* w w w . j a v a 2 s.c om*/ if (!ctx.isActive()) { ctx.start(); } } catch (Exception ex) { } } return super.start(); }
From source file:org.jumpmind.symmetric.ClientSymmetricEngine.java
@Override public synchronized void stop() { if (this.springContext instanceof AbstractApplicationContext) { AbstractApplicationContext ctx = (AbstractApplicationContext) this.springContext; try {/*from w w w . java 2 s . co m*/ if (ctx.isActive()) { ctx.stop(); } } catch (Exception ex) { } } super.stop(); }
From source file:org.opennms.poller.remote.Main.java
private static void shutdownContextAndExit(AbstractApplicationContext context) { int returnCode = 0; // MVR: gracefully shutdown scheduler, otherwise context.close() will raise // an exception. See #NMS-6966 for more details. if (context.isActive()) { // If there is a scheduler in the context, then shut it down Scheduler scheduler = (Scheduler) context.getBean("scheduler"); if (scheduler != null) { try { LOG.info("Shutting down PollerFrontEnd scheduler"); scheduler.shutdown();/*w w w .ja v a 2 s . c o m*/ LOG.info("PollerFrontEnd scheduler shutdown complete"); } catch (SchedulerException ex) { LOG.warn("Shutting down PollerFrontEnd scheduler failed", ex); returnCode = 10; } } // Now close the application context. This will invoke // {@link DefaultPollerFrontEnd#destroy()} which will mark the // remote poller as "Stopped" during shutdown instead of letting // it remain in the "Disconnected" state. context.close(); } final int returnCodeValue = returnCode; new Thread() { public void run() { // Sleep for a couple of seconds so that the other // PropertyChangeListeners get a chance to fire try { Thread.sleep(5000); } catch (InterruptedException e) { } // Exit System.exit(returnCodeValue); } }.start(); }