javax.realtime
Class WaitFreeWriteQueue

java.lang.Object
  |
  +--javax.realtime.WaitFreeWriteQueue

public class WaitFreeWriteQueue
extends java.lang.Object

The wait-free queue classes facilitate communication and synchronization between instances of RealtimeThread and Thread. The problem is that synchronized access objects shared between real-time threads and threads might cause the real-time threads to incur delays due to execution of the garbage collector.

The write method of this class does not block on an imagined queue-full condition variable. If the write() method is called on a full queue false is returned. If two real-time threads intend to read from this queue they must provide their own synchronization.

The read() method of this queue is synchronized and may be called by more than one writer and will block on queue empty.


Constructor Summary
WaitFreeWriteQueue(java.lang.Thread writer, java.lang.Thread reader, int maximum, MemoryArea memory)
          A queue with an unsynchronized and nonblocking write() method and a synchronized and blocking read() method.
 
Method Summary
 void clear()
          Set this to empty.
 boolean force(java.lang.Object object)
          Force this Object to replace the last one.
 boolean isEmpty()
          Used to determine if this is empty.
 boolean isFull()
          Used to determine if this is full.
 java.lang.Object read()
          A synchronized read on the queue.
 int size()
          Used to determine the number of elements in this.
 boolean write(java.lang.Object object)
          Try to insert an element into the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaitFreeWriteQueue

public WaitFreeWriteQueue(java.lang.Thread writer,
                          java.lang.Thread reader,
                          int maximum,
                          MemoryArea memory)
                   throws java.lang.IllegalArgumentException,
                          java.lang.InstantiationException,
                          java.lang.ClassNotFoundException,
                          java.lang.IllegalAccessException
A queue with an unsynchronized and nonblocking write() method and a synchronized and blocking read() method.
Parameters:
writer - An instance of Thread.
reader - An instance of Thread.
maximum - The maximum number of elements in the queue.
memory - The MemoryArea in which this object and internal elements are allocated.
Method Detail

clear

public void clear()
Set this to empty.

isEmpty

public boolean isEmpty()
Used to determine if this is empty.
Returns:
True if this is empty and false if this is not empty.

isFull

public boolean isFull()
Used to determine if this is full.
Returns:
True if this is full and false if this is not full.

read

public java.lang.Object read()
A synchronized read on the queue.
Returns:
The Object read or null if this is empty.

size

public int size()
Used to determine the number of elements in this.
Returns:
An integer which is the number of non-empty positions in this.

force

public boolean force(java.lang.Object object)
              throws MemoryScopeException
Force this Object to replace the last one. If the reader should happen to have just removed the other Object just as we were updating it, we will return false. False may mean that it just saw what we put in there. Either way, the best thing to do is to just write again -- which will succeed, and check on the readers side for consecutive identical read values.
Returns:
True if the queue was full, object was enqueued, and the last entry was overwritten with object

write

public boolean write(java.lang.Object object)
              throws MemoryScopeException
Try to insert an element into the queue.
Parameters:
object - The Object to insert.
Returns:
True if the insert succeeded, false if not.