org.echarts.util
Class FIFOAcceptor

java.lang.Object
  extended by org.echarts.util.FIFOAcceptor
All Implemented Interfaces:
java.io.Serializable

public final class FIFOAcceptor
extends java.lang.Object
implements java.io.Serializable

A bit of a hack, but a useful hack nonetheless. Rather than merging messages from different sources into a single FIFO (or FIFO subclass) and having a thread wait on the FIFO, this class permits a thread to simultaneously wait on more than one FIFO at a time, akin to the Unix socket select() procedure, or Ada's selective accept construct. An acceptor may maintain strong references to its FIFO's but a FIFO maintains only weak references to its acceptors. This way, when a program releases all references to an acceptor it will be garbage collected even if the program still maintains references to fifo's referenced by the acceptor. An acceptor can only be used with local instances of FIFO's (i.e. FIFOImpl's), not with remote references to FIFO's. A note concerning the use of locks: synchronization is very tricky in this code since it is possible for a fifo to be accessing this object's state while this object is accessing the same fifo's state. We permit acquiring the fifo's lock followed by the acceptor's lock but not vice versa in order to prevent deadlock. To read or write the enabledFIFOsList, one must hold the acceptor's lock.

See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
FIFOAcceptor()
           
 
Method Summary
 java.lang.Object accept()
          Wait for an element to become available in one of the monitored FIFOs.
 java.lang.Object acceptNoBlock()
          Check for an element to become available in one of the monitored FIFOs.
 void clearAcceptorAcceptor()
          Clears value of AcceptorAcceptor for this FIFOAcceptor.
 void setAcceptorAcceptor(AcceptorAcceptor acceptorAcceptor)
          Sets value of AcceptorAcceptor for this FIFOAcceptor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

FIFOAcceptor

public FIFOAcceptor()
Method Detail

acceptNoBlock

public final java.lang.Object acceptNoBlock()
Check for an element to become available in one of the monitored FIFOs. If an element is available, return it, otherwise returns null.


accept

public final java.lang.Object accept()
                              throws java.lang.InterruptedException
Wait for an element to become available in one of the monitored FIFOs. This method blocks until a non-null object is retrieved and returned from a FIFO. Note that it is possible for a thread to block indefinitely in the event that no FIFO's are associated with the acceptor.

Throws:
java.lang.InterruptedException

setAcceptorAcceptor

public final void setAcceptorAcceptor(AcceptorAcceptor acceptorAcceptor)
Sets value of AcceptorAcceptor for this FIFOAcceptor.


clearAcceptorAcceptor

public final void clearAcceptorAcceptor()
Clears value of AcceptorAcceptor for this FIFOAcceptor.