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