06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

RTEvent post(RTEvent e)<br />

final void doPost(RTEvent e)<br />

final RTEvent tryPost(RTEvent e)<br />

final RTEvent tryPost(RTEvent e, long timeout)<br />

3.4. Message-based communication – Mailboxes<br />

Fetching The corresponding methods for fetching messages look as follows,<br />

where the tryFetch methods return null if no event object was obtained.<br />

RTEvent fetch()<br />

final RTEvent doFetch()<br />

final RTEvent tryFetch()<br />

final RTEvent tryFetch(long timeout)<br />

Control and status The following non-blocking methods can be used to<br />

check if the buffer is empty or full.<br />

boolean isEmpty()<br />

boolean isFull()<br />

For a single producing or consuming thread these methods can be useful,<br />

but in the general case with outer threads involved the returned state<br />

may of course be invalid already when execution continues on the next<br />

line (due to preemption, etc.), so using the try-methods are usually<br />

preferred.<br />

Sometimes state or mode changes are to take place based on the state<br />

of the buffer, and the responsible thread is to be blocked until the buffer<br />

condition is fulfilled. The following await-methods are blocking. Examples<br />

of use include: await all event consumed before terminating the<br />

application, await producer started before starting operator or networking<br />

interface, await buffer filled with event trace, and await consumer<br />

started, respectively:<br />

void awaitEmpty()<br />

void awaitNotEmpty()<br />

void awaitFull()<br />

void awaitNotFull()<br />

The fetchAll is to get all buffered events leaving the buffer empty. The<br />

event that was the next to be fetched is returned as the first element<br />

(index 0), followed by the other events in FIFO order with the most<br />

recently posted event as the last element. An empty array (not null) is<br />

returned if the buffer was empty. Calling flush also results in an empty<br />

buffer.<br />

RTEvent[] fetchAll()<br />

void flush()<br />

There are set and get methods for the maximum size of the buffer.<br />

Note that if the maximum size of the buffer is decreased to less than<br />

the current size (obtained via currentSize), the caller of setMaxSize is<br />

blocked until the size actually has decreased to the new maximum size<br />

(due to other threads fetching messages).<br />

93

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!