javax.realtime
Class WaitFreeReadQueue

java.lang.Object
  extended byjavax.realtime.WaitFreeReadQueue

public class WaitFreeReadQueue
extends Object

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

Since:
0.3.8
Author:
Morgan Deters

Constructor Summary
WaitFreeReadQueue(int maximum, boolean notify)
           
WaitFreeReadQueue(int maximum, MemoryArea memory, boolean notify)
           
WaitFreeReadQueue(Thread writer, Thread reader, int maximum, MemoryArea memory)
          Constructs a new WaitFreeReadQueue.
WaitFreeReadQueue(Thread writer, Thread reader, int maximum, MemoryArea memory, boolean notify)
          Constructs a new WaitFreeReadQueue.
 
Method Summary
 void clear()
          Empties the queue.
 boolean isEmpty()
          Checks if the queue is empty.
 boolean isFull()
          Checks if the queue is full.
 Object read()
          An unsynchronized and nonblocking read operation.
 int size()
          Returns the number of elements in the queue.
 void waitForData()
          If the queue is empty, this method doesn't return until the writing thread inserts an element.
 boolean write(Object object)
          A synchronized and blocking write operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaitFreeReadQueue

public WaitFreeReadQueue(Thread writer,
                         Thread reader,
                         int maximum,
                         MemoryArea memory,
                         boolean notify)
Constructs a new WaitFreeReadQueue.

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
notify - whether to notify the reader when data is added [unclear in spec, so unimplemented in jRate]

WaitFreeReadQueue

public WaitFreeReadQueue(Thread writer,
                         Thread reader,
                         int maximum,
                         MemoryArea memory)
Constructs a new WaitFreeReadQueue.

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

WaitFreeReadQueue

public WaitFreeReadQueue(int maximum,
                         MemoryArea memory,
                         boolean notify)

WaitFreeReadQueue

public WaitFreeReadQueue(int maximum,
                         boolean notify)
Method Detail

clear

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


isEmpty

public boolean isEmpty()
Checks if the queue is empty. This method is unsynchronized; if it could be called at the same time as another unsynchronized read operation on this object, the callers need to synchronize.

Returns:
true if the queue is empty, false otherwise

isFull

public boolean isFull()
Checks if the queue is full. This method is unsynchronized; if it could be called at the same time as another unsynchronized read operation on this object, the callers need to synchronize.

Returns:
true if the queue is full, false otherwise

size

public int size()
Returns the number of elements in the queue. This method is unsynchronized; if it could be called at the same time as another unsynchronized read operation on this object, the callers need to synchronize.

Returns:
the number of elements in the queue

read

public Object read()
An unsynchronized and nonblocking read operation. This method is unsynchronized; if it could be called at the same time as another unsynchronized read operation on this object, the callers need to synchronize.

Returns:
the object removed from the queue, or null if the queue is empty

waitForData

public void waitForData()
If the queue is empty, this method doesn't return until the writing thread inserts an element. Otherwise, this method returns immediately.


write

public boolean write(Object object)
              throws MemoryScopeException
A synchronized and blocking write operation.

Parameters:
object - the object to write to the queue
Returns:
true
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.