nl.tudelft.simulation.event
Class EventProducer

java.lang.Object
  extended by nl.tudelft.simulation.event.EventProducer
All Implemented Interfaces:
Serializable, EventProducerInterface
Direct Known Subclasses:
EventIterator, EventProducingCollection, EventProducingList, EventProducingMap, EventProducingSet, RemoteEventProducer

public abstract class EventProducer
extends Object
implements EventProducerInterface, Serializable

The EventProducer forms the reference implementation of the EventProducerInterface. Objects extending this class are provided all the functionalities for registration and event firering.

(c) copyright 2002-2005 Delft University of Technology , the Netherlands.

See for project information www.simulation.tudelft.nl/event
License of use: Lesser General Public License (LGPL) , no warranty

Since:
1.2
Version:
$Revision: 1.1 $ $Date: 2007/01/06 13:24:35 $
Author:
Peter Jacobs
See Also:
Serialized Form

Field Summary
protected  Map listeners
          listeners is the collection of interested listeners
 
Fields inherited from interface nl.tudelft.simulation.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
 
Constructor Summary
EventProducer()
          constructs a new EventProducer and checks for double values in events
 
Method Summary
 boolean addListener(EventListenerInterface listener, EventType eventType)
          adds the listener as weak reference to the listener.
 boolean addListener(EventListenerInterface listener, EventType eventType, boolean weak)
          adds a listener to the BEGINNING of a queue of listeners.
 boolean addListener(EventListenerInterface listener, EventType eventType, short position)
          adds the listener as weak reference to the listener.
 boolean addListener(EventListenerInterface listener, EventType eventType, short position, boolean weak)
          adds a listener to the specified position of a queue of listeners.
protected  EventInterface fireEvent(EventInterface event)
          fires an event to subscribed listeners.
protected  EventInterface fireEvent(EventListenerInterface listener, EventInterface event)
          fires the event to the listener.
protected  boolean fireEvent(EventType eventType, boolean value)
          fires a boolean value to subscribed listeners subscribed to eventType.
protected  boolean fireEvent(EventType eventType, boolean value, double time)
          fires a boolean value to subscribed listeners subscribed to eventType.
protected  byte fireEvent(EventType eventType, byte value)
          fires a byte value to subscribed listeners subscribed to eventType.
protected  byte fireEvent(EventType eventType, byte value, double time)
          fires a byte value to subscribed listeners subscribed to eventType.
protected  double fireEvent(EventType eventType, double value)
          fires a double value to subscribed listeners subscribed to eventType.
protected  double fireEvent(EventType eventType, double value, double time)
          fires a double value to subscribed listeners subscribed to eventType.
protected  int fireEvent(EventType eventType, int value)
          fires an integer value to subscribed listeners subscribed to eventType.
protected  int fireEvent(EventType eventType, int value, double time)
          fires an integer value to subscribed listeners subscribed to eventType.
protected  long fireEvent(EventType eventType, long value)
          fires a long value to subscribed listeners subscribed to eventType.
protected  long fireEvent(EventType eventType, long value, double time)
          fires a long value to subscribed listeners subscribed to eventType.
protected  Object fireEvent(EventType eventType, Object value)
          fires a value to subscribed listeners subscribed to eventType.
protected  Object fireEvent(EventType eventType, Object value, double time)
          fires a Serializable value to subscribed listeners subscribed to eventType.
protected  short fireEvent(EventType eventType, short value)
          fires a short value to subscribed listeners subscribed to eventType.
protected  short fireEvent(EventType eventType, short value, double time)
          fires a short value to subscribed listeners subscribed to eventType.
 EventType[] getEventTypes()
          returns all the eventTypes for which a listener can subscribe.
protected  int removeAllListeners()
          removes all the listeners from the producer.
protected  int removeAllListeners(Class ofClass)
          removes all the listeners of a class.
 boolean removeListener(EventListenerInterface listener, EventType eventType)
          removes the subscription of a listener for a specific event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected Map listeners
listeners is the collection of interested listeners

Constructor Detail

EventProducer

public EventProducer()
constructs a new EventProducer and checks for double values in events

Method Detail

addListener

public boolean addListener(EventListenerInterface listener,
                           EventType eventType)
adds the listener as weak reference to the listener.

Specified by:
addListener in interface EventProducerInterface
Parameters:
listener - the listener which is interested at events of eventtype.
eventType - the events of interest.
Returns:
the success of adding the listener. If a listener was already added false is returned.
See Also:
#addListener(EventListenerInterface, EventType)

addListener

public boolean addListener(EventListenerInterface listener,
                           EventType eventType,
                           boolean weak)
Description copied from interface: EventProducerInterface
adds a listener to the BEGINNING of a queue of listeners.

Specified by:
addListener in interface EventProducerInterface
Parameters:
listener - the listener which is interested at events of eventtype.
eventType - the events of interest.
weak - whether or not the listener is added as weak reference.
Returns:
the success of adding the listener. If a listener was already added false is returned.
See Also:
#addListener(nl.tudelft.simulation.event.EventListenerInterface, nl.tudelft.simulation.event.EventType, boolean)

addListener

public boolean addListener(EventListenerInterface listener,
                           EventType eventType,
                           short position)
adds the listener as weak reference to the listener.

