Java Code Examples for org.springframework.context.ApplicationListener#onApplicationEvent()

The following examples show how to use org.springframework.context.ApplicationListener#onApplicationEvent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleApplicationEventMulticaster.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) {
	try {
		listener.onApplicationEvent(event);
	}
	catch (ClassCastException ex) {
		String msg = ex.getMessage();
		if (msg == null || matchesClassCastMessage(msg, event.getClass())) {
			// Possibly a lambda-defined listener which we could not resolve the generic event type for
			// -> let's suppress the exception and just log a debug message.
			Log logger = LogFactory.getLog(getClass());
			if (logger.isTraceEnabled()) {
				logger.trace("Non-matching event type for listener: " + listener, ex);
			}
		}
		else {
			throw ex;
		}
	}
}
 
Example 2
Source File: SimpleApplicationEventMulticaster.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) {
	try {
		listener.onApplicationEvent(event);
	}
	catch (ClassCastException ex) {
		String msg = ex.getMessage();
		if (msg == null || matchesClassCastMessage(msg, event.getClass())) {
			// Possibly a lambda-defined listener which we could not resolve the generic event type for
			// -> let's suppress the exception and just log a debug message.
			Log logger = LogFactory.getLog(getClass());
			if (logger.isDebugEnabled()) {
				logger.debug("Non-matching event type for listener: " + listener, ex);
			}
		}
		else {
			throw ex;
		}
	}
}
 
Example 3
Source File: SafeApplicationEventMulticaster.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void multicastEventInternal(final ApplicationEvent event) {
    for (final ApplicationListener listener : getApplicationListeners(event)) {
        Executor executor = getTaskExecutor();
        if (executor != null) {
            executor.execute(new Runnable() {
                public void run() {
                    listener.onApplicationEvent(event);
                }
            });
        }
        else {
            listener.onApplicationEvent(event);
        }
    }
}
 
Example 4
Source File: SimpleApplicationEventMulticaster.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) {
	try {
		listener.onApplicationEvent(event);
	}
	catch (ClassCastException ex) {
		String msg = ex.getMessage();
		if (msg == null || msg.startsWith(event.getClass().getName())) {
			// Possibly a lambda-defined listener which we could not resolve the generic event type for
			Log logger = LogFactory.getLog(getClass());
			if (logger.isDebugEnabled()) {
				logger.debug("Non-matching event type for listener: " + listener, ex);
			}
		}
		else {
			throw ex;
		}
	}
}
 
Example 5
Source File: SimpleApplicationEventMulticaster.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Invoke the given listener with the given event.
 * @param listener the ApplicationListener to invoke
 * @param event the current event to propagate
 * @since 4.1
 */
@SuppressWarnings({"unchecked", "rawtypes"})
protected void invokeListener(ApplicationListener listener, ApplicationEvent event) {
	ErrorHandler errorHandler = getErrorHandler();
	if (errorHandler != null) {
		try {
			listener.onApplicationEvent(event);
		}
		catch (Throwable err) {
			errorHandler.handleError(err);
		}
	}
	else {
		listener.onApplicationEvent(event);
	}
}
 
Example 6
Source File: PublishedEventsParameterResolver.java    From moduliths with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {

	ApplicationListener<ApplicationEvent> listener = delegate.get();

	if (listener != null) {
		listener.onApplicationEvent(event);
	}
}
 
Example 7
Source File: IndexInfo.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void notifyListeners(String description, int count)
{
    if (!this.applicationListeners.isEmpty())
    {
        IndexEvent event = new IndexEvent(this, description, count);
        for (ApplicationListener listener : this.applicationListeners)
        {
            listener.onApplicationEvent(event);
        }
    }
}
 
Example 8
Source File: DefaultPropertyBackedBeanRegistry.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Broadcast event.
 * 
 * @param event
 *            the event
 */
private void broadcastEvent(PropertyBackedBeanEvent event)
{
    // If the system is up and running, broadcast the event immediately
    if (this.isSchemaAvailable && this.wasDictionaryBootstrapped)
    {
        // If we have a transaction, the changed properties in it should be updated earlier,
        // then the bean restart message will be sent to other node
        // see ALF-20066
        if (AlfrescoTransactionSupport.getTransactionId() != null &&
                (event instanceof PropertyBackedBeanStartedEvent ||
                event instanceof PropertyBackedBeanStoppedEvent))
        {
            this.afterTransactionEvents.add(event);
            AlfrescoTransactionSupport.bindListener(this);
        }
        else
        {
            for (ApplicationListener listener : this.listeners)
            {
                listener.onApplicationEvent(event);
            }
        }
    }
    // Otherwise, defer broadcasting until the schema available event is handled
    else
    {
        this.deferredEvents.add(event);
    }
}
 
Example 9
Source File: DefaultPropertyBackedBeanRegistry.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void afterCommit()
{
    for (ApplicationEvent event : this.afterTransactionEvents)
    {
        for (ApplicationListener listener : this.listeners)
        {
            listener.onApplicationEvent(event);
        }
    }
    this.afterTransactionEvents.clear();
}
 
Example 10
Source File: PersistentApplicationEventMulticaster.java    From spring-domain-events with Apache License 2.0 5 votes vote down vote up
private void executeListenerWithCompletion(EventPublication publication,
		ApplicationListener<ApplicationEvent> listener) {

	try {

		listener.onApplicationEvent(publication.getApplicationEvent());
		registry.get().markCompleted(publication);

	} catch (Exception e) {
		// Log
	}
}
 
Example 11
Source File: UiEventsMulticasterImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
protected void invokeListener(ApplicationListener listener, ApplicationEvent event) {
    try {
        listener.onApplicationEvent(event);
    } catch (ClassCastException ex) {
        String msg = ex.getMessage();
        if (msg == null || msg.startsWith(event.getClass().getName())) {
            // Possibly a lambda-defined listener which we could not resolve the generic event type for
            LoggerFactory.getLogger(UiEventsMulticaster.class)
                    .debug("Non-matching event type for listener: {}", listener, ex);
        } else {
            throw ex;
        }
    }
}