/** * Assert that this context's BeanFactory is currently active, * throwing an {@link IllegalStateException} if it isn't. * <p>Invoked by all {@link BeanFactory} delegation methods that depend * on an active context, i.e. in particular all bean accessor methods. * <p>The default implementation checks the {@link #isActive() 'active'} status * of this context overall. May be overridden for more specific checks, or for a * no-op if {@link #getBeanFactory()} itself throws an exception in such a case. */ protected void assertBeanFactoryActive() { if (!this.active.get()) { if (this.closed.get()) { throw new IllegalStateException(getDisplayName() + " has been closed already"); } else { throw new IllegalStateException(getDisplayName() + " has not been refreshed yet"); } } }
/** * Assert that this context's BeanFactory is currently active, * throwing an {@link IllegalStateException} if it isn't. * <p>Invoked by all {@link BeanFactory} delegation methods that depend * on an active context, i.e. in particular all bean accessor methods. * <p>The default implementation checks the {@link #isActive() 'active'} status * of this context overall. May be overridden for more specific checks, or for a * no-op if {@link #getBeanFactory()} itself throws an exception in such a case. */ protected void assertBeanFactoryActive() { if (!this.active.get()) { if (this.closed.get()) { throw new IllegalStateException(getDisplayName() + " has been closed already"); } else { throw new IllegalStateException(getDisplayName() + " has not been refreshed yet"); } } }
/** * Return information about this context. */ @Override public String toString() { StringBuilder sb = new StringBuilder(getDisplayName()); sb.append(", started on ").append(new Date(getStartupDate())); ApplicationContext parent = getParent(); if (parent != null) { sb.append(", parent: ").append(parent.getDisplayName()); } return sb.toString(); }
/** * Prepare this context for refreshing, setting its startup date and * active flag as well as performing any initialization of property sources. */ protected void prepareRefresh() { this.startupDate = System.currentTimeMillis(); this.closed.set(false); this.active.set(true); if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) { logger.trace("Refreshing " + this); } else { logger.debug("Refreshing " + getDisplayName()); } } // Initialize any placeholder property sources in the context environment initPropertySources(); // Validate that all properties marked as required are resolvable // see ConfigurablePropertyResolver#setRequiredProperties getEnvironment().validateRequiredProperties(); // Allow for the collection of early ApplicationEvents, // to be published once the multicaster is available... this.earlyApplicationEvents = new LinkedHashSet<>(); }
/** * Return information about this context. */ @Override public String toString() { StringBuilder sb = new StringBuilder(getDisplayName()); sb.append(", started on ").append(new Date(getStartupDate())); ApplicationContext parent = getParent(); if (parent != null) { sb.append(", parent: ").append(parent.getDisplayName()); } return sb.toString(); }
/** * Prepare this context for refreshing, setting its startup date and * active flag as well as performing any initialization of property sources. */ protected void prepareRefresh() { this.startupDate = System.currentTimeMillis(); this.closed.set(false); this.active.set(true); if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) { logger.trace("Refreshing " + this); } else { logger.debug("Refreshing " + getDisplayName()); } } // Initialize any placeholder property sources in the context environment initPropertySources(); // Validate that all properties marked as required are resolvable // see ConfigurablePropertyResolver#setRequiredProperties getEnvironment().validateRequiredProperties(); // Allow for the collection of early ApplicationEvents, // to be published once the multicaster is available... this.earlyApplicationEvents = new LinkedHashSet<>(); }
/** * Assert that this context's BeanFactory is currently active, * throwing an {@link IllegalStateException} if it isn't. * <p>Invoked by all {@link BeanFactory} delegation methods that depend * on an active context, i.e. in particular all bean accessor methods. * <p>The default implementation checks the {@link #isActive() 'active'} status * of this context overall. May be overridden for more specific checks, or for a * no-op if {@link #getBeanFactory()} itself throws an exception in such a case. */ protected void assertBeanFactoryActive() { if (!this.active.get()) { if (this.closed.get()) { throw new IllegalStateException(getDisplayName() + " has been closed already"); } else { throw new IllegalStateException(getDisplayName() + " has not been refreshed yet"); } } }
public void onApplicationEvent(ApplicationEvent event) { // only respond to ContextRefreshedEvents that are sourced from the parent context if (event.getSource() != parent) return; if (event instanceof ContextRefreshedEvent) { if (logger.isDebugEnabled()) logger.debug(format("Caught ContextRefreshedEvent from parent application context [%s], now refreshing [%s]", parent.getDisplayName(), child.getDisplayName())); copyBeanFactoryPostProcessors(); child.setParent(parent); child.refresh(); return; } if (event instanceof ContextClosedEvent) { if (logger.isDebugEnabled()) logger.debug(format("Caught ContextClosedEvent from parent application context [%s], now closing [%s]", parent.getDisplayName(), child.getDisplayName())); child.close(); return; } }
/** * Callback from the container to gracefully stop flows and modules, and stop the inner loaded contexts */ public void destroy() throws Exception { // shutdown all modules cleanly List<String> modulesToRemove = new ArrayList<>(); for (Module<Flow> module : this.moduleContainer.getModules()) { this.moduleActivator.deactivate(module); modulesToRemove.add(module.getName()); } // remove all modules from container for (String moduleToRemove : modulesToRemove) { moduleContainer.remove(moduleToRemove); } // TODO - find a more generic way of managing this for platform resources shutdownSchedulers(platformContext); shutdownMonitors(platformContext); // close our inner loaded contexts for (AbstractApplicationContext context : innerContexts) { logger.debug("closing and destroying inner context: " + context.getDisplayName()); shutdownSchedulers(context); shutdownMonitors(context); context.close(); } innerContexts.clear(); }