edu.rice.cs.drjava.model
Class EventNotifier<T>

java.lang.Object
  extended by edu.rice.cs.drjava.model.EventNotifier<T>
Direct Known Subclasses:
BrowserHistoryManager, ConcreteRegionManager, DebugEventNotifier, GlobalEventNotifier, InteractionsEventNotifier

public abstract class EventNotifier<T>
extends Object

Base class for all component-specific EventNotifiers. This class provides common methods to manage listeners of a specific type. T the type of the listener class to be managed.

Version:
$Id: EventNotifier.java 4691 2008-12-02 23:33:27Z dlsmith $

Field Summary
protected  LinkedList<T> _listeners
          All T Listeners that are listening to the model.
protected  ReaderWriterLock _lock
          Provides synchronization primitives for solving the readers/writers problem.
 
Constructor Summary
EventNotifier()
           
 
Method Summary
 void addListener(T listener)
          Adds a listener to the notifier.
 void removeAllListeners()
          Removes all listeners from this notifier.
 void removeListener(T listener)
          Removes a listener from the notifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_listeners

protected final LinkedList<T> _listeners
All T Listeners that are listening to the model. Accesses to this collection are protected by the ReaderWriterLock. The collection must be synchronized, since multiple readers could access it at once.


_lock

protected final ReaderWriterLock _lock
Provides synchronization primitives for solving the readers/writers problem. In EventNotifier, adding and removing listeners are considered write operations, and all notifications are considered read operations. Multiple reads can occur simultaneously, but only one write can occur at a time, and no reads can occur during a write.

Constructor Detail

EventNotifier

public EventNotifier()
Method Detail

addListener

public void addListener(T listener)
Adds a listener to the notifier.

Parameters:
listener - a listener that reacts on events

removeListener

public void removeListener(T listener)
Removes a listener from the notifier. If the thread already holds the lock, then the listener is removed later, but as soon as possible. Note: It is NOT guaranteed that the listener will not be executed again.

Parameters:
listener - a listener that reacts on events

removeAllListeners

public void removeAllListeners()
Removes all listeners from this notifier. If the thread already holds the lock, then the listener is removed later, but as soon as possible. Note: It is NOT guaranteed that the listener will not be executed again.