|
RoboJDETM v2.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ridgesoft.io.Mailbox
public class Mailbox
This class implements a reliable means for passing messages over an unrelaible serial data stream, such as a serial port. The protocol supports messages as short arrays of binary data. It does not restrict the data which messages may contain, although the messages must be shorter than the specified receive length. The protocol ensures the messages are delivered to the receiver in the order they are transmitted. The protocol also implements flow control, ensuring the transmitter cannot send messages faster than the output stream can deliver them and the receiver can process them.
The protocol is symmetric, allowing both ends of the stream to use this class to pass data.
Constructor Summary | |
---|---|
Mailbox(InputStream inputStream,
OutputStream outputStream,
int maximumReceiveLength,
int basePriority)
Constructs a Mailbox object. |
Method Summary | |
---|---|
void |
close()
Close the mailbox. |
byte[] |
getMessage()
Gets the next message sent by the peer. |
byte[] |
getMessage(int maximumWaitTime)
Gets the next message sent by the peer. |
int |
getReceiveErrors()
Gets the count of recieve message errors. |
int |
getRetransmitCount()
Gets the count of retransmissions. |
void |
open()
Open the mailbox, waiting as long as necessary to connect with the peer at the other end of the streams. |
void |
open(int timeout)
Open the mailbox, waiting no longer than the timeout value to connect with the peer at the other end of the streams. |
void |
postMessage(byte[] message)
Posts a message to be delivered to the peer. |
void |
postMessage(byte[] message,
int maximumWaitTime)
Posts a message to be delivered to the peer. |
void |
setRetransmitTime(int rxTime)
Sets the amount of time to wait before retransmitting an unacknowledged message. |
void |
setRxSleepTime(int rxSleepTime)
Sets the time the receiver thread sleeps between polls of the input stream when there is no data. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait |
Constructor Detail |
---|
public Mailbox(InputStream inputStream, OutputStream outputStream, int maximumReceiveLength, int basePriority)
inputStream
- an InputStream objectoutputStream
- an OutputStream objectmaximumReceiveLength
- a value as large or larger than the maximum length of any receive message.
Larger messages will be discarded.basePriority
- the base priority for the mailbox's threads. The mailbox will create threads
which run at this priority and the next higher priority when it is openned.Method Detail |
---|
public void close()
public byte[] getMessage() throws IOException
IOException
public byte[] getMessage(int maximumWaitTime) throws IOException
maximumWaitTime
- the maximum time in milliseconds to wait for a message
IOException
public int getReceiveErrors()
public int getRetransmitCount()
public void open() throws IOException
IOException
public void open(int timeout) throws IOException
timeout
- timeout in milliseconds
IOException
public void postMessage(byte[] message) throws IOException
message
- a byte array containing the message to send
IOException
public void postMessage(byte[] message, int maximumWaitTime) throws IOException
message
- a byte array containing the message to sendmaximumWaitTime
- the maximum time in milliseconds to wait. The value 0 indicates
do not timeout.
IOException
public void setRetransmitTime(int rxTime)
rxTime
- retransmit timeout in milliseconds.
The default is 1000 milliseconds.public void setRxSleepTime(int rxSleepTime)
rxSleepTime
- time in milliseconds to wait between receive polls.
The default is 4 milliseconds.
|
RoboJDETM v2.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |