org.objectweb.proactive.core.event
Class AbstractEventProducer

java.lang.Object
  |
  +--org.objectweb.proactive.core.event.AbstractEventProducer
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BodyEventProducerImpl, BodyMap, FutureEventProducerImpl, MessageEventProducerImpl, MigrationManagerImpl, RequestQueueImpl, RuntimeRegistrationEventProducerImpl

public abstract class AbstractEventProducer
extends java.lang.Object
implements java.io.Serializable

Provides support for adding, removing and notifying ProActiveListener. This class is a generic class that can be derived to get immediate support for sending ProActiveEvent to ProActiveListener.

A class producing ProActiveEvent and allowing ProActiveListener to register can have two strategies with those listeners in case of migration. If the listeners are local to the JVM, it doesn't make sense to serialize them with the migrating object. If the listener are part of the migrating subsystem, they should be serialized with the subsystem.

This class supports the two strategies and a boolean passed to the constructor indicates the strategy to apply with the registered listeners in case of migration.

In case of the listeners are not serialized with this object, meaning that there are not part of the subsystem in which is attached this object, we only keep weak references on them. The reference this event producer is keeping on one given listener won't prevent it to be garbage collected if no other strong reference are kept by another object.

This class is thread safe.

Since:
ProActive 0.9
Version:
1.0, 2001/10/23
Author:
ProActive Team
See Also:
Serialized Form

Nested Class Summary
protected static interface AbstractEventProducer.ListenerList
           A class implementing this interface provide a minimum set of methods to support the addition and removal of listener.
 
Field Summary
protected  AbstractEventProducer.ListenerList eventListeners
          the list of listeners.
protected static org.apache.log4j.Logger logger
           
protected  boolean shouldSerializeListeners
          flag specifying if the list of listeners should be serialized
 
Constructor Summary
AbstractEventProducer()
          Creates an AbstractEventProducer that does not serialize its registered listener.
AbstractEventProducer(boolean shouldSerializeListeners)
          Creates an AbstractEventProducer and specifies whether its registered listener should be serialized or not
 
Method Summary
protected  void addListener(ProActiveListener listener)
          Adds the given listener
protected  boolean hasListeners()
          Returns true is this event producer has at least one registered listener
protected  void notifyAllListeners(ProActiveEvent event)
          Notifies all registered listener with the event.
protected abstract  void notifyOneListener(ProActiveListener listener, ProActiveEvent event)
          Notifies one listener with the event.
protected  void removeListener(ProActiveListener listener)
          Removes the given listener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Logger logger

shouldSerializeListeners

protected boolean shouldSerializeListeners
flag specifying if the list of listeners should be serialized


eventListeners

protected transient AbstractEventProducer.ListenerList eventListeners
the list of listeners. There are serialized or not depending the value of the variable shouldSerializeListeners. If not serialized we use WeakReference to reference them.

Constructor Detail

AbstractEventProducer

public AbstractEventProducer()
Creates an AbstractEventProducer that does not serialize its registered listener.


AbstractEventProducer

public AbstractEventProducer(boolean shouldSerializeListeners)
Creates an AbstractEventProducer and specifies whether its registered listener should be serialized or not

Parameters:
shouldSerializeListeners - true if the registered listeners should be serialized, false else.
Method Detail

hasListeners

protected boolean hasListeners()
Returns true is this event producer has at least one registered listener

Returns:
true is this event producer has at least one registered listener

addListener

protected void addListener(ProActiveListener listener)
Adds the given listener


removeListener

protected void removeListener(ProActiveListener listener)
Removes the given listener


notifyAllListeners

protected void notifyAllListeners(ProActiveEvent event)
Notifies all registered listener with the event. This method call notifyOneListener on each registered listener.


notifyOneListener

protected abstract void notifyOneListener(ProActiveListener listener,
                                          ProActiveEvent event)
Notifies one listener with the event.



Copyright © April 2004 INRIA All Rights Reserved.