org.springframework.context.Lifecycle#isRunning ( )源码实例Demo

下面列出了org.springframework.context.Lifecycle#isRunning ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Start the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that it depends on are started first.
 * @param lifecycleBeans a Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to start
 */
private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) {
	Lifecycle bean = lifecycleBeans.remove(beanName);
	if (bean != null && bean != this) {
		String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName);
		for (String dependency : dependenciesForBean) {
			doStart(lifecycleBeans, dependency, autoStartupOnly);
		}
		if (!bean.isRunning() &&
				(!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) {
			if (logger.isTraceEnabled()) {
				logger.trace("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]");
			}
			try {
				bean.start();
			}
			catch (Throwable ex) {
				throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex);
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Successfully started bean '" + beanName + "'");
			}
		}
	}
}
 
/**
 * Start the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that it depends on are started first.
 * @param lifecycleBeans a Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to start
 */
private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) {
	Lifecycle bean = lifecycleBeans.remove(beanName);
	if (bean != null && bean != this) {
		String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName);
		for (String dependency : dependenciesForBean) {
			doStart(lifecycleBeans, dependency, autoStartupOnly);
		}
		if (!bean.isRunning() &&
				(!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) {
			if (logger.isTraceEnabled()) {
				logger.trace("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]");
			}
			try {
				bean.start();
			}
			catch (Throwable ex) {
				throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex);
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Successfully started bean '" + beanName + "'");
			}
		}
	}
}
 
源代码3 项目: lams   文件: DefaultLifecycleProcessor.java
/**
 * Start the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that it depends on are started first.
 * @param lifecycleBeans Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to start
 */
private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) {
	Lifecycle bean = lifecycleBeans.remove(beanName);
	if (bean != null && !this.equals(bean)) {
		String[] dependenciesForBean = this.beanFactory.getDependenciesForBean(beanName);
		for (String dependency : dependenciesForBean) {
			doStart(lifecycleBeans, dependency, autoStartupOnly);
		}
		if (!bean.isRunning() &&
				(!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) {
			if (logger.isDebugEnabled()) {
				logger.debug("Starting bean '" + beanName + "' of type [" + bean.getClass() + "]");
			}
			try {
				bean.start();
			}
			catch (Throwable ex) {
				throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex);
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Successfully started bean '" + beanName + "'");
			}
		}
	}
}
 
/**
 * Start the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that it depends on are started first.
 * @param lifecycleBeans Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to start
 */
private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) {
	Lifecycle bean = lifecycleBeans.remove(beanName);
	if (bean != null && !this.equals(bean)) {
		String[] dependenciesForBean = this.beanFactory.getDependenciesForBean(beanName);
		for (String dependency : dependenciesForBean) {
			doStart(lifecycleBeans, dependency, autoStartupOnly);
		}
		if (!bean.isRunning() &&
				(!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) {
			if (logger.isDebugEnabled()) {
				logger.debug("Starting bean '" + beanName + "' of type [" + bean.getClass() + "]");
			}
			try {
				bean.start();
			}
			catch (Throwable ex) {
				throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex);
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Successfully started bean '" + beanName + "'");
			}
		}
	}
}
 
源代码5 项目: spring-analysis-note   文件: SockJsClient.java
@Override
public void start() {
	if (!isRunning()) {
		this.running = true;
		for (Transport transport : this.transports) {
			if (transport instanceof Lifecycle) {
				Lifecycle lifecycle = (Lifecycle) transport;
				if (!lifecycle.isRunning()) {
					lifecycle.start();
				}
			}
		}
	}
}
 
源代码6 项目: spring-analysis-note   文件: SockJsClient.java
@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();
				}
			}
		}
	}
}
 
源代码7 项目: java-technology-stack   文件: SockJsClient.java
@Override
public void start() {
	if (!isRunning()) {
		this.running = true;
		for (Transport transport : this.transports) {
			if (transport instanceof Lifecycle) {
				Lifecycle lifecycle = (Lifecycle) transport;
				if (!lifecycle.isRunning()) {
					lifecycle.start();
				}
			}
		}
	}
}
 
源代码8 项目: java-technology-stack   文件: SockJsClient.java
@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();
				}
			}
		}
	}
}
 
/**
 * 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);
			}
		}
	}
}
 
/**
 * 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);
			}
		}
	}
}
 
源代码11 项目: lams   文件: DefaultLifecycleProcessor.java
/**
 * 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);
			}
		}
	}
}
 
/**
 * 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);
			}
		}
	}
}