Code a java class named QBuffer that implements
queues of fixed finite size (either as arrays or as linked lists). Your buffer class needs
to implement the following interface:
public interface FixedSizeQueue {
/** Checks the queue to see if it is empty
@param none
@return true if the queue is empty, false otherwise */
public boolean isEmpty();
/** Checks the queue to see if it is full
@param none
@return true if the queue if full, false otherwise */
public boolean isFull();
/** Adds an object to a (non-full) queue
@param x is the object to be added to the queue
@return void */
public void enqueue(Object x);
/** Removes next object from the (non-empty) queue
@param none
@return Object returned is the element removed from the queue */
public Object dequeue();
}
In your implementation of the QBuffer class, you will also need
a constructor with signature
QBuffer (int n)
that constructs a new empty queue with max capacity n and you will need to "synchronize" the enqueue and dequeue methods in your implementation of the buffer class, so they
won't try to modify buffer variables at the same time. Do this by
putting the keyword "synchonized" on the method signature line (right after the word "public").
Download Pipeline.class,
FixedSizeQueue.class,
Source.class,
Middleman.class,
Sink.class
and Person.class from this web site.
Compile your QBuffer class (creating your own QBuffer.class file).
Then test your program by running the command
java Pipeline
You can examine the source code for the Pipeline,
FixedSizeQueue,
Source,
Middleman,
Sink and
Person classes if you wish, but all you
should need are the downloaded class files and the class file created by compiling your own QBuffer class.
This application provides a different, and
perhaps more interesting, implementation of the project you
completed in Lab #5. This time, the source, middleman and sink
all run concurrently and rely on the queues provided by your
buffer class to help them pass information through the system.
|