Search in sources :

Example 1 with ArkService

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

the class ArkServiceContainer method stop.

/**
 * Stop Ark Service Container
 * @throws ArkRuntimeException
 * @since 0.1.0
 */
public void stop() throws ArkRuntimeException {
    if (stopped.compareAndSet(false, true)) {
        LOGGER.info("Begin to stop ArkServiceContainer");
        ClassLoader oldClassLoader = ClassLoaderUtils.pushContextClassLoader(getClass().getClassLoader());
        try {
            Collections.reverse(arkServiceList);
            for (ArkService arkService : arkServiceList) {
                LOGGER.info(String.format("Dispose service: %s", arkService.getClass().getName()));
                arkService.dispose();
            }
            LOGGER.info("Finish to stop ArkServiceContainer");
        } finally {
            ClassLoaderUtils.popContextClassLoader(oldClassLoader);
        }
    }
}
Also used : ArkService(com.alipay.sofa.ark.spi.service.ArkService)

Example 2 with ArkService

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

the class ArkServiceContainer method start.

/**
 * Start Ark Service Container
 * @throws ArkRuntimeException
 * @since 0.1.0
 */
public void start() throws ArkRuntimeException {
    if (started.compareAndSet(false, true)) {
        ClassLoader oldClassLoader = ClassLoaderUtils.pushContextClassLoader(getClass().getClassLoader());
        try {
            LOGGER.info("Begin to start ArkServiceContainer");
            injector = Guice.createInjector(findServiceModules());
            for (Binding<ArkService> binding : injector.findBindingsByType(new TypeLiteral<ArkService>() {
            })) {
                arkServiceList.add(binding.getProvider().get());
            }
            Collections.sort(arkServiceList, new OrderComparator());
            for (ArkService arkService : arkServiceList) {
                LOGGER.info(String.format("Init Service: %s", arkService.getClass().getName()));
                arkService.init();
            }
            ArkServiceContainerHolder.setContainer(this);
            ArkClient.setBizFactoryService(getService(BizFactoryService.class));
            ArkClient.setBizManagerService(getService(BizManagerService.class));
            ArkClient.setInjectionService(getService(InjectionService.class));
            ArkClient.setEventAdminService(getService(EventAdminService.class));
            ArkClient.setArguments(arguments);
            LOGGER.info("Finish to start ArkServiceContainer");
        } finally {
            ClassLoaderUtils.popContextClassLoader(oldClassLoader);
        }
    }
}
Also used : ArkService(com.alipay.sofa.ark.spi.service.ArkService) BizFactoryService(com.alipay.sofa.ark.spi.service.biz.BizFactoryService) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) InjectionService(com.alipay.sofa.ark.spi.service.injection.InjectionService) OrderComparator(com.alipay.sofa.ark.common.util.OrderComparator) BizManagerService(com.alipay.sofa.ark.spi.service.biz.BizManagerService)

Aggregations

ArkService (com.alipay.sofa.ark.spi.service.ArkService)2 OrderComparator (com.alipay.sofa.ark.common.util.OrderComparator)1 BizFactoryService (com.alipay.sofa.ark.spi.service.biz.BizFactoryService)1 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)1 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)1 InjectionService (com.alipay.sofa.ark.spi.service.injection.InjectionService)1