@Override public boolean isRunning() { if (this.webSocketClient instanceof Lifecycle) { return ((Lifecycle) this.webSocketClient).isRunning(); } else { return this.running; } }
@Override public void stopInternal() throws Exception { if (this.client instanceof Lifecycle && ((Lifecycle) this.client).isRunning()) { ((Lifecycle) this.client).stop(); } super.stopInternal(); }
@Override public void startInternal() { if (this.client instanceof Lifecycle && !((Lifecycle) this.client).isRunning()) { ((Lifecycle) this.client).start(); } super.startInternal(); }
@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(); } } } } }
@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(); } } } } }
if (bean.isRunning()) { if (bean instanceof SmartLifecycle) { if (logger.isTraceEnabled()) {
if (((Lifecycle) context).isRunning()) { level = Status.Level.OK; } else {
if (((Lifecycle) context).isRunning()) { level = Status.Level.OK; } else {
/** * 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 + "'"); } } } }
if (bean.isRunning()) { if (bean instanceof SmartLifecycle) { if (logger.isTraceEnabled()) {
/** * 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 + "'"); } } } }
@Test public void singleLifecycleShutdown() throws Exception { CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>(); Lifecycle bean = new TestLifecycleBean(null, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); context.refresh(); assertFalse(bean.isRunning()); bean.start(); assertTrue(bean.isRunning()); context.stop(); assertEquals(1, stoppedBeans.size()); assertFalse(bean.isRunning()); assertEquals(bean, stoppedBeans.get(0)); }
context.getBeanFactory().registerSingleton("bean7", bean7); context.refresh(); assertTrue(bean2.isRunning()); assertTrue(bean3.isRunning()); assertTrue(bean5.isRunning()); assertTrue(bean6.isRunning()); assertTrue(bean7.isRunning()); assertFalse(bean1.isRunning()); assertFalse(bean4.isRunning()); bean1.start(); bean4.start(); assertTrue(bean1.isRunning()); assertTrue(bean4.isRunning()); context.stop(); assertFalse(bean1.isRunning()); assertFalse(bean2.isRunning()); assertFalse(bean3.isRunning()); assertFalse(bean4.isRunning()); assertFalse(bean5.isRunning()); assertFalse(bean6.isRunning()); assertFalse(bean7.isRunning()); assertEquals(7, stoppedBeans.size()); assertEquals(Integer.MAX_VALUE, getPhase(stoppedBeans.get(0)));
IntegrationWebSocketConnectionManager(WebSocketClient client, String uriTemplate, Object... uriVariables) { super(uriTemplate, uriVariables); this.client = client; this.syncClientLifecycle = ((client instanceof Lifecycle) && !((Lifecycle) client).isRunning()); }
@Override public boolean isRunning() { return !(this.messageProcessor instanceof Lifecycle) || ((Lifecycle) this.messageProcessor).isRunning(); }
@Override public boolean isRunning() { return this.handshakeHandler instanceof Lifecycle && ((Lifecycle) this.handshakeHandler).isRunning(); }
@Override public boolean isRunning() { return !(this.object instanceof Lifecycle) || ((Lifecycle) this.object).isRunning(); }
@Override @ManagedAttribute public boolean isRunning() { return this.lifecycle.isRunning(); }
@Override @ManagedAttribute public boolean isRunning() { return this.lifecycle.isRunning(); }
@Override public boolean isRunning() { T instance = get(); return !(instance instanceof Lifecycle) || ((Lifecycle) instance).isRunning(); }