|
Eclipse Platform Release 3.3 |
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.core.runtime.ListenerList
This class is a thread safe list that is designed for storing lists of listeners. The implementation is optimized for minimal memory footprint, frequent reads and infrequent writes. Modification of the list is synchronized and relatively expensive, while accessing the listeners is very fast. Readers are given access to the underlying array data structure for reading, with the trust that they will not modify the underlying array.
Use the getListeners
method when notifying listeners. The recommended
code sequence for notifying all registered listeners of say,
FooListener.eventHappened
, is:
Object[] listeners = myListenerList.getListeners(); for (int i = 0; i < listeners.length; ++i) { ((FooListener) listeners[i]).eventHappened(event); }
This class can be used without OSGi running.
Field Summary | |
---|---|
static int |
EQUALITY
Mode constant (value 0) indicating that listeners should be considered the same if they are equal. |
static int |
IDENTITY
Mode constant (value 1) indicating that listeners should be considered the same if they are identical. |
Constructor Summary | |
---|---|
ListenerList()
Creates a listener list in which listeners are compared using equality. |
|
ListenerList(int mode)
Creates a listener list using the provided comparison mode. |
Method Summary | |
---|---|
void |
add(Object listener)
Adds a listener to this list. |
void |
clear()
Removes all listeners from this list. |
Object[] |
getListeners()
Returns an array containing all the registered listeners. |
boolean |
isEmpty()
Returns whether this listener list is empty. |
void |
remove(Object listener)
Removes a 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 |
public static final int EQUALITY
public static final int IDENTITY
Constructor Detail |
public ListenerList()
public ListenerList(int mode)
mode
- The mode used to determine if listeners are the same.Method Detail |
public void add(Object listener)
listener
- the non-null
listener to addpublic Object[] getListeners()
Note: Callers of this method must not modify the returned array.
public boolean isEmpty()
true
if there are no registered listeners, and
false
otherwisepublic void remove(Object listener)
listener
- the non-null
listener to removepublic int size()
public void clear()
|
Eclipse Platform Release 3.3 |
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp. and others 2000, 2007. All rights reserved.