|
|||||||||
| Home >> All >> com >> virtuosotechnologies >> lib >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.virtuosotechnologies.lib.util
Class EventBroadcastHelper

java.lang.Objectcom.virtuosotechnologies.lib.util.EventBroadcastHelper
- public final class EventBroadcastHelper
- extends java.lang.Object
A helper class for broadcasting events.
This class is meant to be used internally by any class that needs to broadcast events. It provides the following facilities:
- It manages a set of listeners, providing helper methods for adding and removing listeners.
- It optionally references listeners via weak references, so they can be garbage collected and do not need to be removed explicitly.
- It provides methods for broadcasting an event to all listeners.
| Field Summary | |
private java.lang.Class |
listenerClass_
|
private java.util.List |
listeners_
|
private java.lang.String |
name_
|
private boolean |
verbose_
|
| Constructor Summary | |
EventBroadcastHelper(java.lang.Class listenerClass)
Constructor. |
|
| Method Summary | |
private boolean |
addListenerHelper(java.util.EventListener listener)
Helper for addListener methods. |
void |
addListenerStrong(java.util.EventListener listener)
Add a listener to the set of listeners. |
void |
addListenerWeak(java.util.EventListener listener)
Add a listener to the set of listeners. |
void |
fireAbortableEvent(java.lang.reflect.Method method,
java.util.EventObject event)
Fires an event. |
void |
fireAbortableEvent(java.lang.String methodName,
java.util.EventObject event)
Fires an event. |
void |
fireEvent(java.lang.reflect.Method method,
java.util.EventObject event)
Fires an event. |
void |
fireEvent(java.lang.String methodName,
java.util.EventObject event)
Fires an event. |
java.lang.Class |
getListenerClass()
Returns the listener class associated with this broadcaster. |
static java.lang.reflect.Method |
getListenerMethod(java.lang.Class listenerClass,
java.lang.String name,
java.lang.Class eventClass)
A helper for listener interfaces that want to provide static Method members for fast access to their methods. |
java.util.List |
getListenersAsList()
Returns a copy of the set of listeners as a list. |
java.util.Set |
getListenersAsSet()
Returns a copy of the set of listeners as a set. |
static java.lang.reflect.Method |
getUniqueListenerMethod(java.lang.Class listenerClass)
A helper for listener interfaces that want to provide static Method members for fast access to their methods. |
boolean |
isVerbose()
Get verbose mode |
void |
removeAllListeners()
Removes all listeners from the set of listeners. |
void |
removeListener(java.util.EventListener listener)
Removes a listener from the set of listeners. |
void |
setName(java.lang.String name)
Set identifying name that will be returned from toString |
void |
setVerbose(boolean verbose)
Set verbose mode |
java.lang.String |
toString()
toString override |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
listenerClass_
private java.lang.Class listenerClass_
listeners_
private java.util.List listeners_
verbose_
private boolean verbose_
name_
private java.lang.String name_
| Constructor Detail |
EventBroadcastHelper
public EventBroadcastHelper(java.lang.Class listenerClass)
- Constructor.
| Method Detail |
getListenerMethod
public static java.lang.reflect.Method getListenerMethod(java.lang.Class listenerClass, java.lang.String name, java.lang.Class eventClass)
- A helper for listener interfaces that want to provide static
Method members for fast access to their methods. This allows a
listener interface to initialize a static member in a single line
so a static initializer inner class is not needed.
getUniqueListenerMethod
public static java.lang.reflect.Method getUniqueListenerMethod(java.lang.Class listenerClass)
- A helper for listener interfaces that want to provide static
Method members for fast access to their methods. This version
assumes that the listener class declares exactly one method,
and it returns that method.
isVerbose
public boolean isVerbose()
- Get verbose mode
setVerbose
public void setVerbose(boolean verbose)
- Set verbose mode
setName
public void setName(java.lang.String name)
- Set identifying name that will be returned from toString
toString
public java.lang.String toString()
- toString override
getListenerClass
public java.lang.Class getListenerClass()
- Returns the listener class associated with this broadcaster.
addListenerHelper
private boolean addListenerHelper(java.util.EventListener listener)
- Helper for addListener methods. Checks to make sure the listener
is valid, and isn't already added. Returns true if it is okay to
add the listener.
addListenerWeak
public void addListenerWeak(java.util.EventListener listener)
- Add a listener to the set of listeners. Has no effect if the
listener is already in the set. References the new listener
through a weak reference, which means the reference will go away
when the listener gets collected. This has two implications:
- If the listener is going to get collected otherwise, you don't need to explicitly remove it from the listener list.
-
You shouldn't add a listener weakly without storing a reference
to it, or it might get collected prematurely. For example,
the following is a no-no:
addListenerWeak(new MyListener());
addListenerStrong
public void addListenerStrong(java.util.EventListener listener)
- Add a listener to the set of listeners. Has no effect if the
listener is already in the set. References the new listener
through a strong reference, which means the reference will not
be collected until the listener is explicitly removed.
removeListener
public void removeListener(java.util.EventListener listener)
- Removes a listener from the set of listeners. Has no effect if the
listener is not in the list.
removeAllListeners
public void removeAllListeners()
- Removes all listeners from the set of listeners.
getListenersAsSet
public java.util.Set getListenersAsSet()
- Returns a copy of the set of listeners as a set. The copy is
not backed by the original, so modifications made to the returned
set do not affect the actual set of listeners.
getListenersAsList
public java.util.List getListenersAsList()
- Returns a copy of the set of listeners as a list. The copy is
not backed by the original, so modifications made to the returned
list do not affect the actual set of listeners.
fireEvent
public void fireEvent(java.lang.String methodName, java.util.EventObject event)
- Fires an event. This version takes the name of the method to invoke
and an event object to send.
This version of fireEvent may be a little slow because it looks up the method object from the name and parameters via reflection. If an event is to be fired rapidly, you may want to create and cache the method object yourself, and call the other version of fireEvent() that takes a method object.
fireEvent
public void fireEvent(java.lang.reflect.Method method, java.util.EventObject event)
- Fires an event. This version takes a method object to invoke
and an event object to send.
fireAbortableEvent
public void fireAbortableEvent(java.lang.String methodName, java.util.EventObject event) throws EventAbortedException
- Fires an event. This version takes the name of the method to invoke
and an event object to send.
This version of fireEvent may be a little slow because it looks up the method object from the name and parameters via reflection. If an event is to be fired rapidly, you may want to create and cache the method object yourself, and call the other version of fireEvent() that takes a method object.
fireAbortableEvent
public void fireAbortableEvent(java.lang.reflect.Method method, java.util.EventObject event) throws EventAbortedException
- Fires an event. This version takes a method object to invoke
and an event object to send.
|
|||||||||
| Home >> All >> com >> virtuosotechnologies >> lib >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.virtuosotechnologies.lib.util.EventBroadcastHelper