public void initialize() { if (!initialized) { LOGGER.debug("Initializing triggering policy {}", triggeringPolicy); initialized = true; triggeringPolicy.initialize(this); if (triggeringPolicy instanceof LifeCycle) { ((LifeCycle) triggeringPolicy).start(); } } }
private void initializeShutdownCallbackRegistry() { if (SHUTDOWN_HOOK_ENABLED && this.shutdownCallbackRegistry instanceof LifeCycle) { try { ((LifeCycle) this.shutdownCallbackRegistry).start(); } catch (final IllegalStateException e) { LOGGER.error("Cannot start ShutdownCallbackRegistry, already shutting down."); throw e; } catch (final RuntimeException e) { LOGGER.error("There was an error starting the ShutdownCallbackRegistry.", e); } } }
public void setTriggeringPolicy(final TriggeringPolicy triggeringPolicy) { triggeringPolicy.initialize(this); final TriggeringPolicy policy = this.triggeringPolicy; int count = 0; boolean policyUpdated = false; do { ++count; } while (!(policyUpdated = triggeringPolicyUpdater.compareAndSet(this, this.triggeringPolicy, triggeringPolicy)) && count < MAX_TRIES); if (policyUpdated) { if (triggeringPolicy instanceof LifeCycle) { ((LifeCycle) triggeringPolicy).start(); } if (policy instanceof LifeCycle) { ((LifeCycle) policy).stop(); } } else { if (triggeringPolicy instanceof LifeCycle) { ((LifeCycle) triggeringPolicy).stop(); } } }
@Test public void lifecycleStart() { // given LifeCycle lifeCycle = createLifeCycleTestObject(); assertFalse(lifeCycle.isStarted()); // when lifeCycle.start(); // then assertFalse(lifeCycle.isStopped()); assertTrue(lifeCycle.isStarted()); }
@Test public void lifecycleStop() { // given LifeCycle lifeCycle = createLifeCycleTestObject(); assertFalse(lifeCycle.isStarted()); lifeCycle.start(); assertTrue(lifeCycle.isStarted()); // when lifeCycle.stop(); // then assertFalse(lifeCycle.isStarted()); assertTrue(lifeCycle.isStopped()); }