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 ByteBuffer
s.
In general, messages may be delayed, dropped or delivered out of order; however, some implementations may provide better guarantees.
Remote nodes are identified by String
s; the interpretation of these String
s 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
Modifier and TypeInterfaceDescriptionstatic interface
Callback interface used byNetwork
implementations. -
Method Summary
Modifier and TypeMethodDescriptionboolean
send
(String peer, ByteBuffer msg) Send (or enqueue for sending) a message to a remote peer.void
start
(Network.Handler handler) Start this instance.void
stop()
Stop this instance.
-
Method Details
-
start
Start this instance.- Parameters:
handler
- handler for notifications- Throws:
IllegalStateException
- if already startedIllegalArgumentException
- ifhandler
is 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 parameterpeer
at 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
- ifpeer
cannot be interpretedIllegalArgumentException
- ifpeer
ormsg
is null
-