use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.
the class CreatedComponentRedistryTest method test.
@Test
public void test() throws Exception {
CreatedComponentRedistry registry = new CreatedComponentRedistry();
String name = registry.add(new Object());
logger.info("{}", name);
Lifecycle lifecycle = new NoOpLifecycleObject();
registry.add(lifecycle);
registry.initialize();
registry.start();
Assert.assertTrue(lifecycle.getLifecycleState().isStarted());
Lifecycle lifecycle2 = new NoOpLifecycleObject();
registry.add(lifecycle2);
Assert.assertTrue(lifecycle2.getLifecycleState().isStarted());
registry.remove(lifecycle2);
Assert.assertTrue(lifecycle2.getLifecycleState().isDisposed());
Assert.assertEquals(2, registry.allComponents().size());
}
use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.
the class AbstractComponentRegistry method disposeAllComponents.
private void disposeAllComponents() {
List<Lifecycle> components = lifecycleCallable();
Collections.reverse(components);
for (Lifecycle lifecycle : components) {
if (lifecycle.getLifecycleState().canDispose()) {
try {
lifecycle.dispose();
} catch (Throwable th) {
logger.error("[doDispose]" + lifecycle, th);
}
}
}
}
use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.
the class AbstractComponentRegistry method stopAllComponents.
private void stopAllComponents() {
List<Lifecycle> components = lifecycleCallable();
Collections.reverse(components);
for (Lifecycle lifecycle : components) {
if (lifecycle.getLifecycleState().canStop()) {
try {
lifecycle.stop();
} catch (Throwable th) {
logger.error("[doStop]" + lifecycle, th);
}
}
}
}
use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.
the class CreatedComponentRedistry method doRemove.
@Override
public boolean doRemove(Object component) throws Exception {
String name = null;
for (Entry<String, Object> entry : components.entrySet()) {
if (entry.getValue() == component) {
name = entry.getKey();
break;
}
}
if (name == null) {
logger.info("[doRemove][can not find component]{}", component);
return false;
}
logger.info("[doRemove]{}, {}", name, component);
components.remove(name);
if (component instanceof Lifecycle) {
Lifecycle lifecycle = (Lifecycle) component;
if (lifecycle.getLifecycleState() != null) {
if (lifecycle.getLifecycleState().canStop()) {
lifecycle.stop();
}
if (lifecycle.getLifecycleState().canDispose()) {
lifecycle.dispose();
}
}
}
return true;
}
use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.
the class DefaultLifecycleControllerTest method testCanInitialize.
@Test
public void testCanInitialize() throws Exception {
Lifecycle lifecycle = new NoOpLifecycleObject();
lifecycle.initialize();
try {
lifecycle.initialize();
Assert.fail();
} catch (Exception e) {
}
lifecycle.start();
try {
lifecycle.initialize();
Assert.fail();
} catch (Exception e) {
}
lifecycle.stop();
try {
lifecycle.initialize();
Assert.fail();
} catch (Exception e) {
}
lifecycle.dispose();
lifecycle.initialize();
}
Aggregations