Example usage for org.springframework.context.event ApplicationEventMulticaster multicastEvent

List of usage examples for org.springframework.context.event ApplicationEventMulticaster multicastEvent

Introduction

In this page you can find the example usage for org.springframework.context.event ApplicationEventMulticaster multicastEvent.

Prototype

void multicastEvent(ApplicationEvent event);

Source Link

Document

Multicast the given application event to appropriate listeners.

Usage

From source file:org.openspaces.core.space.mode.SpaceModeContextLoader.java

/**
 * A hack to only send the application event on the child application context we are loading,
 * without propogating it to the parent application context (when using {@link
 * ApplicationContext#publishEvent(org.springframework.context.ApplicationEvent)} which will
 * create a recursive event calling.//from w ww . jav a 2s  .  c  o  m
 */
protected void publishEvent(ApplicationEvent applicationEvent) {
    if (applicationContext == null) {
        return;
    }
    ApplicationEventMulticaster eventMulticaster;
    try {
        MethodInvoker methodInvoker = new MethodInvoker();
        methodInvoker.setTargetClass(AbstractApplicationContext.class);
        methodInvoker.setTargetMethod("getApplicationEventMulticaster");
        methodInvoker.setTargetObject(applicationContext);
        methodInvoker.setArguments(null);
        methodInvoker.prepare();
        eventMulticaster = (ApplicationEventMulticaster) methodInvoker.invoke();
    } catch (Exception e) {
        logger.warn("Failed to get application event multicaster to publish event to child application context",
                e);
        return;
    }
    eventMulticaster.multicastEvent(applicationEvent);
}