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;
}
}
}
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));
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations