Search in sources :

Example 1 with AfterFinishStartupEvent

use of com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent in project sofa-ark by alipay.

the class ZookeeperConfigActivator method registerEventHandler.

protected void registerEventHandler(final PluginContext context) {
    final String bizInitConfig = new String(bizNodeCache.getCurrentData().getData());
    EventAdminService eventAdminService = context.referenceService(EventAdminService.class).getService();
    eventAdminService.register(new EventHandler<AfterFinishDeployEvent>() {

        @Override
        public void handleEvent(AfterFinishDeployEvent event) {
            LOGGER.info("Start to process init app config: {}", bizInitConfig);
            OperationProcessor.process(OperationTransformer.transformToBizOperation(bizInitConfig, context));
        }

        @Override
        public int getPriority() {
            return 0;
        }
    });
    eventAdminService.register(new EventHandler<AfterFinishStartupEvent>() {

        @Override
        public void handleEvent(AfterFinishStartupEvent event) {
            ConfigProcessor.createConfigProcessor(context, ipConfigDeque, "ip-zookeeper-config").start();
            ConfigProcessor.createConfigProcessor(context, bizConfigDeque, "app-zookeeper-config").start();
        }

        @Override
        public int getPriority() {
            return 0;
        }
    });
}
Also used : AfterFinishDeployEvent(com.alipay.sofa.ark.spi.event.AfterFinishDeployEvent) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) AfterFinishStartupEvent(com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent)

Example 2 with AfterFinishStartupEvent

use of com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent in project sofa-ark by alipay.

the class EventTest method testEvent.

