Java Code Examples for org.springframework.context.Lifecycle#stop()

The following examples show how to use org.springframework.context.Lifecycle#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SockJsClient.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void stop() {
	if (isRunning()) {
		this.running = false;
		for (Transport transport : this.transports) {
			if (transport instanceof Lifecycle) {
				Lifecycle lifecycle = (Lifecycle) transport;
				if (lifecycle.isRunning()) {
					lifecycle.stop();
				}
			}
		}
	}
}
 
Example 2
Source File: SockJsClient.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void stop() {
	if (isRunning()) {
		this.running = false;
		for (Transport transport : this.transports) {
			if (transport instanceof Lifecycle) {
				Lifecycle lifecycle = (Lifecycle) transport;
				if (lifecycle.isRunning()) {
					lifecycle.stop();
				}
			}
		}
	}
}
 
Example 3
Source File: DefaultLifecycleProcessor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Stop the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that depends on it are stopped first.
 * @param lifecycleBeans a Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to stop
 */
private void doStop(Map<String, ? extends Lifecycle> lifecycleBeans, final String beanName,
		final CountDownLatch latch, final Set<String> countDownBeanNames) {

	Lifecycle bean = lifecycleBeans.remove(beanName);
	if (bean != null) {
		String[] dependentBeans = getBeanFactory().getDependentBeans(beanName);
		for (String dependentBean : dependentBeans) {
			doStop(lifecycleBeans, dependentBean, latch, countDownBeanNames);
		}
		try {
			if (bean.isRunning()) {
				if (bean instanceof SmartLifecycle) {
					if (logger.isTraceEnabled()) {
						logger.trace("Asking bean '" + beanName + "' of type [" +
								bean.getClass().getName() + "] to stop");
					}
					countDownBeanNames.add(beanName);
					((SmartLifecycle) bean).stop(() -> {
						latch.countDown();
						countDownBeanNames.remove(beanName);
						if (logger.isDebugEnabled()) {
							logger.debug("Bean '" + beanName + "' completed its stop procedure");
						}
					});
				}
				else {
					if (logger.isTraceEnabled()) {
						logger.trace("Stopping bean '" + beanName + "' of type [" +
								bean.getClass().getName() + "]");
					}
					bean.stop();
					if (logger.isDebugEnabled()) {
						logger.debug("Successfully stopped bean '" + beanName + "'");
					}
				}
			}
			else if (bean instanceof SmartLifecycle) {
				// Don't wait for beans that aren't running...
				latch.countDown();
			}
		}
		catch (Throwable ex) {
			if (logger.isWarnEnabled()) {
				logger.warn("Failed to stop bean '" + beanName + "'", ex);
			}
		}
	}
}
 
Example 4
Source File: DefaultLifecycleProcessor.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Stop the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that depends on it are stopped first.
 * @param lifecycleBeans a Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to stop
 */
private void doStop(Map<String, ? extends Lifecycle> lifecycleBeans, final String beanName,
		final CountDownLatch latch, final Set<String> countDownBeanNames) {

	Lifecycle bean = lifecycleBeans.remove(beanName);
	if (bean != null) {
		String[] dependentBeans = getBeanFactory().getDependentBeans(beanName);
		for (String dependentBean : dependentBeans) {
			doStop(lifecycleBeans, dependentBean, latch, countDownBeanNames);
		}
		try {
			if (bean.isRunning()) {
				if (bean instanceof SmartLifecycle) {
					if (logger.isTraceEnabled()) {
						logger.trace("Asking bean '" + beanName + "' of type [" +
								bean.getClass().getName() + "] to stop");
					}
					countDownBeanNames.add(beanName);
					((SmartLifecycle) bean).stop(() -> {
						latch.countDown();
						countDownBeanNames.remove(beanName);
						if (logger.isDebugEnabled()) {
							logger.debug("Bean '" + beanName + "' completed its stop procedure");
						}
					});
				}
				else {
					if (logger.isTraceEnabled()) {
						logger.trace("Stopping bean '" + beanName + "' of type [" +
								bean.getClass().getName() + "]");
					}
					bean.stop();
					if (logger.isDebugEnabled()) {
						logger.debug("Successfully stopped bean '" + beanName + "'");
					}
				}
			}
			else if (bean instanceof SmartLifecycle) {
				// Don't wait for beans that aren't running...
				latch.countDown();
			}
		}
		catch (Throwable ex) {
			if (logger.isWarnEnabled()) {
				logger.warn("Failed to stop bean '" + beanName + "'", ex);
			}
		}
	}
}
 
