Example usage for org.springframework.context ConfigurableApplicationContext publishEvent

List of usage examples for org.springframework.context ConfigurableApplicationContext publishEvent

Introduction

In this page you can find the example usage for org.springframework.context ConfigurableApplicationContext publishEvent.

Prototype

default void publishEvent(ApplicationEvent event) 

Source Link

Document

Notify all matching listeners registered with this application of an application event.

Usage

From source file:org.alfresco.repo.search.impl.lucene.index.IndexInfo.java

private void publishDiscoveryEvent() {
    if (this.config == null) {
        return;/*from   w  w  w  . java2 s. co  m*/
    }
    final IndexEvent discoveryEvent = new IndexEvent(this, "Discovery", 1);
    final ConfigurableApplicationContext applicationContext = this.config.getApplicationContext();
    try {
        applicationContext.publishEvent(discoveryEvent);
    } catch (IllegalStateException e) {
        // There's a possibility that the application context hasn't fully refreshed yet, so register a listener
        // that will fire when it has
        applicationContext.addApplicationListener(new ApplicationListener() {

            public void onApplicationEvent(ApplicationEvent event) {
                if (event instanceof ContextRefreshedEvent) {
                    applicationContext.publishEvent(discoveryEvent);
                }
            }
        });
    }
}

From source file:org.springframework.boot.context.event.EventPublishingRunListener.java

@Override
public void started(ConfigurableApplicationContext context) {
    context.publishEvent(new ApplicationStartedEvent(this.application, this.args, context));
}

From source file:org.springframework.boot.context.event.EventPublishingRunListener.java

@Override
public void running(ConfigurableApplicationContext context) {
    context.publishEvent(new ApplicationReadyEvent(this.application, this.args, context));
}

From source file:org.springframework.boot.context.event.EventPublishingRunListener.java

@Override
public void failed(ConfigurableApplicationContext context, Throwable exception) {
    ApplicationFailedEvent event = new ApplicationFailedEvent(this.application, this.args, context, exception);
    if (context != null && context.isActive()) {
        // Listeners have been registered to the application context so we should
        // use it at this point if we can
        context.publishEvent(event);
    } else {/* w ww  . jav  a  2s  .  c  o  m*/
        // An inactive context may not have a multicaster so we use our multicaster to
        // call all of the context's listeners instead
        if (context instanceof AbstractApplicationContext) {
            for (ApplicationListener<?> listener : ((AbstractApplicationContext) context)
                    .getApplicationListeners()) {
                this.initialMulticaster.addApplicationListener(listener);
            }
        }
        this.initialMulticaster.setErrorHandler(new LoggingErrorHandler());
        this.initialMulticaster.multicastEvent(event);
    }
}

From source file:org.springframework.cloud.consul.bus.ConsulBusIT.java

@Test
public void test001ConsulOutboundEndpoint_HandleRequestMessage() {
    ConfigurableApplicationContext context = getOutboundContext();
    context.publishEvent(new SimpleRemoteEvent(this, "testService", "testMessage"));
}