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.

3. Multi-Threaded Programming<br />

int currentSize()<br />

public int getMaxSize()<br />

void setMaxSize(int newSize)<br />

Other protected fields Apart from the protected buffer array and object<br />

lock described above, the following are the other fields for subclass usage.<br />

First there are the indexes for reading respectively writing as shown in<br />

Figure 3-10, as well as the current size:<br />

int currSize;<br />

int postAt;<br />

int fetchAt;<br />

There are two fields for keeping the maximum size. It is the maxSizeW<br />

that is the requested maximum size. The maxSizeR can temporarily<br />

during shrinkage (resizing equal to true) of a too large buffer be greater<br />

than maxSizeW, but they will have the same value during normal operation<br />

(when resizing equals false).<br />

int maxSizeR;<br />

int maxSizeW;<br />

boolean resizing;<br />

Threads that are interrupted during (or prior to) blocking are thrown<br />

an RTInterrupted error.<br />

Referring to buffer input or output<br />

Sometimes it is desirable to have an object that represents only one end of a<br />

buffer. For the RTEventBuffer, utilizing Java interfaces, this is accomplished<br />

by one interface for input containing the post methods, and one interface for<br />

output containing the methods for fetching events. Thus,<br />

class RTEventBuffer implements RTEventBufferInput , RTEventBufferOutput<br />

where these interfaces are defined as<br />

interface RTEventBufferInput {<br />

RTEvent post(RTEvent e);<br />

void doPost(RTEvent e);<br />

RTEvent tryPost(RTEvent e);<br />

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

RTEvent tryPost(RTEvent e, long timeout , int nanos);<br />

}<br />

interface RTEventBufferOutput {<br />

RTEvent fetch();<br />

RTEvent doFetch();<br />

RTEvent tryFetch();<br />

RTEvent tryFetch(long timeout);<br />

RTEvent tryFetch(long timeout , int nanos);<br />

}<br />

Refer to the RTEventBuffer above for a description of the methods. Using<br />

these interfaces you can for instance have the output of a buffer managed<br />

94 2012-08-29 16:05

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

Saved successfully!

Ooh no, something went wrong!