Class BufferQueue

java.lang.Object
  |
  +--BufferQueue

public class BufferQueue
extends java.lang.Object

An object of class BufferQueue is a named queue of Buffers used by a BoundedBufferProcess. The name is established when the BufferQueue is constructed. It can be retrieved by calling toString(). When a BufferQueue is constructed, its capacity is established. It can be filled immediately afterward by calling fill(). If the BufferQueue is not full then a Buffer can be added by calling putBuffer(). Buffers can be retrieved by calling getBuffer(). This method does not return until there is an available Buffer in the BufferQueue.


Field Summary
protected  Buffer[] buffers
          buffers is the array of Buffers for this BufferQueue.
protected  int capacity
          capacity is the maximum number of Buffers that this BufferQueue can hold.
protected  int count
          count is the number of Buffers in this BufferQueue.
protected  java.lang.String name
          name is the name for this BufferQueue.
protected  int nextGet
          nextGet is the index where the next available Buffer can be found in this BufferQueue.
 
Constructor Summary
BufferQueue(java.lang.String nm, int n)
          new BufferQueue(nm, n) returns a new BufferQueue with a capacity for n Buffer objects.
 
Method Summary
 void fill()
          bq.fill() fills bq with Buffers whose names are the decimal representations of integers from 0 up to one less than the capacity of bq.
 Buffer getBuffer()
          bq.getBuffer() returns the next available Buffer from bq.
 boolean isFull()
          bq.isFull() returns true if there is no more room for Buffers in bq.
 void putBuffer(Buffer buff)
          bq.putBuffer(buff) adds buff to bq.
 java.lang.String toString()
          bq.toString() returns the name of bq.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buffers

protected Buffer[] buffers
buffers is the array of Buffers for this BufferQueue.

capacity

protected int capacity
capacity is the maximum number of Buffers that this BufferQueue can hold.

count

protected int count
count is the number of Buffers in this BufferQueue.

nextGet

protected int nextGet
nextGet is the index where the next available Buffer can be found in this BufferQueue.

name

protected java.lang.String name
name is the name for this BufferQueue.
Constructor Detail

BufferQueue

public BufferQueue(java.lang.String nm,
                   int n)
new BufferQueue(nm, n) returns a new BufferQueue with a capacity for n Buffer objects. The name of the new BufferQueue is formed by concatenating its class name with nm.
Method Detail

fill

public void fill()
bq.fill() fills bq with Buffers whose names are the decimal representations of integers from 0 up to one less than the capacity of bq.

isFull

public boolean isFull()
bq.isFull() returns true if there is no more room for Buffers in bq.

getBuffer

public Buffer getBuffer()
bq.getBuffer() returns the next available Buffer from bq. If bq is empty then getBuffer() does not return until there is an available Buffer.

putBuffer

public void putBuffer(Buffer buff)
bq.putBuffer(buff) adds buff to bq. Preconditions: bq.isFull() is false.

toString

public java.lang.String toString()
bq.toString() returns the name of bq.
Overrides:
toString in class java.lang.Object