org.echarts.util
Class AcceptorAcceptor

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

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

Permits threads to wait on more than one FIFOAcceptor at a time. Acceptors have different relative priorities such that if a message exists in more than one FIFOAcceptor, then the FIFOAcceptor with higher priority will be accessed. A given FIFOAcceptor may be associated with at most one AcceptorAcceptor at a time.

See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
AcceptorAcceptor(int size)
          Create an AcceptorAcceptor of given size > 0.
 
Method Summary
 java.lang.Object accept()
          Wait for an element to become available in one of the monitored FIFOAcceptors.
 java.lang.Object acceptNoBlock()
          Check for an element to become available in one of the monitored FIFOAcceptors.
 void addAcceptor(FIFOAcceptor acceptor, int priority)
          Adds a FIFOAcceptor to set of FIFOAcceptors associated with this AcceptorAcceptor.
 void clear()
          Removes all FIFOAcceptors from this AcceptorAcceptor, and clears AcceptorAcceptor's list of outstanding FIFOAcceptors.
 void removeAcceptor(FIFOAcceptor acceptor, int priority)
           
 void update()
          Called by a FIFOAcceptor when the FIFOAcceptor has an available element.
 
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

AcceptorAcceptor

public AcceptorAcceptor(int size)
Create an AcceptorAcceptor of given size > 0. Priority range for an AcceptorAcceptor of size n is 0 < pri < n-1.

Method Detail

acceptNoBlock

public final java.lang.Object acceptNoBlock()
Check for an element to become available in one of the monitored FIFOAcceptors. If an element is available, remove it and execute the acceptor action associated with the FIFO. Returns the object if an acceptor action was executed, 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 FIFOAcceptors. Once the element is removed from the FIFO, execute the acceptor action associated with the FIFO. While at least one FIFO is registered with this acceptor, this method blocks until an action is executed and returns the object removed from the FIFO, otherwise this method returns null.

Throws:
java.lang.InterruptedException

addAcceptor

public final void addAcceptor(FIFOAcceptor acceptor,
                              int priority)
Adds a FIFOAcceptor to set of FIFOAcceptors associated with this AcceptorAcceptor. Lower priority value means higher relative priority. Priority range for an AcceptorAcceptor of size n is 0 < pri < n-1.


removeAcceptor

public final void removeAcceptor(FIFOAcceptor acceptor,
                                 int priority)

update

public final void update()
Called by a FIFOAcceptor when the FIFOAcceptor has an available element. Wake up next thread waiting on this AcceptorAcceptor for an element to arrive, if such a thread exists.


clear

public final void clear()
Removes all FIFOAcceptors from this AcceptorAcceptor, and clears AcceptorAcceptor's list of outstanding FIFOAcceptors. Once this method has been called it is possible to reuse this AcceptorAcceptor.