06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4. Exercises and Labs<br />

PeriodicThread<br />

The PeriodicThread is used when an activity needs periodic execution. The<br />

perform method will be called at periodic intervals. The PeriodicThread inherits<br />

from RTThread via CyclicThread, and thus have a mailbox.<br />

public abstract class CyclicThread extends RTThread implements Runnable { ... }<br />

public class PeriodicThread extends CyclicThread {<br />

}<br />

/**<br />

* Allocates a new PeriodicThread object.<br />

*<br />

* @param period the period of the new thread , in milliseconds.<br />

*<br />

* @exception IllegalArgumentException if the period is not positive.<br />

*/<br />

public PeriodicThread(long period) { ... }<br />

/**<br />

* To be overridden. The perform method will be called at periodic<br />

* intervals.<br />

*/<br />

protected void perform() {}<br />

Mailbox - RTEventBuffer<br />

Mailboxes are implemented in the RTEventBuffer class. A thread should only<br />

fetch messages posted to its own mailbox.<br />

public abstract class RTEventBuffer implements RTEventBufferInput ,<br />

RTEventBufferOutput , Synchronized {<br />

}<br />

/**<br />

* Returns the next RTEvent in the queue , blocks if none available.<br />

*<br />

* @return a non -null event.<br />

*/<br />

public abstract RTEvent doFetch();<br />

/**<br />

* Returns the next available RTEvent in the queue , or null if the queue is<br />

* empty. In other words , this method always returns immediately , even if<br />

* the queue is empty (non -blocking).<br />

*<br />

* @return an RTEvent if any available , null otherwise<br />

*/<br />

public abstract RTEvent tryFetch();<br />

/**<br />

* Adds an RTEvent to the queue , blocks caller if the queue is full.<br />

*<br />

* @param e the event to enqueue<br />

*/<br />

public abstract void doPost(RTEvent e);<br />

134 2012-08-29 16:05

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

Saved successfully!

Ooh no, something went wrong!