use of com.alipay.sofa.ark.spi.service.event.EventAdminService in project sofa-ark by alipay.
the class ArkClientTest method testBizArguments.
@Test
public void testBizArguments() throws Throwable {
EventAdminService eventAdminService = arkServiceContainer.getService(EventAdminService.class);
List<String> topicList = new ArrayList<>();
EventHandler eventHandler = new EventHandler<ArkEvent>() {
@Override
public void handleEvent(ArkEvent event) {
topicList.add(event.getTopic());
}
@Override
public int getPriority() {
return 0;
}
};
eventAdminService.register(eventHandler);
File bizFile3 = ArkClient.createBizSaveFile("biz-demo", "3.0.0");
FileUtils.copyInputStreamToFile(bizUrl3.openStream(), bizFile3);
ArkClient.installBiz(bizFile3);
// ArkClient.installBiz(new File(bizUrl3.getFile()));
ArkClient.uninstallBiz("biz-demo", "3.0.0");
File bizFile33 = ArkClient.createBizSaveFile("biz-demo", "3.0.0");
FileUtils.copyInputStreamToFile(bizUrl3.openStream(), bizFile33);
ArkClient.installBiz(bizFile33, new String[] { "demo" });
ArkClient.uninstallBiz("biz-demo", "3.0.0");
Assert.assertEquals("BEFORE-INVOKE-BIZ-START", topicList.get(0));
Assert.assertEquals("No arguments", topicList.get(1));
Assert.assertEquals("AFTER-INVOKE-BIZ-START", topicList.get(2));
// new event
Assert.assertEquals("BEFORE-RECYCLE-BIZ", topicList.get(4));
Assert.assertEquals("demo", topicList.get(7));
}
use of com.alipay.sofa.ark.spi.service.event.EventAdminService in project sofa-ark by alipay.
the class BizModel method stop.
@Override
public void stop() {
AssertUtils.isTrue(bizState == BizState.ACTIVATED || bizState == BizState.DEACTIVATED || bizState == BizState.BROKEN, "BizState must be ACTIVATED, DEACTIVATED or BROKEN.");
if (isMasterBizAndEmbedEnable()) {
// skip stop when embed mode
return;
}
ClassLoader oldClassLoader = ClassLoaderUtils.pushContextClassLoader(this.classLoader);
bizState = BizState.DEACTIVATED;
EventAdminService eventAdminService = ArkServiceContainerHolder.getContainer().getService(EventAdminService.class);
try {
// this can trigger uninstall handler
eventAdminService.sendEvent(new BeforeBizStopEvent(this));
} finally {
BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
bizManagerService.unRegisterBiz(bizName, bizVersion);
bizState = BizState.UNRESOLVED;
eventAdminService.sendEvent(new BeforeBizRecycleEvent(this));
urls = null;
denyImportPackages = null;
denyImportClasses = null;
denyImportResources = null;
if (bizTempWorkDir != null && bizTempWorkDir.exists()) {
bizTempWorkDir.delete();
}
bizTempWorkDir = null;
if (classLoader instanceof AbstractClasspathClassLoader) {
((AbstractClasspathClassLoader) classLoader).clearCache();
}
classLoader = null;
ClassLoaderUtils.popContextClassLoader(oldClassLoader);
eventAdminService.sendEvent(new AfterBizStopEvent(this));
}
}
Aggregations