Search in sources :

Example 1 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException 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)

Example 2 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException 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));
    }
}
Also used : BeforePluginStopEvent(com.alipay.sofa.ark.spi.event.plugin.BeforePluginStopEvent) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) AfterPluginStopEvent(com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent)

Example 3 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException 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);
    }
}
Also used : BeforePluginStartupEvent(com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) AfterPluginStartupEvent(com.alipay.sofa.ark.spi.event.plugin.AfterPluginStartupEvent) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 4 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.

the class StandardTelnetServerImpl method run.

@Override
public void run() {
    AssertUtils.isTrue(port > 0, "Telnet port should be positive integer.");
    try {
        LOGGER.info("Listening on port: " + port);
        CommonThreadPool workerPool = new CommonThreadPool().setCorePoolSize(WORKER_THREAD_POOL_SIZE).setDaemon(true).setThreadPoolName(Constants.TELNET_SERVER_WORKER_THREAD_POOL_NAME);
        ThreadPoolManager.registerThreadPool(Constants.TELNET_SERVER_WORKER_THREAD_POOL_NAME, workerPool);
        nettyTelnetServer = new NettyTelnetServer(port, workerPool.getExecutor());
        nettyTelnetServer.open();
    } catch (InterruptedException e) {
        LOGGER.error("Unable to open netty telnet server.", e);
        throw new ArkRuntimeException(e);
    }
}
Also used : CommonThreadPool(com.alipay.sofa.ark.common.thread.CommonThreadPool) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 5 with ArkRuntimeException

use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.

the class StandardTelnetServerImpl method shutdown.

@Override
public void shutdown() {
    if (shutdown.compareAndSet(false, true)) {
        try {
            if (nettyTelnetServer != null) {
                nettyTelnetServer.close();
                nettyTelnetServer = null;
            }
        } catch (Throwable t) {
            LOGGER.error("An error occurs when shutdown telnet server.", t);
            throw new ArkRuntimeException(t);
        }
    }
}
Also used : ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Aggregations

ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)23 Biz (com.alipay.sofa.ark.spi.model.Biz)6 URL (java.net.URL)4 ArkContainerTest (com.alipay.sofa.ark.container.ArkContainerTest)3 BaseTest (com.alipay.sofa.ark.container.BaseTest)3 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)3 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)3 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)3 PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)3 File (java.io.File)3 KeeperException (org.apache.zookeeper.KeeperException)3 Test (org.junit.Test)3 BizModel (com.alipay.sofa.ark.container.model.BizModel)2 Plugin (com.alipay.sofa.ark.spi.model.Plugin)2 Extensible (com.alipay.sofa.ark.spi.service.extension.Extensible)2 Extension (com.alipay.sofa.ark.spi.service.extension.Extension)2 HashSet (java.util.HashSet)2 NodeCache (org.apache.curator.framework.recipes.cache.NodeCache)2 NodeCacheListener (org.apache.curator.framework.recipes.cache.NodeCacheListener)2 ClassPathArchive (com.alipay.sofa.ark.bootstrap.ClasspathLauncher.ClassPathArchive)1