edu.nps.moves.net
Interface BehaviorProducerIF

All Known Implementing Classes:
BehaviorProducerUDP

public interface BehaviorProducerIF

The BehaviorProducer interface describes a class that listens in its own thread for PDUs, then notifies any listeners when they arrive.

This implements a listener pattern. Those interested in hearing from the BehaviorProducerIF register with the object. When the BehaviorProducerIF gets (or produces) a PDU, it notifies all listeners. Note that there is no attempt to limit which listeners/consumers receive the PDU.

Version:
$Id:$
Author:
DMcG

Method Summary
 void addListener(BehaviorConsumerIF consumer)
          Add a listener that will be notified when a PDU is ready.
 void removeListener(BehaviorConsumerIF consumer)
          Remove a listener/consumer of PDUs from the notification list.
 void setUseCopies(boolean shouldCreateCopy)
          This is a performance option.
 

Method Detail

addListener

void addListener(BehaviorConsumerIF consumer)
Add a listener that will be notified when a PDU is ready.

Parameters:
consumer - the object that will be notified of the PDU

removeListener

void removeListener(BehaviorConsumerIF consumer)
Remove a listener/consumer of PDUs from the notification list.

Parameters:
consumer - to be removed from the notification list

setUseCopies

void setUseCopies(boolean shouldCreateCopy)
This is a performance option. When a PDU arrives we want to distribute it to all listeners. If we use a single copy of the object distributed to all listeners this may cause problems if one listener modifies the object and undermines the expectations of another listener. to avoid this we can create a new copy of the PDU and hand off a new, unique copy of the object to each listener. But this may cause some performance problems, since it takes a while to allocate a new object.

The default behavior should be to distribute a new, unqiue copy to each listener. this allows the user to override this behavior for better performance.

Parameters:
shouldCreateCopy - true to create a new copy for each listener, false for a shared copy for each listener