T - The listener type.public class ListenerBroadcast<T> extends Object implements StoppableDispatch<MethodInvocation>
Manages a set of listeners of type T. Provides an implementation of T which can be used to broadcast to all registered listeners.
Ordering is maintained for events, so that events are delivered to listeners in the order they are generated. Events are delivered to listeners in the order that listeners are added to this broadcaster.
| Modifier | Constructor and Description |
|---|---|
|
ListenerBroadcast(Class<T> type) |
protected |
ListenerBroadcast(Class<T> type,
Transformer<StoppableDispatch<MethodInvocation>,StoppableDispatch<MethodInvocation>> transformer) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(Dispatch<MethodInvocation> dispatch)
Adds a
Dispatch to receive events from this broadcast. |
void |
add(String methodName,
Action<?> action)
Adds an action to be executed when the given method is called.
|
void |
add(String methodName,
Closure closure)
Adds a closure to be notified when the given method is called.
|
void |
add(T listener)
Adds a listener.
|
void |
addAll(Iterable<? extends T> listeners)
Adds the given listeners.
|
void |
dispatch(MethodInvocation event)
Broadcasts the given event to all listeners.
|
T |
getSource()
Returns the broadcaster.
|
Class<T> |
getType()
Returns the type of listener to which this class broadcasts.
|
void |
maybeAdd(Object listener)
Adds the given listener if it is an instance of the listener type.
|
void |
remove(Object listener)
Removes the given listener.
|
void |
removeAll(Iterable<?> listeners)
Removes the given listeners.
|
void |
stop()
Stops this dispatch.
|
protected ListenerBroadcast(Class<T> type, Transformer<StoppableDispatch<MethodInvocation>,StoppableDispatch<MethodInvocation>> transformer)
public T getSource()
public Class<T> getType()
public void add(T listener)
listener - The listener.public void addAll(Iterable<? extends T> listeners)
listeners - The listenerspublic void maybeAdd(Object listener)
listener - The listenerpublic void add(Dispatch<MethodInvocation> dispatch)
Dispatch to receive events from this broadcast.public void add(String methodName, Closure closure)
public void add(String methodName, Action<?> action)
public void remove(Object listener)
listener - The listener.public void removeAll(Iterable<?> listeners)
listeners - The listenerspublic void dispatch(MethodInvocation event)
dispatch in interface Dispatch<MethodInvocation>event - The eventpublic void stop()
StoppableDispatchstop in interface Stoppablestop in interface StoppableDispatch<MethodInvocation>Copyright © 2013. All rights reserved