Search in sources :

Example 6 with BizManagerService

use of com.alipay.sofa.ark.spi.service.biz.BizManagerService in project sofa-ark by alipay.

the class BaseTest method registerMockBiz.

protected void registerMockBiz() {
    if (arkContainer == null) {
        String[] args = new String[] { "-Ajar=" + jarURL.toExternalForm() };
        arkContainer = (ArkContainer) ArkContainer.main(args);
    }
    BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
    Biz biz = new BizModel().setBizName("mock").setBizVersion("1.0").setClassLoader(this.getClass().getClassLoader()).setDenyImportPackages("").setDenyImportClasses("").setDenyImportResources("").setBizState(BizState.RESOLVED);
    bizManagerService.registerBiz(biz);
    ((BizModel) biz).setBizState(BizState.ACTIVATED);
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService)

Example 7 with BizManagerService

use of com.alipay.sofa.ark.spi.service.biz.BizManagerService in project sofa-ark by alipay.

the class TestClassLoader method createTestBiz.

private Biz createTestBiz(String bizIdentity) {
    String[] bizNameAndVersion = bizIdentity.split(":");
    if (bizNameAndVersion.length != 2) {
        throw new ArkRuntimeException("error bizIdentity format.");
    }
    BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
    Biz testBiz = new BizModel().setBizName(bizNameAndVersion[0]).setBizVersion(bizNameAndVersion[1]).setClassLoader(this).setDenyImportPackages("").setDenyImportClasses("").setDenyImportResources("").setBizState(BizState.RESOLVED);
    bizManagerService.registerBiz(testBiz);
    return testBiz;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 8 with BizManagerService

use of com.alipay.sofa.ark.spi.service.biz.BizManagerService 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

BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)8 Biz (com.alipay.sofa.ark.spi.model.Biz)6 BizModel (com.alipay.sofa.ark.container.model.BizModel)3 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)3 AbstractClasspathClassLoader (com.alipay.sofa.ark.container.service.classloader.AbstractClasspathClassLoader)2 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)2 MainMethodRunner (com.alipay.sofa.ark.bootstrap.MainMethodRunner)1 ArkServiceContainer (com.alipay.sofa.ark.container.service.ArkServiceContainer)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 PluginContext (com.alipay.sofa.ark.spi.model.PluginContext)1 ServiceReference (com.alipay.sofa.ark.spi.registry.ServiceReference)1 ClassloaderService (com.alipay.sofa.ark.spi.service.classloader.ClassloaderService)1 PluginDeployService (com.alipay.sofa.ark.spi.service.plugin.PluginDeployService)1 PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1