Object
MessageReceiver
- All Implemented Interfaces:
CompletionHandler<Integer,
AsynchronousSocketChannel>
public class MessageReceiver
extends Object
implements CompletionHandler<Integer,AsynchronousSocketChannel>
This handler acts as a message receiver and is notified each time server reads some data from the
client.
All read requests are done asynchronously. It means that this receiver may be called with different amounts of data read each time.
Receiver relies on message scanner to extract a message from a stream of bytes and then it passes them back to the looper.
Each time receiver reads new portion of data it appends it to internal buffer and then it uses scanner to tell where message ends in this buffer and another begins.
-
Constructor Summary
ConstructorDescriptionMessageReceiver
(AsynchronousSocketChannel channel, MessageScanner scanner) MessageReceiver
(AsynchronousSocketChannel channel, MessageScanner scanner, int bufSize) -
Method Summary
Modifier and TypeMethodDescriptionvoid
completed
(Integer result, AsynchronousSocketChannel channel) Called once read operation succeeds with some data read or when read is failed.void
failed
(Throwable exc, AsynchronousSocketChannel channel) receive()
-
Constructor Details
-
MessageReceiver
-
MessageReceiver
-
-
Method Details
-
completed
Called once read operation succeeds with some data read or when read is failed.- Specified by:
completed
in interfaceCompletionHandler<Integer,
AsynchronousSocketChannel>
-
failed
- Specified by:
failed
in interfaceCompletionHandler<Integer,
AsynchronousSocketChannel>
-
receive
-