javax.realtime
Class WaitFreeWriteQueue

java.lang.Object
  extended byjavax.realtime.WaitFreeWriteQueue

public class WaitFreeWriteQueue
extends Object

A queue that provides unsynchronized nonblocking write() and synchronized blocking read().

Since:
0.3.8
Author:
Morgan Deters

Constructor Summary
WaitFreeWriteQueue(Thread writer, Thread reader, int maximum, MemoryArea memory)
          Constructs a new WaitFreeWriteQueue.
 
Method Summary
 void clear()
          Empties the queue.
 boolean force(Object object)
          Replace the last object with this object.
 boolean isEmpty()
          Checks if the queue is empty.
 boolean isFull()
          Checks if the queue is full.
 Object read()
          A synchronized and blocking read operation.
 int size()
          Returns the number of elements in the queue.
 boolean write(Object object)
          An unsynchronized and nonblocking write operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaitFreeWriteQueue

public WaitFreeWriteQueue(Thread writer,
                          Thread reader,
                          int maximum,
                          MemoryArea memory)
                   throws IllegalArgumentException,
                          InstantiationException,
                          ClassNotFoundException,
                          IllegalAccessException
Constructs a new WaitFreeWriteQueue.

Parameters:
writer - the writing thread
reader - the reading thread
maximum - the capacity of the queue
memory - the MemoryArea in which to allocate the queue's buffer; if null, then the current memory area is used
Method Detail

clear

public void clear()
Empties the queue. This method is unsynchronized; if it could be called at the same time as a read() operation, the callers need to synchronize.


isEmpty

public boolean isEmpty()
Checks if the queue is empty.

Returns:
true if the queue is empty, false otherwise

isFull

public boolean isFull()
Checks if the queue is full.

Returns:
true if the queue is full, false otherwise

read

public Object read()
A synchronized and blocking read operation.

Returns:
the object removed from the queue

size

public int size()
Returns the number of elements in the queue.

Returns:
the number of elements in the queue

force

public boolean force(Object object)
              throws MemoryScopeException
Replace the last object with this object. Returns false if the reader removed the other object as this operation was updating it.

Parameters:
object - the object to write to the queue
Returns:
true upon success, false otherwise
Throws:
MemoryScopeException - if the object is in an incompatible memory area

write

public boolean write(Object object)
              throws MemoryScopeException
An unsynchronized and nonblocking write operation.

Parameters:
object - the object to write to the queue
Returns:
true upon success, false otherwise
Throws:
MemoryScopeException - if the object is in an incompatible memory area


jRate is developed and maintained by the jRate project development team.
Copyright (c) 2001-2006 Angelo Corsaro and Morgan Deters.