|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jarol.messages.Link
public abstract class Link
Jarol-wise, non-blocking, lock-free bidirectional message link abstract class.
A link has the intent of providing calling tasks a Jarol-wise signal/port interface for operation, with deterministic operation and non-blocking behavior.
This base class is extended by classes that implement actual network links in the Jarol system or custom ones defined by the user. Derived classes need only to provide link access functions (start/stop/send/receive functions), the application interface logic is within the base link class.
The link can be used to send and receive message using two instances of base.Port and an instance of base.Signal:
1) A receive port which callers can poll for received messages. The receive port is updated asynchronously (as soon as messages arrive).
2) A send port in which callers can place messages to be sent
3) A send signal to actually send the messages in the send port over the link. To send messages, the link caller should place a number of messages in the send port then trigger the send signal.
Internally Link works as follows:
1) A "receiver thread" polls the communication link and when it gets a new message it places it on the receive port.
2) A "sender thread" that waits on the send signal, then sends data from the send port over the communication link.
Note that a link will self-disconnect if the physical connection has a fatal error.
Field Summary | |
---|---|
static int |
DEFAULT_PORT_BUFSZ
Default buffer capacity for the receive and send ports |
static int |
MAX_MESSAGE_PAYLOAD
Maximum message payload |
Constructor Summary | |
---|---|
Link(MessageFactory factory)
Constructor specifying message factory. |
|
Link(MessageFactory factory,
int recvPortBufSz,
int sendPortBufSz)
Constructor specifying message factory and receive/send port capacity. |
Method Summary | |
---|---|
void |
connect()
Connect the message link. |
boolean |
connected()
Check if link is connected. |
void |
disconnect()
Disconnect the message link. |
Port |
getRecvPort()
Get receive port. |
Port |
getSendPort()
Get send port. |
Signal |
getSendSignal()
Get send signal. |
protected abstract int |
recv(byte[] buf,
int off,
int len,
int timeout)
Abstract method used to receive data. |
protected abstract void |
send(byte[] data,
int off,
int len)
Abstract method used to send data. |
protected abstract void |
start()
Abstract method for starting the link. |
protected abstract void |
stop()
Abstract method for stopping the link. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_PORT_BUFSZ
public static final int MAX_MESSAGE_PAYLOAD
Constructor Detail |
---|
public Link(MessageFactory factory)
factory
- the message factorypublic Link(MessageFactory factory, int recvPortBufSz, int sendPortBufSz)
factory
- the message factoryrecvPortBufSz
- the buffer size for the receive portsendPortBufSz
- the buffer size for the send portMethod Detail |
---|
public final boolean connected()
public final Port getSendPort()
public final Signal getSendSignal()
public final Port getRecvPort()
public final void connect() throws java.io.IOException
java.io.IOException
- if there a problem in connecting the linkpublic final void disconnect()
protected abstract void start() throws java.io.IOException
java.io.IOException
- if a port-specific error occurs (eg network related)protected abstract void stop() throws java.io.IOException
java.io.IOException
- if a port-specific error occurs (eg network related)protected abstract void send(byte[] data, int off, int len) throws java.io.IOException
data
- the message payloadoff
- payload offsetlen
- payload length
java.io.IOException
- if a port-specific error occurs (eg network related)protected abstract int recv(byte[] buf, int off, int len, int timeout) throws java.io.IOException
buf
- the receive buffer to useoff
- the receive buffer offsetlen
- the receive buffer usable lengthtimeout
- the time to wait for a message
java.io.IOException
- if a port-specific error occurs (eg network related)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |