|
|||||||||
| Home >> All >> org >> eclipse >> core >> internal >> [ runtime overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.eclipse.core.internal.runtime
Class ListenerList

java.lang.Objectorg.eclipse.core.internal.runtime.ListenerList
- public class ListenerList
- extends java.lang.Object
Internal class to maintain a list of listeners. This class is a thread safe list that is optimized for frequent reads and infrequent writes. Copy on write is used to ensure readers can access the list without synchronization overhead. Readers are given access to the underlying array data structure for reading, with the trust that they will not modify the underlying array.
N.B.: This class is similar to other ListenerLists available throughout Eclipse code base, except that it uses equality instead of identity to compare listeners. This does not compromise efficiency (since listeners addition/removal is not a frequent operation) and provides more flexibility to clients.
- Since:
- 3.0
| Field Summary | |
private static java.lang.Object[] |
EmptyArray
The empty array singleton instance. |
private java.lang.Object[] |
listeners
The list of listeners. |
| Constructor Summary | |
ListenerList()
Creates a listener list. |
|
| Method Summary | |
void |
add(java.lang.Object listener)
Adds the given listener to this list. |
java.lang.Object[] |
getListeners()
Returns an array containing all the registered listeners. |
boolean |
isEmpty()
Returns whether this listener list is empty. |
void |
remove(java.lang.Object listener)
Removes the given listener from this list. |
int |
size()
Returns the number of registered listeners. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
EmptyArray
private static final java.lang.Object[] EmptyArray
- The empty array singleton instance.
listeners
private volatile java.lang.Object[] listeners
- The list of listeners. Initially
nullbut initialized to an array of size capacity the first time a listener is added. Maintains invariant: listeners != null
| Constructor Detail |
ListenerList
public ListenerList()
- Creates a listener list.
| Method Detail |
add
public void add(java.lang.Object listener)
- Adds the given listener to this list. Has no effect if an equal
listener is already registered.
This method is synchronized to protect against multiple threads adding or removing listeners concurrently. This does not block concurrent readers.
getListeners
public java.lang.Object[] getListeners()
- Returns an array containing all the registered listeners.
The resulting array is unaffected by subsequent adds or removes.
If there are no listeners registered, the result is an empty array
singleton instance (no garbage is created).
Use this method when notifying listeners, so that any modifications
to the listener list during the notification will have no effect on
the notification itself.
Note: callers must not modify the returned array.
isEmpty
public boolean isEmpty()
- Returns whether this listener list is empty.
remove
public void remove(java.lang.Object listener)
- Removes the given listener from this list. Has no effect if an
identical listener was not already registered.
This method is synchronized to protect against multiple threads adding or removing listeners concurrently. This does not block concurrent readers.
size
public int size()
- Returns the number of registered listeners.
|
|||||||||
| Home >> All >> org >> eclipse >> core >> internal >> [ runtime overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.eclipse.core.internal.runtime.ListenerList