Class SynchronousCommandTransport
- java.lang.Object
-
- hudson.remoting.CommandTransport
-
- hudson.remoting.SynchronousCommandTransport
-
- Direct Known Subclasses:
AbstractSynchronousByteArrayCommandTransport
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
CommandTransport.CommandReceiver
.- Author:
- Kohsuke Kawaguchi
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class hudson.remoting.CommandTransport
CommandTransport.CommandReceiver
-
-
Constructor Summary
Constructors Constructor Description SynchronousCommandTransport()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Command
read()
Called byChannel
to read the next command to arrive from the stream.void
setup(Channel channel, CommandTransport.CommandReceiver receiver)
Starts the transport.-
Methods inherited from class hudson.remoting.CommandTransport
closeRead, closeWrite, getRemoteCapability, write
-
-
-
-
Field Detail
-
channel
protected Channel channel
-
-
Method Detail
-
read
public abstract Command read() throws IOException, ClassNotFoundException, InterruptedException
Called byChannel
to read the next command to arrive from the stream.
-
setup
public void setup(Channel channel, CommandTransport.CommandReceiver receiver)
Description copied from class:CommandTransport
Starts the transport. This method is called once and only once at the end of the initialization ofChannel
, after theCommandTransport.getRemoteCapability()
is invoked. The first purpose of this method is to provide a reference back toChannel
, and the second purpose of this method is to allowCommandTransport
to message pumping, where it starts receiving commands from the other side and pass them ontoCommandTransport.CommandReceiver
. This abstraction enables asynchronous processing — for example you can have a single thread serving a large number ofChannel
s via NIO. For subtypes that prefer synchronous operation, extend fromSynchronousCommandTransport
.Closing the read pump:
Channel
implementsChannel.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 yourCommandTransport.closeRead()
(from the same thread that invokedCommandTransport.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 callsCommandTransport.closeRead()
to shutdown the reader side.- Specified by:
setup
in classCommandTransport
-
-