Search in sources :

Example 1 with MainMethodRunner

use of com.alipay.sofa.ark.bootstrap.MainMethodRunner 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;
        }
    }
}
Also used : BeforeBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent) MainMethodRunner(com.alipay.sofa.ark.bootstrap.MainMethodRunner) Biz(com.alipay.sofa.ark.spi.model.Biz) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) AfterBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent) AbstractClasspathClassLoader(com.alipay.sofa.ark.container.service.classloader.AbstractClasspathClassLoader) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Aggregations

MainMethodRunner (com.alipay.sofa.ark.bootstrap.MainMethodRunner)1 AbstractClasspathClassLoader (com.alipay.sofa.ark.container.service.classloader.AbstractClasspathClassLoader)1 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)1 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)1 BeforeBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent)1 Biz (com.alipay.sofa.ark.spi.model.Biz)1 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)1 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)1