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.event; 018 019import org.springframework.context.ApplicationEvent; 020import org.springframework.context.ApplicationListener; 021import org.springframework.core.ResolvableType; 022import org.springframework.lang.Nullable; 023 024/** 025 * Interface to be implemented by objects that can manage a number of 026 * {@link ApplicationListener} objects and publish events to them. 027 * 028 * <p>An {@link org.springframework.context.ApplicationEventPublisher}, typically 029 * a Spring {@link org.springframework.context.ApplicationContext}, can use an 030 * {@code ApplicationEventMulticaster} as a delegate for actually publishing events. 031 * 032 * @author Rod Johnson 033 * @author Juergen Hoeller 034 * @author Stephane Nicoll 035 * @see ApplicationListener 036 */ 037public interface ApplicationEventMulticaster { 038 039 /** 040 * Add a listener to be notified of all events. 041 * @param listener the listener to add 042 */ 043 void addApplicationListener(ApplicationListener<?> listener); 044 045 /** 046 * Add a listener bean to be notified of all events. 047 * @param listenerBeanName the name of the listener bean to add 048 */ 049 void addApplicationListenerBean(String listenerBeanName); 050 051 /** 052 * Remove a listener from the notification list. 053 * @param listener the listener to remove 054 */ 055 void removeApplicationListener(ApplicationListener<?> listener); 056 057 /** 058 * Remove a listener bean from the notification list. 059 * @param listenerBeanName the name of the listener bean to remove 060 */ 061 void removeApplicationListenerBean(String listenerBeanName); 062 063 /** 064 * Remove all listeners registered with this multicaster. 065 * <p>After a remove call, the multicaster will perform no action 066 * on event notification until new listeners are registered. 067 */ 068 void removeAllListeners(); 069 070 /** 071 * Multicast the given application event to appropriate listeners. 072 * <p>Consider using {@link #multicastEvent(ApplicationEvent, ResolvableType)} 073 * if possible as it provides better support for generics-based events. 074 * @param event the event to multicast 075 */ 076 void multicastEvent(ApplicationEvent event); 077 078 /** 079 * Multicast the given application event to appropriate listeners. 080 * <p>If the {@code eventType} is {@code null}, a default type is built 081 * based on the {@code event} instance. 082 * @param event the event to multicast 083 * @param eventType the type of event (can be {@code null}) 084 * @since 4.2 085 */ 086 void multicastEvent(ApplicationEvent event, @Nullable ResolvableType eventType); 087 088}