ilog.views.util.event
Class IlvAbstractEventListenerCollection

java.lang.Object
  extended by ilog.views.util.event.IlvAbstractEventListenerCollection
All Implemented Interfaces:
IlvEventListenerCollection, Serializable
Direct Known Subclasses:
IlvEventListenerList, IlvEventListenerSet

public abstract class IlvAbstractEventListenerCollection
extends Object
implements IlvEventListenerCollection, Serializable

IlvAbstractEventListenerCollection implements a thread-safe collection of event listeners. Concrete subclasses can choose a specific collection implementation based on the tradeoffs of event dispatch speed vs. the speed of adding and removing listeners. Several general issues should be weighed when choosing between using an IlvAbstractEventListenerCollection subclass or a multicaster to manage the event dispatch system for a class:

  1. A multicaster has increasingly poor performance when it comes to adding/removing large numbers of listeners. This is due to a full, non-indexed search through the multicaster tree to locate a specific listener.
  2. A class using an IlvAbstractEventListenerCollection will dispatch events through an iterative algorithm, while a multicaster uses a recursive algorithm. For large numbers of event listeners, a multicaster can cause a stack overflow exception to occur.

Here is an example that shows how a class can use an IlvAbstractEventListenerCollection concrete subclass for registering event listeners and dispatching events to them:


   public class MyClass {
       IlvEventListenerCollection xyzListeners = new IlvEventListenerSet();

       public void addXYZListener (XYZListener aListener) {
           xyzListeners.addListener(aListener);
       }

       public void removeXYZListener (XYZListener aListener) {
           xyzListeners.removeListener(aListener);
       }

       public void notifyXYZListeners () {
           XYZEvent event = new XYZEvent(this);
           for (Iterator i = xyzListeners.getListeners(); i.hasNext(); ) {
               XYZListener xyzListener = (XYZListener) i.next();
               xyzListener.xyzHappened(event);
           }
       }
   }
 

Since:
JViews 5.5
See Also:
Serialized Form

Constructor Summary
IlvAbstractEventListenerCollection()
          Creates a new IlvAbstractEventListenerCollection.
 
Method Summary
 void addListener(EventListener listener)
          Adds the specified listener to this collection.
protected abstract  Collection cloneListeners()
          Returns a copy of the collection of event listeners.
 boolean contains(EventListener listener)
          Returns whether this collection contains the specified listener.
 Iterator getListeners()
          Returns an iterator over the event listeners.
protected abstract  void initListeners()
          Initializes the collection of event listeners.
 void removeListener(EventListener listener)
          Removes the specified listener from this collection.
 void save(ObjectOutputStream s, String k)
          Serializes the collection of event listeners as a series of key-value pairs.
 int size()
          Returns the number of listeners in this collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvAbstractEventListenerCollection

public IlvAbstractEventListenerCollection()
Creates a new IlvAbstractEventListenerCollection.

Method Detail

initListeners

protected abstract void initListeners()
Initializes the collection of event listeners.


cloneListeners

protected abstract Collection cloneListeners()
Returns a copy of the collection of event listeners.


addListener

public void addListener(EventListener listener)
Adds the specified listener to this collection.

Specified by:
addListener in interface IlvEventListenerCollection
Parameters:
listener - The listener.

removeListener

public void removeListener(EventListener listener)
Removes the specified listener from this collection.

Specified by:
removeListener in interface IlvEventListenerCollection
Parameters:
listener - The listener.

getListeners

public Iterator getListeners()
Returns an iterator over the event listeners. It is safe to add or remove listeners from this collection during the course of the iteration.

Specified by:
getListeners in interface IlvEventListenerCollection

size

public int size()
Returns the number of listeners in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:
The number of listeners in this collection.
Since:
JViews 7.5

contains

public boolean contains(EventListener listener)
Returns whether this collection contains the specified listener.

Specified by:
contains in interface IlvEventListenerCollection
Parameters:
listener - The listener.
Returns:
true if this collection contains listener, otherwise false.

save

public void save(ObjectOutputStream s,
                 String k)
          throws IOException
Serializes the collection of event listeners as a series of key-value pairs.

Specified by:
save in interface IlvEventListenerCollection
Parameters:
s - The object output stream to write the event listeners.
k - A key string that is written in front of each listener to identify its type.
Throws:
IOException


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.