public abstract class SynchronousCommandTransport extends CommandTransport
CommandTransport that implements the read operation in a synchronous fashion.
This class uses a thread to pump commands and pass them to CommandReceiver.
CommandTransport.CommandReceiver| Constructor and Description |
|---|
SynchronousCommandTransport() |
| Modifier and Type | Method and Description |
|---|---|
abstract Command |
read()
Called by
Channel to read the next command to arrive from the stream. |
void |
setup(Channel channel,
CommandTransport.CommandReceiver receiver)
Starts the transport.
|
closeRead, closeWrite, getRemoteCapability, writeprotected Channel channel
public abstract Command read() throws IOException, ClassNotFoundException, InterruptedException
Channel to read the next command to arrive from the stream.public void setup(Channel channel, CommandTransport.CommandReceiver receiver)
CommandTransportChannel,
after the CommandTransport.getRemoteCapability() is invoked.
The first purpose of this method is to provide a reference back to Channel, and
the second purpose of this method is to allow CommandTransport to message pumping,
where it starts receiving commands from the other side and pass them onto CommandTransport.CommandReceiver.
This abstraction enables asynchronous processing — for example you can have a single thread
serving a large number of Channels via NIO.
For subtypes that prefer synchronous operation, extend from SynchronousCommandTransport.
Channel implements Channel.CloseCommand its own "end of command stream" marker, and
therefore under the orderly shutdown scenario, it doesn't rely on the transport to provide EOF-like
marker. Instead, Channel will call your CommandTransport.closeRead() (from the same thread
that invoked CommandTransport.CommandReceiver.handle(Command)) to indicate that it is done with the reading.
If the transport encounters any error from the lower layer (say, the underlying TCP/IP socket
encountered a REST), then call CommandTransport.CommandReceiver.terminate(IOException) to initiate the abnormal
channel termination. This in turn calls CommandTransport.closeRead() to shutdown the reader side.
setup in class CommandTransportCopyright © 2004–2020. All rights reserved.