javax.realtime
Class WaitFreeReadQueue

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

public class WaitFreeReadQueue
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 read() method of this class does not block on an imagined queue-empty condition variable. If the read() is called on an empty queue null is returned. If two real-time threads intend to read from this queue they must provide their own synchronization.

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


Constructor Summary
WaitFreeReadQueue(java.lang.Thread writer, java.lang.Thread reader, int maximum, MemoryArea memory)
          A queue with an unsynchronized and nonblocking read() method and a synchronized and blocking write() method.
WaitFreeReadQueue(java.lang.Thread writer, java.lang.Thread reader, int maximum, MemoryArea memory, boolean notify)
          A queue with an unsynchronized and nonblocking read() method and a synchronized and blocking write() method.
 
Method Summary
 void clear()
          Set this to empty.
 boolean isEmpty()
          Used to determine if this is empty.
 boolean isFull()
          Used to determine if this is full.
 java.lang.Object read()
          Returns the next element in the queue unless the queue is empty.
 int size()
          Used to determine the number of elements in this.
 void waitForData()
          If this is empty waitForData() waits on the event until the writer inserts data.
 boolean write(java.lang.Object object)
          The synchronized and blocking write.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaitFreeReadQueue

public WaitFreeReadQueue(java.lang.Thread writer,
                         java.lang.Thread reader,
                         int maximum,
                         MemoryArea memory,
                         boolean notify)
                  throws java.lang.IllegalArgumentException,
                         java.lang.InstantiationException,
                         java.lang.ClassNotFoundException,
                         java.lang.IllegalAccessException
A queue with an unsynchronized and nonblocking read() method and a synchronized and blocking write() 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 stored.
notify - Whether or not the reader is notified when data is added.

WaitFreeReadQueue

public WaitFreeReadQueue(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 read() method and a synchronized and blocking write() method. The memory areas of the given threads are found. If these memory areas are the same the queue is created in that memory area. If these memory areas are different the queue is created in the memory area accessible by the most restricted thread type.
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 stored.
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()
Returns the next element in the queue unless the queue is empty. If the queue is empty null is returned.

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.

waitForData

public void waitForData()
If this is empty waitForData() waits on the event until the writer inserts data. Note that true priority inversion does not occur since the writer locks a different object and the notify is executed by the AsyncEventHandler which has noHeap characteristics.

write

public boolean write(java.lang.Object object)
              throws MemoryScopeException
The synchronized and blocking write. This call blocks on queue full and will wait until there is space in the queue.
Parameters:
object - The Object that is placed in this.