Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 


Eclipse Platform
Release 3.5

org.eclipse.core.runtime
Class ListenerList


java.lang.Object
  extended by 
org.eclipse.core.runtime.ListenerList
Direct Known Subclasses:
ListenerList

public class ListenerList
extends Object

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.

A listener list handles the same listener being added multiple times, and tolerates removal of listeners that are the same as other listeners in the list. For this purpose, listeners can be compared with each other using either equality or identity, as specified in the list constructor.

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.

Since:
org.eclipse.equinox.common 3.2

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

EQUALITY

public static final int EQUALITY
Mode constant (value 0) indicating that listeners should be considered the same if they are equal.

See Also:
Constant Field Values

IDENTITY

public static final int IDENTITY
Mode constant (value 1) indicating that listeners should be considered the same if they are identical.

See Also:
Constant Field Values
Constructor Detail

ListenerList

public ListenerList()
Creates a listener list in which listeners are compared using equality.


ListenerList

public ListenerList(int mode)
Creates a listener list using the provided comparison mode.

Parameters:
mode - The mode used to determine if listeners are the same.
Method Detail

add

public void add(
Object listener)
Adds a listener to this list. This method has no effect if the same listener is already registered.

Parameters:
listener - the non-null listener to add

getListeners

public 
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. 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 of this method must not modify the returned array.

Returns:
the list of registered listeners

isEmpty

public boolean isEmpty()
Returns whether this listener list is empty.

Returns:
true if there are no registered listeners, and false otherwise

remove

public void remove(
Object listener)
Removes a listener from this list. Has no effect if the same listener was not already registered.

Parameters:
listener - the non-null listener to remove

size

public int size()
Returns the number of registered listeners.

Returns:
the number of registered listeners

clear

public void clear()
Removes all listeners from this list.


Eclipse Platform
Release 3.5

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire