|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectse.lth.cs.realtime.event.RTEventBuffer
se.lth.cs.realtime.event.Buffer
The standard full-featured RTEventBuffer implementation,
including methods for conditional blocking on full/empty conditions. By using
separate Condition objects for each extra buffer condition,
improved efficiency (fewer context switches) is accomplished in the case that
many threads are waiting on different things. This requires the application
to be started via class Main or being compiled with a suitable
compiler, otherwise about the same efficiency as if the implicit condition
was used will be obtained.
To meet the efficiency demands of some applications, most methods are final. The class as such is, however, not final since subclassing is expected for adding more features, hence the protected visibility of fields. Additionally, the methods post and fetch are virtual (i.e., not final). They by default call the corresponding do-method and are typed accordingly, but they are free for redefinition which can even result in synchronized being omitted if mutual exclusion is ensured elsewhere (in enclosing monitor, etc.). See also the implemented interfaces, which are facilitating access to only one end of the buffer.
For simple applications the more easy to understand implementation
BufferPlain could be used. Also that class extends the
RTEventBuffer.
BufferPlain,
License| Nested Class Summary |
| Nested classes inherited from class se.lth.cs.realtime.Synchronized |
Synchronized.Lock |
| Field Summary |
| Fields inherited from class se.lth.cs.realtime.event.RTEventBuffer |
DEFAULT_SIZE |
| Constructor Summary | |
Buffer()
Initializes the buffer with a size of DEFAULT_SIZE. |
|
Buffer(int maxSize)
Initializes the queue (buffer) with a given maximal size. |
|
Buffer(int maxSize,
Synchronized.Lock lock)
Initializes the queue (buffer) with a given maximal size, and with a lock object to be used for synchronization. |
|
| Method Summary | |
void |
awaitEmpty()
Waits for buffer to become empty. |
void |
awaitFull()
Waits for buffer to become full. |
void |
awaitNotEmpty()
Waits for buffer to become non-empty. |
void |
awaitNotFull()
Waits for buffer to become non-full. |
int |
currentSize()
The current size of the buffer. |
RTEvent |
doFetch()
Returns the next RTEvent in the queue, blocks if none available. |
void |
doPost(RTEvent e)
Adds an RTEvent to the queue, blocks caller if the queue is full. |
RTEvent[] |
fetchAll()
Get all buffered events leaving the buffer empty. |
void |
flush()
Removes all buffered events. |
int |
getMaxSize()
Gets the maximum size of the buffer. |
boolean |
isEmpty()
Checks if buffer is empty. |
boolean |
isFull()
Checks if buffer is full. |
void |
setMaxSize(int newSize)
Changes size of buffer. |
RTEvent |
tryFetch()
Returns the next available RTEvent in the queue, or null if the queue is empty. |
RTEvent |
tryFetch(long timeout)
Get the next RTEvent in the queue, or block (up to the specified timeout time) if no event is available. |
RTEvent |
tryPost(RTEvent e)
Adds an EventObject to the queue, without blocking if the queue is full. |
RTEvent |
tryPost(RTEvent e,
long timeout)
Adds an RTEvent to the queue, blocks caller if the queue is full up to the specified timeout time. |
| Methods inherited from class se.lth.cs.realtime.event.RTEventBuffer |
fetch, post |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Buffer()
DEFAULT_SIZE.
public Buffer(int maxSize)
maxSize - maximum queue size
public Buffer(int maxSize,
Synchronized.Lock lock)
maxSize - maximum queue sizelock - external monitor/object to synchronized with| Method Detail |
public final RTEvent doFetch()
doFetch in interface RTEventBufferOutputdoFetch in class RTEventBufferpublic final RTEvent tryFetch()
tryFetch in interface RTEventBufferOutputtryFetch in class RTEventBufferpublic final RTEvent tryFetch(long timeout)
BufferPlain.
tryFetch in interface RTEventBufferOutputtryFetch in class RTEventBuffertimeout - the maximum blocking time time in milli-seconds.
public final void doPost(RTEvent e)
doPost in interface RTEventBufferInputdoPost in class RTEventBuffere - the event to enqueuepublic final RTEvent tryPost(RTEvent e)
tryPost in interface RTEventBufferInputtryPost in class RTEventBuffere - the event to enqueue
public final RTEvent tryPost(RTEvent e,
long timeout)
BufferPlain.
tryPost in interface RTEventBufferInputtryPost in class RTEventBuffere - the event to enqueuetimeout - the maximum blocking time time in milli-seconds.
public boolean isEmpty()
isEmpty in class RTEventBufferpublic void awaitEmpty()
public void awaitNotEmpty()
public boolean isFull()
isFull in class RTEventBufferpublic void awaitFull()
public void awaitNotFull()
public int currentSize()
currentSize in class RTEventBufferRTEventBuffer#maxSizepublic void flush()
flush in class RTEventBufferpublic RTEvent[] fetchAll()
fetchAll in class RTEventBufferpublic int getMaxSize()
getMaxSize in class RTEventBufferpublic void setMaxSize(int newSize)
newSize - the new maximum number of objects that can be enqueued
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||