001/*
002 * Copyright 2002-2019 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.context;
018
019/**
020 * Interface that encapsulates event publication functionality.
021 *
022 * <p>Serves as a super-interface for {@link ApplicationContext}.
023 *
024 * @author Juergen Hoeller
025 * @author Stephane Nicoll
026 * @since 1.1.1
027 * @see ApplicationContext
028 * @see ApplicationEventPublisherAware
029 * @see org.springframework.context.ApplicationEvent
030 * @see org.springframework.context.event.ApplicationEventMulticaster
031 * @see org.springframework.context.event.EventPublicationInterceptor
032 */
033@FunctionalInterface
034public interface ApplicationEventPublisher {
035
036        /**
037         * Notify all <strong>matching</strong> listeners registered with this
038         * application of an application event. Events may be framework events
039         * (such as ContextRefreshedEvent) or application-specific events.
040         * <p>Such an event publication step is effectively a hand-off to the
041         * multicaster and does not imply synchronous/asynchronous execution
042         * or even immediate execution at all. Event listeners are encouraged
043         * to be as efficient as possible, individually using asynchronous
044         * execution for longer-running and potentially blocking operations.
045         * @param event the event to publish
046         * @see #publishEvent(Object)
047         * @see org.springframework.context.event.ContextRefreshedEvent
048         * @see org.springframework.context.event.ContextClosedEvent
049         */
050        default void publishEvent(ApplicationEvent event) {
051                publishEvent((Object) event);
052        }
053
054        /**
055         * Notify all <strong>matching</strong> listeners registered with this
056         * application of an event.
057         * <p>If the specified {@code event} is not an {@link ApplicationEvent},
058         * it is wrapped in a {@link PayloadApplicationEvent}.
059         * <p>Such an event publication step is effectively a hand-off to the
060         * multicaster and does not imply synchronous/asynchronous execution
061         * or even immediate execution at all. Event listeners are encouraged
062         * to be as efficient as possible, individually using asynchronous
063         * execution for longer-running and potentially blocking operations.
064         * @param event the event to publish
065         * @since 4.2
066         * @see #publishEvent(ApplicationEvent)
067         * @see PayloadApplicationEvent
068         */
069        void publishEvent(Object event);
070
071}