Boeing Simulation 3.1 API Specification

util
Class ConsumerQueue

java.lang.Object
  |
  +--util.ConsumerQueue

public class ConsumerQueue
extends Object

This class is to be used as a way for multiple Thread objects to request access to ReturnValues coming in across a ConsumerChannel. Each return value is associated with a unique ID number. Accessing threads may call a dequeue passing in the ID value which will cause that thread to block until a ReturnValue matching that ID is read in off the channel. Furthermore, non ReturnValue objects are enqueued in the ordinaryObject queue which can be accessed by the dequeue method that does not take in any parameters. This is also a blocking method but this does not mean that it blocks at the same time as the ReturnValue dequeue will.

Version:
$Revision: 1.15 $
Author:
Dave Jurgens
See Also:
MethodRequest, ReturnValue

Field Summary
protected  connect.ConsumerChannel channel
          The ConsumerChannel that this queue will read off of.
protected  Map channelStatus
          Contains information regarding whether the ConsumerChannel is still an active channel from which to be read.
protected  Map channelToThread
          The mapping of the channel to the WorkerThread currently executing it.
protected  util.Queue ordinaryObjects
          all non-ReturnValue objects are buffeded on this queue.
protected  Map returnValues
          ReturnValues are stored based on ID (as an Integer) in this map when the are read in.
private static long serialVersionUID
           
private  int waiting
          The number of Thread objects currently waiting to dequeue a ReturnValue.
 
Constructor Summary
protected ConsumerQueue()
           
  ConsumerQueue(connect.ConsumerChannel channel)
           
 
Method Summary
 Object dequeue()
          Dequeues an object from the ordinaryObjects queue (i.e.
 util.ReturnValue dequeue(int requestID)
          Dequeue a ReturnValue matching the specific requestID.
 int getWaitingThreadCount()
          Returns the number of threads currently waiting on a ReturnValue.
 boolean isActive()
          Returns true if this is actively reading in objects from the channel.
protected  boolean isChannelActive(connect.ConsumerChannel channel)
          Retuns the active status of the channel.
protected  void setActiveStatus(connect.ConsumerChannel channel, boolean status)
          Sets the active status of the channel, which determines whether the channel will continue reading in.
protected  util.WorkerThread startListeningThread(connect.ConsumerChannel channel)
          Starts a WorkerThread to read in values and then returns a reference to that thread.
 void stop()
          Stops the reading in of the current ConsumerStream.
protected  void stopChannel(connect.ConsumerChannel channel)
          Marks the channel as not active and then waits for the WorkerThread to notify it that the thread has finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

channel

protected connect.ConsumerChannel channel
The ConsumerChannel that this queue will read off of.


channelStatus

protected final Map channelStatus
Contains information regarding whether the ConsumerChannel is still an active channel from which to be read.


channelToThread

protected final Map channelToThread
The mapping of the channel to the WorkerThread currently executing it.


ordinaryObjects

protected final util.Queue ordinaryObjects
all non-ReturnValue objects are buffeded on this queue.


returnValues

protected final Map returnValues
ReturnValues are stored based on ID (as an Integer) in this map when the are read in.


waiting

private int waiting
The number of Thread objects currently waiting to dequeue a ReturnValue.

Constructor Detail

ConsumerQueue

public ConsumerQueue(connect.ConsumerChannel channel)

ConsumerQueue

protected ConsumerQueue()
Method Detail

dequeue

public util.ReturnValue dequeue(int requestID)
Dequeue a ReturnValue matching the specific requestID. This method blocks until that ID is read in. The method knows that the specified ID has been read in when it is notified by the internal thread reading in that a new ReturnValue has been read in. Then it checks the map to see if a ReturnValue has been mapped to the ID (i.e. signifying that the ReturnValue is of that key).

See Also:
ReturnValue.getReturnValueID(), MethodRequest.getReturnValueID()

dequeue

public Object dequeue()
Dequeues an object from the ordinaryObjects queue (i.e. a non-ReturnValue object)


getWaitingThreadCount

public int getWaitingThreadCount()
Returns the number of threads currently waiting on a ReturnValue.


isActive

public boolean isActive()
Returns true if this is actively reading in objects from the channel.


isChannelActive

protected boolean isChannelActive(connect.ConsumerChannel channel)
Retuns the active status of the channel.


startListeningThread

protected util.WorkerThread startListeningThread(connect.ConsumerChannel channel)
Starts a WorkerThread to read in values and then returns a reference to that thread. This method constantly reads in off the ConsumerChannel. If the object that it reads in is a ReturnValue, it put it in the Map using its ReturnID as the key. Then it will notify all waiting parties that a new value has been put in the mapping. If the object read in was not a ReturnValue, then it is put in the ordinaryObjects queue. Starting a channel automatically marks its status as being active.

See Also:
ordinaryObjects, returnValues

setActiveStatus

protected void setActiveStatus(connect.ConsumerChannel channel,
                               boolean status)
Sets the active status of the channel, which determines whether the channel will continue reading in. Setting the status does not have the invariant that upon returning, not additional object may be read.


stop

public void stop()
Stops the reading in of the current ConsumerStream. This method has the invariant that after returning, no additional objects will be read from the queue.


stopChannel

protected void stopChannel(connect.ConsumerChannel channel)
Marks the channel as not active and then waits for the WorkerThread to notify it that the thread has finished. This method will only return when no additional objects will be read in.


Boeing Simulation 3.1 API Specification

To submit a bug or feature email the author of that class. Funding for this research was provided by Boeing and DARPA.