thread
Class BoundedBuffer

java.lang.Object
  extended by thread.BoundedBuffer

public class BoundedBuffer
extends java.lang.Object

A bounded buffer has some capacity to store objects. With the method put objects are placed into the buffer, and with the get objects are taken from the buffer. put blocks if there is no space to place a object into the buffer. get blocks if there are no objects in the buffer. The objects are put to and get from the buffer in FIFO order.

Author:
Akitoshi Yoshida, Heinz Kredel. see Queue
See Also:
see Channel see MemoryChannel see SyncChannel see Stack

Field Summary
private  java.lang.Object[] buffer
          The buffer storage of objects.
private  Semaphore empty
          A semaphore to indicate an empty buffer.
private  int front
          The position of the first filled cell.
private  Semaphore full
          A semaphore to indicate a full buffer.
private  java.lang.Object gt
           
private  java.lang.Object pt
           
private  int rear
          The position of the first empty cell.
private  int size
          The size of the buffer.
 
Constructor Summary
BoundedBuffer(int init)
          Constructs a BoundedBuffer with a desired size.
 
Method Summary
 boolean empty()
          Tests if the BoundedBuffer is empty.
 java.lang.Object get()
          Get an object from the BoundedBuffer
 void put(java.lang.Object v)
          Add an object to the BoundedBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

private java.lang.Object[] buffer
The buffer storage of objects.


size

private int size
The size of the buffer.


front

private int front
The position of the first filled cell.


rear

private int rear
The position of the first empty cell.


empty

private Semaphore empty
A semaphore to indicate an empty buffer.


full

private Semaphore full
A semaphore to indicate a full buffer.


pt

private java.lang.Object pt

gt

private java.lang.Object gt
Constructor Detail

BoundedBuffer

public BoundedBuffer(int init)
Constructs a BoundedBuffer with a desired size.

Parameters:
init - the size of the buffer.
Method Detail

empty

public boolean empty()
Tests if the BoundedBuffer is empty. If it is, gives back the value true.

Returns:
The boolean value of (whether the BoundedBuffer is empty or not).

put

public void put(java.lang.Object v)
         throws java.lang.InterruptedException
Add an object to the BoundedBuffer

Parameters:
v - object to be added to the buffer.
Throws:
java.lang.InterruptedException

get

public java.lang.Object get()
                     throws java.lang.InterruptedException
Get an object from the BoundedBuffer

Returns:
next object in buffer.
Throws:
java.lang.InterruptedException