@Test
public void testEvent() {
    Biz biz = new BizModel().setBizName("test-biz").setBizVersion("1.0.0").setBizState(BizState.RESOLVED);
    Plugin plugin = new PluginModel().setPluginName("test-plugin").setVersion("1.0.0");
    eventAdminService.sendEvent(new AfterBizStartupEvent(biz));
    Assert.assertTrue(result.get(0).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_START));
    eventAdminService.sendEvent(new BeforeBizStartupEvent(biz));
    Assert.assertTrue(result.get(1).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_START));
    eventAdminService.sendEvent(new BeforeBizStopEvent(biz));
    Assert.assertTrue(result.get(2).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_STOP));
    eventAdminService.sendEvent(new AfterBizStopEvent(biz));
    Assert.assertTrue(result.get(3).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_STOP));
    eventAdminService.sendEvent(new BeforeBizSwitchEvent(biz));
    Assert.assertTrue(result.get(4).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_SWITCH));
    eventAdminService.sendEvent(new AfterBizSwitchEvent(biz));
    Assert.assertTrue(result.get(5).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_SWITCH));
    eventAdminService.sendEvent(new AfterPluginStartupEvent(plugin));
    Assert.assertTrue(result.get(6).equalsIgnoreCase(Constants.PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_START));
    eventAdminService.sendEvent(new AfterPluginStopEvent(plugin));
    Assert.assertTrue(result.get(7).equalsIgnoreCase(Constants.PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_STOP));
    eventAdminService.sendEvent(new BeforePluginStartupEvent(plugin));
    Assert.assertTrue(result.get(8).equalsIgnoreCase(Constants.PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_START));
    eventAdminService.sendEvent(new BeforePluginStopEvent(plugin));
    Assert.assertTrue(result.get(9).equalsIgnoreCase(Constants.PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_STOP));
    eventAdminService.sendEvent(new AfterFinishDeployEvent());
    Assert.assertTrue(result.get(10).equalsIgnoreCase(Constants.ARK_EVENT_TOPIC_AFTER_FINISH_DEPLOY_STAGE));
    eventAdminService.sendEvent(new AfterFinishStartupEvent());
    Assert.assertTrue(result.get(11).equalsIgnoreCase(Constants.ARK_EVENT_TOPIC_AFTER_FINISH_STARTUP_STAGE));
    eventAdminService.sendEvent(new TestArkEvent(""));
    Assert.assertTrue(result.get(12).equalsIgnoreCase("test-ark"));
    eventAdminService.sendEvent(new BeforeBizRecycleEvent(biz));
    Assert.assertTrue(result.get(13).equalsIgnoreCase(Constants.BIZ_EVENT_TOPIC_BEFORE_RECYCLE_BIZ));
}
Also used : BeforePluginStopEvent(com.alipay.sofa.ark.spi.event.plugin.BeforePluginStopEvent) AfterPluginStartupEvent(com.alipay.sofa.ark.spi.event.plugin.AfterPluginStartupEvent) AfterBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent) AfterFinishStartupEvent(com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent) BeforeBizSwitchEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizSwitchEvent) BizModel(com.alipay.sofa.ark.container.model.BizModel) AfterBizStopEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStopEvent) BeforeBizRecycleEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizRecycleEvent) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BeforePluginStartupEvent(com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent) Biz(com.alipay.sofa.ark.spi.model.Biz) BeforeBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent) AfterFinishDeployEvent(com.alipay.sofa.ark.spi.event.AfterFinishDeployEvent) AfterBizSwitchEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizSwitchEvent) BeforeBizStopEvent(com.alipay.sofa.ark.spi.event.biz.BeforeBizStopEvent) Plugin(com.alipay.sofa.ark.spi.model.Plugin) AfterPluginStopEvent(com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Example 3 with AfterFinishStartupEvent

use of com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent in project sofa-ark by alipay.

the class MultiEventTest method testEvent.

@Test
public void testEvent() {
    eventAdminService.sendEvent(new AfterFinishStartupEvent());
    Assert.assertTrue(result.get(0).equalsIgnoreCase(Constants.ARK_EVENT_TOPIC_AFTER_FINISH_STARTUP_STAGE));
}
Also used : AfterFinishStartupEvent(com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 4 with AfterFinishStartupEvent

use of com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent in project sofa-ark by alipay.

the class ArkApplicationStartListener method startUpArkEmbed.

protected void startUpArkEmbed(SpringApplicationEvent event) {
    if (this.getClass().getClassLoader() != Thread.currentThread().getContextClassLoader()) {
        return;
    }
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        ApplicationEnvironmentPreparedEvent preparedEvent = (ApplicationEnvironmentPreparedEvent) event;
        EmbedSofaArkBootstrap.launch(preparedEvent.getEnvironment());
    }
    if (event instanceof ApplicationReadyEvent) {
        if (ArkClient.getEventAdminService() != null && ArkClient.getMasterBiz() != null) {
            ArkClient.getEventAdminService().sendEvent(new AfterBizStartupEvent(ArkClient.getMasterBiz()));
            ArkClient.getEventAdminService().sendEvent(new AfterFinishDeployEvent());
            ArkClient.getEventAdminService().sendEvent(new AfterFinishStartupEvent());
        }
    }
}
Also used : AfterFinishDeployEvent(com.alipay.sofa.ark.spi.event.AfterFinishDeployEvent) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) AfterBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent) AfterFinishStartupEvent(com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)

Aggregations

AfterFinishStartupEvent (com.alipay.sofa.ark.spi.event.AfterFinishStartupEvent)4 AfterFinishDeployEvent (com.alipay.sofa.ark.spi.event.AfterFinishDeployEvent)3 BaseTest (com.alipay.sofa.ark.container.BaseTest)2 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)2 Test (org.junit.Test)2 BizModel (com.alipay.sofa.ark.container.model.BizModel)1 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)1 AfterBizStopEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStopEvent)1 AfterBizSwitchEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizSwitchEvent)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 BeforeBizSwitchEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizSwitchEvent)1 AfterPluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.AfterPluginStartupEvent)1 AfterPluginStopEvent (com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent)1 BeforePluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent)1 BeforePluginStopEvent (com.alipay.sofa.ark.spi.event.plugin.BeforePluginStopEvent)1 Biz (com.alipay.sofa.ark.spi.model.Biz)1 Plugin (com.alipay.sofa.ark.spi.model.Plugin)1 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)1