Search in sources :

Example 6 with EventAdminService

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));
}
Also used : EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) ArrayList(java.util.ArrayList) EventHandler(com.alipay.sofa.ark.spi.service.event.EventHandler) ArkEvent(com.alipay.sofa.ark.spi.event.ArkEvent) File(java.io.File) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 7 with EventAdminService

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));
    }
}
Also used : BeforeBizRecycleEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizRecycleEvent) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) AbstractClasspathClassLoader(com.alipay.sofa.ark.container.service.classloader.AbstractClasspathClassLoader) BeforeBizStopEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizStopEvent) AfterBizStopEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStopEvent) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) AbstractClasspathClassLoader(com.alipay.sofa.ark.container.service.classloader.AbstractClasspathClassLoader)

Aggregations

EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)7 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)3 BaseTest (com.alipay.sofa.ark.container.BaseTest)2 AbstractClasspathClassLoader (com.alipay.sofa.ark.container.service.classloader.AbstractClasspathClassLoader)2 Biz (com.alipay.sofa.ark.spi.model.Biz)2 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)2 EventHandler (com.alipay.sofa.ark.spi.service.event.EventHandler)2 Test (org.junit.Test)2 MainMethodRunner (com.alipay.sofa.ark.bootstrap.MainMethodRunner)1 BizModel (com.alipay.sofa.ark.container.model.BizModel)1 AfterFinishDeployEvent (com.alipay.sofa.ark.spi.event.AfterFinishDeployEvent)1 AfterFinishStartupEvent (com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent)1 ArkEvent (com.alipay.sofa.ark.spi.event.ArkEvent)1 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)1 AfterBizStopEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStopEvent)1 BeforeBizRecycleEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizRecycleEvent)1 BeforeBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent)1 BeforeBizStopEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizStopEvent)1 AfterPluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.AfterPluginStartupEvent)1 AfterPluginStopEvent (com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent)1