javax.realtime
Class WaitFreeWriteQueue

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

public class WaitFreeWriteQueue
extends java.lang.Object

The wait-free queue facilitate communication and synchronization between instances of RealtimeThread and java.lang.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.


Field Summary
protected  int currentIndex
           
protected  javax.realtime.MemoryArea memArea
           
protected  int queueSize
           
protected  java.lang.Thread readerThread
           
protected  java.lang.Object[] writeQueue
           
protected  java.lang.Thread writerThread
           
 
Constructor Summary
WaitFreeWriteQueue(java.lang.Thread writer, java.lang.Thread reader, int maximum, javax.realtime.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 java.lang.Object to replace the last one.
 boolean isEmpty()
          Queries the system to determine if this is empty.
 boolean isFull()
          Queries the system to determine if this is full.
 java.lang.Object read()
          A synchronized read on the queue.
 int size()
          Queries the system to determine the number of elements in this.
 boolean write(java.lang.Object object)
          Attempt 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
 

Field Detail

writeQueue

protected java.lang.Object[] writeQueue

queueSize

protected int queueSize

currentIndex

protected int currentIndex

writerThread

protected java.lang.Thread writerThread

readerThread

protected java.lang.Thread readerThread

memArea

protected javax.realtime.MemoryArea memArea
Constructor Detail

WaitFreeWriteQueue

public WaitFreeWriteQueue(java.lang.Thread writer,
                          java.lang.Thread reader,
                          int maximum,
                          javax.realtime.MemoryArea memory)
                   throws java.lang.IllegalArgumentException
A queue with an unsynchronized and nonblocking write() method and a synchronized and blocking read() method.

Parameters:
writer - An instance of java.lang.Thread.
reader - An instance of java.lang.Thread.
maximum - The maximum number of elements in the queue.
memory - The MemoryArea in which this object and internal elements are allocated.
Throws:
java.lang.IllegalArgumentException - If an argument holds an invalid value. The current memory areas of writer, reader, and memory must be compatible with respect to the assignment and access rules for memory areas.
Method Detail

clear

public void clear()
Set this to empty.


force

public boolean force(java.lang.Object object)
              throws MemoryScopeException
Force this java.lang.Object to replace the last one. If the reader should happen to have just removed the other java.lang.Object just as we were updating it, we will return false. False may mean that it just saw that 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 an element was overwritten. False, if there is an empty element into which the write occured.
Throws:
MemoryScopeException

isEmpty

public boolean isEmpty()
Queries the system to determine if this is empty.

Returns:
True, if this is empty. False, if this is not empty.

isFull

public boolean isFull()
Queries the system to determine if this is full.

Returns:
True, if this is full. False, if this is not full.

read

public java.lang.Object read()
A synchronized read on the queue.

Returns:
The java.lang.Object read or null if this is empty.

size

public int size()
Queries the system to determine the number of elements in this.

Returns:
An integer which is the number of non-empty positions in this.

write

public boolean write(java.lang.Object object)
              throws MemoryScopeException
Attempt to insert an element into the queue.

Parameters:
object - The java.lang.Object to insert.
Returns:
True, if the write succeeded. False, if not.
Throws:
MemoryScopeException