|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--se.lth.cs.realtime.event.RTEventBuffer
A basic queue/buffer for RTEvent
objects.
Essentially a protected bounded buffer with both blocking and non-blocking
methods for posting and fetching messages in terms of references to objects.
For the functionality provided by this basic class, the buffer could have
been typed to contain EventObject
s (the base class of RTEvent),
but to permit subclasses of RTEventBuffer
to utilize the
properties of the RTEvents that class is used here. For instance, one might
need a buffer that keeps track of the total delay of data by referring to
the time-stamps of the newest and oldest RTEvent.
The methods checking or awaiting buffer full/empty are useful for operation supervision, capturing events until a buffer is filled, mode changes, etc.
Field Summary | |
protected int |
currSize
Current queue size. |
protected RTEvent[] |
events
The actual buffer. |
protected int |
fetchAt
Position of first element to fetch, if any. |
protected int |
maxSizeR
Maximal queue size for Reading events. |
protected int |
maxSizeW
Maximal queue size, which is also the size for Writing/posting. |
protected int |
postAt
|
protected boolean |
resizing
Marks that setMaxSize is being evaluated. |
Constructor Summary | |
RTEventBuffer(int maxSize)
Initalizes the queue with a given maximal size. |
Method Summary | |
void |
awaitEmpty()
Waits for buffer to become empty. |
void |
awaitFull()
Waits for buffer to become 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. |
protected void |
error(java.lang.String message)
Takes care of InterruptedException . |
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 |
tryPost(RTEvent e)
Adds an EventObject to the queue, without blocking if the queue is full. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected RTEvent[] events
protected int maxSizeR
setMaxSize
, this
attribute can differ from the ordinary buffer size.maxSizeW
protected int maxSizeW
protected boolean resizing
setMaxSize
is being evaluated.
More than one call whould screw-up that operation because it need to
be blocked until all messages fit into the new (possibly smaller) size.protected int currSize
protected int postAt
protected int fetchAt
Constructor Detail |
public RTEventBuffer(int maxSize)
maxSize
- maximum queue sizeMethod Detail |
public RTEvent tryFetch()
public RTEvent doFetch()
public RTEvent tryPost(RTEvent e)
e
- the event to enqueuepublic void doPost(RTEvent e)
e
- the event to enqueuepublic boolean isEmpty()
public void awaitEmpty()
public boolean isFull()
public void awaitFull()
public int currentSize()
maxSizeR
public void flush()
public int getMaxSize()
public void setMaxSize(int newSize)
the
- new maximum number of objects that can be enqueuedprotected void error(java.lang.String message)
InterruptedException
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |