Interface Network
- All Known Implementing Classes:
ChannelNetwork,TCPNetwork
Communication takes the form of sending and receiving arbitrary packets of data known as "messages".
Messages are simply sequences of zero or more bytes and are represented by ByteBuffers.
In general, messages may be delayed, dropped or delivered out of order; however, some implementations may provide better guarantees.
Remote nodes are identified by Strings; the interpretation of these Strings is up to the implementation,
but typically it is some form of network address.
Incoming messages, along with notifications of output queue status, are delivered to a Network.Handler specified
by the application.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCallback interface used byNetworkimplementations. -
Method Summary
Modifier and TypeMethodDescriptionbooleansend(String peer, ByteBuffer msg) Send (or enqueue for sending) a message to a remote peer.voidstart(Network.Handler handler) Start this instance.voidstop()Stop this instance.
-
Method Details
-
start
Start this instance.- Parameters:
handler- handler for notifications- Throws:
IllegalStateException- if already startedIllegalArgumentException- ifhandleris nullIOException- if an error occurs
-
stop
void stop()Stop this instance.Does nothing if already stopped.
-
send
Send (or enqueue for sending) a message to a remote peer.If this method returns true, then
Handler.outputQueueEmpty()is guaranteed to be invoked with parameterpeerat some later point.- Parameters:
peer- message destinationmsg- message to send- Returns:
- true if message was succesfully enqueued for output; false if message failed to be delivered due to local reasons, such as failure to initiate a new connection or output queue overflow
- Throws:
IllegalArgumentException- ifpeercannot be interpretedIllegalArgumentException- ifpeerormsgis null
-