use of com.alipay.sofa.ark.spi.service.event.EventAdminService in project sofa-ark by alipay.
the class BizModel method start.
@Override
public void start(String[] args) throws Throwable {
AssertUtils.isTrue(bizState == BizState.RESOLVED, "BizState must be RESOLVED");
if (mainClass == null) {
throw new ArkRuntimeException(String.format("biz: %s has no main method", getBizName()));
}
ClassLoader oldClassLoader = ClassLoaderUtils.pushContextClassLoader(this.classLoader);
EventAdminService eventAdminService = ArkServiceContainerHolder.getContainer().getService(EventAdminService.class);
try {
eventAdminService.sendEvent(new BeforeBizStartupEvent(this));
resetProperties();
if (!isMasterBizAndEmbedEnable()) {
long start = System.currentTimeMillis();
MainMethodRunner mainMethodRunner = new MainMethodRunner(mainClass, args);
mainMethodRunner.run();
// this can trigger health checker handler
eventAdminService.sendEvent(new AfterBizStartupEvent(this));
LOGGER.info("Ark biz {} started in {} ms", getIdentity(), (System.currentTimeMillis() - start));
}
} catch (Throwable e) {
bizState = BizState.BROKEN;
throw e;
} finally {
ClassLoaderUtils.popContextClassLoader(oldClassLoader);
}
BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
if (Boolean.getBoolean(Constants.ACTIVATE_NEW_MODULE)) {
Biz currentActiveBiz = bizManagerService.getActiveBiz(bizName);
if (currentActiveBiz == null) {
bizState = BizState.ACTIVATED;
} else {
((BizModel) currentActiveBiz).setBizState(BizState.DEACTIVATED);
bizState = BizState.ACTIVATED;
}
} else {
if (bizManagerService.getActiveBiz(bizName) == null) {
bizState = BizState.ACTIVATED;
} else {
bizState = BizState.DEACTIVATED;
}
}
}
use of com.alipay.sofa.ark.spi.service.event.EventAdminService in project sofa-ark by alipay.
the class PluginModel method stop.
@Override
public void stop() throws ArkRuntimeException {
EventAdminService eventAdminService = ArkServiceContainerHolder.getContainer().getService(EventAdminService.class);
eventAdminService.sendEvent(new BeforePluginStopEvent(this));
try {
if (pluginActivator != null) {
pluginActivator.stop(pluginContext);
}
} catch (Throwable ex) {
throw new ArkRuntimeException(ex.getMessage(), ex);
} finally {
eventAdminService.sendEvent(new AfterPluginStopEvent(this));
}
}
use of com.alipay.sofa.ark.spi.service.event.EventAdminService in project sofa-ark by alipay.
the class PluginModel method start.
@Override
public void start() throws ArkRuntimeException {
if (activator == null || activator.isEmpty()) {
return;
}
EventAdminService eventAdminService = ArkServiceContainerHolder.getContainer().getService(EventAdminService.class);
ClassLoader oldClassLoader = ClassLoaderUtils.pushContextClassLoader(this.pluginClassLoader);
try {
eventAdminService.sendEvent(new BeforePluginStartupEvent(this));
pluginActivator = (PluginActivator) pluginClassLoader.loadClass(activator).newInstance();
pluginActivator.start(pluginContext);
} catch (Throwable ex) {
throw new ArkRuntimeException(ex.getMessage(), ex);
} finally {
eventAdminService.sendEvent(new AfterPluginStartupEvent(this));
ClassLoaderUtils.popContextClassLoader(oldClassLoader);
}
}
use of com.alipay.sofa.ark.spi.service.event.EventAdminService in project sofa-ark by alipay.
the class ZookeeperConfigActivator method registerEventHandler.
protected void registerEventHandler(final PluginContext context) {
final String bizInitConfig = new String(bizNodeCache.getCurrentData().getData());
EventAdminService eventAdminService = context.referenceService(EventAdminService.class).getService();
eventAdminService.register(new EventHandler<AfterFinishDeployEvent>() {
@Override
public void handleEvent(AfterFinishDeployEvent event) {
LOGGER.info("Start to process init app config: {}", bizInitConfig);
OperationProcessor.process(OperationTransformer.transformToBizOperation(bizInitConfig, context));
}
@Override
public int getPriority() {
return 0;
}
});
eventAdminService.register(new EventHandler<AfterFinishStartupEvent>() {
@Override
public void handleEvent(AfterFinishStartupEvent event) {
ConfigProcessor.createConfigProcessor(context, ipConfigDeque, "ip-zookeeper-config").start();
ConfigProcessor.createConfigProcessor(context, bizConfigDeque, "app-zookeeper-config").start();
}
@Override
public int getPriority() {
return 0;
}
});
}
use of com.alipay.sofa.ark.spi.service.event.EventAdminService in project sofa-ark by alipay.
the class EventAdminServiceTest method test.
@Test
public void test() throws Throwable {
try {
Field field = EventAdminServiceImpl.class.getDeclaredField("SUBSCRIBER_MAP");
field.setAccessible(true);
map = (Map) field.get(null);
} catch (Throwable throwable) {
Assert.assertNull(throwable);
}
EventAdminService eventAdminService = ArkServiceContainerHolder.getContainer().getService(EventAdminService.class);
eventAdminService.register(new LowPriorityMockEventHandler());
eventAdminService.register(new HighPriorityMockEventHandler());
eventAdminService.register(new BeforeBizStopEventHandler());
ClassLoader bizClassLoader = getClass().getClassLoader();
Biz biz = new BizModel().setBizState(BizState.DEACTIVATED).setBizName("mock name").setBizVersion("mock name").setClassLoader(bizClassLoader);
Assert.assertNotNull(map.get(bizClassLoader));
biz.stop();
Assert.assertNull(map.get(bizClassLoader));
Assert.assertTrue(mark == 50);
EventHandler eventHandler = new LowPriorityMockEventHandler();
eventAdminService.register(eventHandler);
Assert.assertNotNull(map.get(bizClassLoader));
eventAdminService.unRegister(eventHandler);
Assert.assertFalse(((Set) map.get(bizClassLoader)).contains(eventHandler));
}
Aggregations