Specified by:
addListener in interface EventProducerInterface
Parameters:
listener - the listener which is interested at events of eventtype.
eventType - the events of interest.
position - the position of the listener in the queue.
Returns:
the success of adding the listener. If a listener was already added, or an illegal position is provided false is returned.
See Also:
#addListener(nl.tudelft.simulation.event.EventListenerInterface, nl.tudelft.simulation.event.EventType, short)

addListener

public boolean addListener(EventListenerInterface listener,
                           EventType eventType,
                           short position,
                           boolean weak)
Description copied from interface: EventProducerInterface
adds a listener to the specified position of a queue of listeners.

Specified by:
addListener in interface EventProducerInterface
Parameters:
listener - which is interested at certain events,
eventType - the events of interest.
position - the position of the listener in the queue
weak - whether the reference should be weak or strong.
Returns:
the success of adding the listener. If a listener was already added or an illegal position is provided false is returned.
See Also:
#addListener(nl.tudelft.simulation.event.EventListenerInterface, nl.tudelft.simulation.event.EventType, short, boolean)

fireEvent

protected EventInterface fireEvent(EventListenerInterface listener,
                                   EventInterface event)
                            throws RemoteException
fires the event to the listener. This method is a hook method. The default implementation simply invokes the notify on the listener. In specific cases (filtering, storing, queuing, this method can be overwritten.

Parameters:
listener - the listener for this event
event - the event to fire
Returns:
the event
Throws:
RemoteException - on network failure.

fireEvent

protected EventInterface fireEvent(EventInterface event)
fires an event to subscribed listeners.

Parameters:
event - the event.
Returns:
the event.

fireEvent

protected byte fireEvent(EventType eventType,
                         byte value)
fires a byte value to subscribed listeners subscribed to eventType.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
Returns:
the byte value.

fireEvent

protected boolean fireEvent(EventType eventType,
                            boolean value)
fires a boolean value to subscribed listeners subscribed to eventType.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
Returns:
the byte value.

fireEvent

protected byte fireEvent(EventType eventType,
                         byte value,
                         double time)
fires a byte value to subscribed listeners subscribed to eventType. A timed event is fired.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
time - a timestamp for the event.
Returns:
the byte value.

fireEvent

protected boolean fireEvent(EventType eventType,
                            boolean value,
                            double time)
fires a boolean value to subscribed listeners subscribed to eventType. A timed event is fired.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
time - a timestamp for the event.
Returns:
the byte value.

fireEvent

protected double fireEvent(EventType eventType,
                           double value)
fires a double value to subscribed listeners subscribed to eventType.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
Returns:
the double value.

fireEvent

protected double fireEvent(EventType eventType,
                           double value,
                           double time)
fires a double value to subscribed listeners subscribed to eventType. A timed event is fired.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
time - a timestamp for the event.
Returns:
the double value.

fireEvent

protected int fireEvent(EventType eventType,
                        int value)
fires an integer value to subscribed listeners subscribed to eventType.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
Returns:
the integer value.

fireEvent

protected int fireEvent(EventType eventType,
                        int value,
                        double time)
fires an integer value to subscribed listeners subscribed to eventType. A timed event is fired.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
time - a timestamp for the event.
Returns:
the integer value.

fireEvent

protected long fireEvent(EventType eventType,
                         long value)
fires a long value to subscribed listeners subscribed to eventType.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
Returns:
the long value.

fireEvent

protected long fireEvent(EventType eventType,
                         long value,
                         double time)
fires a long value to subscribed listeners subscribed to eventType. A timed event is fired.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
time - a timestamp for the event.
Returns:
the long value.

fireEvent

protected Object fireEvent(EventType eventType,
                           Object value)
fires a value to subscribed listeners subscribed to eventType.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
Returns:
the Serializable value.

fireEvent

protected Object fireEvent(EventType eventType,
                           Object value,
                           double time)
fires a Serializable value to subscribed listeners subscribed to eventType. A timed event is fired.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
time - a timestamp for the event.
Returns:
the Serializable value.

fireEvent

protected short fireEvent(EventType eventType,
                          short value)
fires a short value to subscribed listeners subscribed to eventType.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
Returns:
the short value.

fireEvent

protected short fireEvent(EventType eventType,
                          short value,
                          double time)
fires a short value to subscribed listeners subscribed to eventType. A timed event is fired.

Parameters:
eventType - the eventType of the event.
value - the value of the event.
time - a timestamp for the event.
Returns:
the short value.

getEventTypes

public EventType[] getEventTypes()
Description copied from interface: EventProducerInterface
returns all the eventTypes for which a listener can subscribe.

Specified by:
getEventTypes in interface EventProducerInterface
Returns:
EventType[] returns the eventTypes for which listeners can subscribe.
See Also:
EventProducerInterface.getEventTypes()

removeAllListeners

protected int removeAllListeners()
removes all the listeners from the producer.

Returns:
int the amount of removed listeners.

removeAllListeners

protected int removeAllListeners(Class ofClass)
removes all the listeners of a class.

Parameters:
ofClass - the class or superclass.
Returns:
the number of listeners which were removed.

removeListener

public boolean removeListener(EventListenerInterface listener,
                              EventType eventType)
Description copied from interface: EventProducerInterface
removes the subscription of a listener for a specific event.

Specified by:
removeListener in interface EventProducerInterface
Parameters:
listener - which is no longer interested.
eventType - the event which is of no interest any more.
Returns:
the success of removing the listener. If a listener was not subscribed false is returned.
See Also:
#removeListener(EventListenerInterface, EventType)


Copyright © 2002-2011 Delft University of Technology, the Netherlands. All Rights Reserved.