Example 5
Source File: DefaultLifecycleProcessor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Stop the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that depends on it are stopped first.
 * @param lifecycleBeans Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to stop
 */
private void doStop(Map<String, ? extends Lifecycle> lifecycleBeans, final String beanName,
		final CountDownLatch latch, final Set<String> countDownBeanNames) {

	Lifecycle bean = lifecycleBeans.remove(beanName);
	if (bean != null) {
		String[] dependentBeans = this.beanFactory.getDependentBeans(beanName);
		for (String dependentBean : dependentBeans) {
			doStop(lifecycleBeans, dependentBean, latch, countDownBeanNames);
		}
		try {
			if (bean.isRunning()) {
				if (bean instanceof SmartLifecycle) {
					if (logger.isDebugEnabled()) {
						logger.debug("Asking bean '" + beanName + "' of type [" + bean.getClass() + "] to stop");
					}
					countDownBeanNames.add(beanName);
					((SmartLifecycle) bean).stop(new Runnable() {
						@Override
						public void run() {
							latch.countDown();
							countDownBeanNames.remove(beanName);
							if (logger.isDebugEnabled()) {
								logger.debug("Bean '" + beanName + "' completed its stop procedure");
							}
						}
					});
				}
				else {
					if (logger.isDebugEnabled()) {
						logger.debug("Stopping bean '" + beanName + "' of type [" + bean.getClass() + "]");
					}
					bean.stop();
					if (logger.isDebugEnabled()) {
						logger.debug("Successfully stopped bean '" + beanName + "'");
					}
				}
			}
			else if (bean instanceof SmartLifecycle) {
				// don't wait for beans that aren't running
				latch.countDown();
			}
		}
		catch (Throwable ex) {
			if (logger.isWarnEnabled()) {
				logger.warn("Failed to stop bean '" + beanName + "'", ex);
			}
		}
	}
}
 
Example 6
Source File: DefaultLifecycleProcessor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Stop the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that depends on it are stopped first.
 * @param lifecycleBeans Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to stop
 */
private void doStop(Map<String, ? extends Lifecycle> lifecycleBeans, final String beanName,
		final CountDownLatch latch, final Set<String> countDownBeanNames) {

	Lifecycle bean = lifecycleBeans.remove(beanName);
	if (bean != null) {
		String[] dependentBeans = this.beanFactory.getDependentBeans(beanName);
		for (String dependentBean : dependentBeans) {
			doStop(lifecycleBeans, dependentBean, latch, countDownBeanNames);
		}
		try {
			if (bean.isRunning()) {
				if (bean instanceof SmartLifecycle) {
					if (logger.isDebugEnabled()) {
						logger.debug("Asking bean '" + beanName + "' of type [" + bean.getClass() + "] to stop");
					}
					countDownBeanNames.add(beanName);
					((SmartLifecycle) bean).stop(new Runnable() {
						@Override
						public void run() {
							latch.countDown();
							countDownBeanNames.remove(beanName);
							if (logger.isDebugEnabled()) {
								logger.debug("Bean '" + beanName + "' completed its stop procedure");
							}
						}
					});
				}
				else {
					if (logger.isDebugEnabled()) {
						logger.debug("Stopping bean '" + beanName + "' of type [" + bean.getClass() + "]");
					}
					bean.stop();
					if (logger.isDebugEnabled()) {
						logger.debug("Successfully stopped bean '" + beanName + "'");
					}
				}
			}
			else if (bean instanceof SmartLifecycle) {
				// don't wait for beans that aren't running
				latch.countDown();
			}
		}
		catch (Throwable ex) {
			if (logger.isWarnEnabled()) {
				logger.warn("Failed to stop bean '" + beanName + "'", ex);
			}
		}
	}
}