Search in sources :

Example 1 with EmbeddedSaturn

use of com.vip.saturn.embed.EmbeddedSaturn in project Saturn by vipshop.

the class EmbeddedSpringSaturnApplication method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEvent event) {
    try {
        if (event instanceof ContextRefreshedEvent) {
            ContextRefreshedEvent contextRefreshedEvent = (ContextRefreshedEvent) event;
            applicationContext = contextRefreshedEvent.getApplicationContext();
            if (embeddedSaturn == null) {
                embeddedSaturn = new EmbeddedSaturn();
                embeddedSaturn.setSaturnApplication(this);
                embeddedSaturn.start();
            }
        } else if (event instanceof ContextClosedEvent) {
            if (embeddedSaturn != null) {
                embeddedSaturn.stopGracefully();
                embeddedSaturn = null;
            }
        }
    } catch (Exception e) {
        logger.warn("exception happened on event: " + event, e);
        if (!ignoreExceptions) {
            throw new RuntimeException(e);
        }
    }
}
Also used : EmbeddedSaturn(com.vip.saturn.embed.EmbeddedSaturn) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent)

Aggregations

EmbeddedSaturn (com.vip.saturn.embed.EmbeddedSaturn)1 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)1 ContextRefreshedEvent (org.springframework.context.event.ContextRefreshedEvent)1