public abstract class AbstractClientChannel extends AbstractChannel implements ClientChannel
| Modifier and Type | Class and Description |
|---|---|
private static class |
AbstractClientChannel.NullIoInputStream |
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulStateAbstractCloseable.StateAttributeRepository.AttributeKey<T>StreamingChannel.Streaming| Modifier and Type | Field and Description |
|---|---|
protected ChannelAsyncInputStream |
asyncErr |
protected ChannelAsyncOutputStream |
asyncIn |
protected ChannelAsyncInputStream |
asyncOut |
private java.lang.String |
channelType |
protected java.io.OutputStream |
err |
protected java.util.concurrent.atomic.AtomicReference<java.lang.String> |
exitSignalHolder |
protected java.util.concurrent.atomic.AtomicReference<java.lang.Integer> |
exitStatusHolder |
protected java.io.InputStream |
in |
protected java.io.InputStream |
invertedErr |
protected java.io.OutputStream |
invertedIn |
protected java.io.InputStream |
invertedOut |
private static java.io.InputStream |
NULL_INPUT_STREAM |
protected java.util.concurrent.atomic.AtomicBoolean |
opened |
protected java.lang.String |
openFailureLang |
protected java.lang.String |
openFailureMsg |
protected int |
openFailureReason |
protected OpenFuture |
openFuture |
protected java.io.OutputStream |
out |
protected boolean |
redirectErrorStream |
protected StreamingChannel.Streaming |
streaming |
channelListenerProxy, channelListeners, closeSignaled, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaledcloseFuture, futureLock, statelogCHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMEMPTYNONE| Modifier | Constructor and Description |
|---|---|
protected |
AbstractClientChannel(java.lang.String type) |
protected |
AbstractClientChannel(java.lang.String type,
java.util.Collection<? extends RequestHandler<Channel>> handlers) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addChannelSignalRequestHandlers(EventNotifier<java.lang.String> notifier) |
protected abstract void |
doOpen() |
protected void |
doWriteData(byte[] data,
int off,
long len) |
protected void |
doWriteExtendedData(byte[] data,
int off,
long len) |
IoInputStream |
getAsyncErr() |
IoOutputStream |
getAsyncIn() |
IoInputStream |
getAsyncOut() |
java.util.Set<ClientChannelEvent> |
getChannelState() |
java.lang.String |
getChannelType() |
java.io.OutputStream |
getErr() |
java.lang.String |
getExitSignal() |
java.lang.Integer |
getExitStatus() |
java.io.InputStream |
getIn() |
protected Closeable |
getInnerCloseable() |
java.io.InputStream |
getInvertedErr()
Obtains an
InputStream to read received SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA data directly
from the channel. |
java.io.OutputStream |
getInvertedIn()
Obtains an
OutputStream to send data directly to the remote end of the channel. |
java.io.InputStream |
getInvertedOut()
Obtains an
InputStream to read received SshConstants.SSH_MSG_CHANNEL_DATA data directly from the
channel. |
java.io.OutputStream |
getOut() |
StreamingChannel.Streaming |
getStreaming() |
void |
handleOpenFailure(Buffer buffer)
For a client channel, this method will be called internally by the session when the server has rejected this
channel opening.
|
void |
handleOpenSuccess(long recipient,
long rwSize,
long packetSize,
Buffer buffer)
For a client channel, this method will be called internally by the session when the confirmation has been
received.
|
void |
handleWindowAdjust(Buffer buffer)
Invoked when
SSH_MSG_CHANNEL_WINDOW_ADJUST received |
boolean |
isRedirectErrorStream() |
protected boolean |
mayWrite() |
OpenFuture |
open() |
OpenFuture |
open(long recipient,
long rwSize,
long packetSize,
Buffer buffer)
For a server channel, this method will actually open the channel
|
void |
setErr(java.io.OutputStream err)
Sets an output stream for the channel to write received
SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA data
to. |
void |
setIn(java.io.InputStream in)
Sets an
InputStream that will be read by this channel and forwarded to the remote channel. |
void |
setOut(java.io.OutputStream out)
Sets an output stream for the channel to write received
SshConstants.SSH_MSG_CHANNEL_DATA data to. |
void |
setRedirectErrorStream(boolean redirectErrorStream)
Defines whether to redirect the error stream into the output stream; has no effect if
ClientChannel.setErr(OutputStream) has also been called by the time the channel is opened. |
void |
setStreaming(StreamingChannel.Streaming streaming) |
protected <C extends java.util.Collection<ClientChannelEvent>> |
updateCurrentChannelState(C state) |
java.util.Set<ClientChannelEvent> |
waitFor(java.util.Collection<ClientChannelEvent> mask,
long timeout)
Waits until any of the specified events in the mask is signaled
|
addChannelListener, addPendingRequest, addRequestHandler, attributeKeys, clearAttributes, computeAttributeIfAbsent, configureWindow, getAttribute, getAttributesCount, getChannelId, getChannelListenerProxy, getChannelStreamWriterResolver, getExecutorService, getLocalWindow, getParentPropertyResolver, getProperties, getRecipient, getRemoteWindow, getRequestHandlers, getSession, handleChannelRegistrationResult, handleChannelRequest, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleInternalRequest, handleRequest, handleSuccess, handleUnknownChannelRequest, init, invokeChannelSignaller, isEofSent, isEofSignalled, isInitialized, notifyStateChanged, notifyStateChanged, preClose, removeAttribute, removeChannelListener, removePendingRequest, removeRequestHandler, resolveChannelStreamWriterResolver, sendEof, sendResponse, sendWindowAdjust, setAttribute, setChannelStreamWriterResolver, setRecipient, signalChannelClosed, signalChannelClosed, signalChannelInitialized, signalChannelInitialized, signalChannelOpenFailure, signalChannelOpenFailure, signalChannelOpenSuccess, signalChannelOpenSuccess, toString, validateIncomingDataSize, writePacketdoCloseGracefully, doCloseImmediatelyaddCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenerdebug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetClientSession, validateCommandExitStatusCode, waitForaddRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, resolveAttribute, writePacketgetSession, getSessionContextgetChannelIdaddChannelListener, getChannelListenerProxy, removeChannelListenergetBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty, isEmptyclearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeattributeKeys, getAttribute, getAttributesCount, ofAttributesMap, ofKeyValuePairgetChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolveraddCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListenerprivate static final java.io.InputStream NULL_INPUT_STREAM
protected final java.util.concurrent.atomic.AtomicBoolean opened
protected StreamingChannel.Streaming streaming
protected ChannelAsyncOutputStream asyncIn
protected ChannelAsyncInputStream asyncOut
protected ChannelAsyncInputStream asyncErr
protected java.io.InputStream in
protected java.io.OutputStream invertedIn
protected java.io.OutputStream out
protected java.io.InputStream invertedOut
protected java.io.OutputStream err
protected java.io.InputStream invertedErr
protected boolean redirectErrorStream
protected final java.util.concurrent.atomic.AtomicReference<java.lang.Integer> exitStatusHolder
protected final java.util.concurrent.atomic.AtomicReference<java.lang.String> exitSignalHolder
protected int openFailureReason
protected java.lang.String openFailureMsg
protected java.lang.String openFailureLang
protected OpenFuture openFuture
private final java.lang.String channelType
protected AbstractClientChannel(java.lang.String type)
protected AbstractClientChannel(java.lang.String type,
java.util.Collection<? extends RequestHandler<Channel>> handlers)
protected void addChannelSignalRequestHandlers(EventNotifier<java.lang.String> notifier)
public java.lang.String getChannelType()
getChannelType in interface ClientChannelpublic StreamingChannel.Streaming getStreaming()
getStreaming in interface StreamingChannelpublic void setStreaming(StreamingChannel.Streaming streaming)
setStreaming in interface StreamingChannelpublic IoOutputStream getAsyncIn()
getAsyncIn in interface ClientChannelpublic IoInputStream getAsyncOut()
getAsyncOut in interface ClientChannelpublic IoInputStream getAsyncErr()
getAsyncErr in interface ClientChannelpublic java.io.OutputStream getInvertedIn()
ClientChannelOutputStream to send data directly to the remote end of the channel. This can be used instead
of using ClientChannel.setIn(InputStream) method and having the channel polling for data in that stream.
When the channel closes, it will close the returned stream.
This method should be called only after the channel has been opened.
getInvertedIn in interface ClientChannelOutputStream for sending data, or null if an input stream was set via
ClientChannel.setIn(InputStream)ClientChannel.setIn(InputStream)public java.io.InputStream getIn()
public void setIn(java.io.InputStream in)
ClientChannelInputStream that will be read by this channel and forwarded to the remote channel. Note that
using such a stream will create an additional thread for pumping the stream which will only be able to end when
that stream is actually closed or EOF on the stream is reached. It is recommended to use the
ClientChannel.getInvertedIn() method instead and write data directly.
The stream must be set before the channel is opened. When the channel closes, it will close the given stream.
setIn in interface ClientChannelin - an InputStream to be polled and forwardedClientChannel.getInvertedIn()public java.io.InputStream getInvertedOut()
ClientChannelInputStream to read received SshConstants.SSH_MSG_CHANNEL_DATA data directly from the
channel. This is an alternative to ClientChannel.setOut(OutputStream). If the error stream is redirected to the output
stream via setRedirectErrorStream(true), this stream will also receive
SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA data.
When the channel closes, it will not close the returned stream. It is the caller's responsibility to close the returned stream if needed. Closing the stream while the channel is open may cause the channel to be closed forcibly if more data arrives. The stream remains open after the channel has closed, so that the caller can read the last arrived data even afterwards.
As with all external processes, the application should read this stream to avoid that the channel blocks when the stream's buffer is full. The buffer size for the returned stream is bounded by the channel's local window size. If the caller does not read this stream, the channel will block once the local window is exhausted.
This method should be called only after the channel has been opened.
getInvertedOut in interface ClientChannelInputStream for reading received data, or null if an output stream was set via
ClientChannel.setOut(OutputStream)ClientChannel.setOut(OutputStream),
ClientChannel.setRedirectErrorStream(boolean)public java.io.OutputStream getOut()
public void setOut(java.io.OutputStream out)
ClientChannelSshConstants.SSH_MSG_CHANNEL_DATA data to. For
remote command execution, this is typically the remote command's stdout. If the error stream is
redirected to the output stream via setRedirectErrorStream(true), this
stream will also receive SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA data.
The stream must be set before the channel is opened. When the channel closes, it will close the given stream.
If no stream is set by the time the channel is opened, the channel will internally forward data to a stream that
can be read via the InputStream obtained via ClientChannel.getInvertedOut().
setOut in interface ClientChannelout - the OutputStreamClientChannel.getInvertedOut(),
ClientChannel.setRedirectErrorStream(boolean)public java.io.InputStream getInvertedErr()
ClientChannelInputStream to read received SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA data directly
from the channel. This is an alternative to ClientChannel.setErr(OutputStream). If the error stream is redirected to
the output stream via setRedirectErrorStream(true), the returned stream
will not receive any data and be always at EOF.
When the channel closes, it will not close the returned stream. It is the caller's responsibility to close the returned stream if needed. Closing the stream while the channel is open may cause the channel to be closed forcibly if more data arrives. The stream remains open after the channel has closed, so that the caller can read the last arrived data even afterwards.
As with all external processes, the application should read this stream (unless it was redirected) to avoid that the channel blocks when the stream's buffer is full. The buffer size for the returned stream is bounded by the channel's local window size. If the caller does not read this stream, the channel will block once the local window is exhausted.
This method should be called only after the channel has been opened.
getInvertedErr in interface ClientChannelInputStream for reading received data, or null if an output stream was set via
ClientChannel.setErr(OutputStream)ClientChannel.setErr(OutputStream),
ClientChannel.setRedirectErrorStream(boolean)public java.io.OutputStream getErr()
public void setErr(java.io.OutputStream err)
ClientChannelSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA data
to. For remote command execution, this is typically the remote command's stderr.
The stream must be set before the channel is opened. When the channel closes, it will close the given stream.
If no stream is set by the time the channel is opened, the channel will internally forward data to a stream that
can be read via the InputStream obtained via ClientChannel.getInvertedErr(). (Or it might forward the data to
the output stream if setRedirectErrorStream(true) is set.)
setErr in interface ClientChannelerr - the OutputStreamClientChannel.getInvertedErr(),
ClientChannel.setRedirectErrorStream(boolean)public boolean isRedirectErrorStream()
public void setRedirectErrorStream(boolean redirectErrorStream)
ClientChannelClientChannel.setErr(OutputStream) has also been called by the time the channel is opened.setRedirectErrorStream in interface ClientChannelredirectErrorStream - whether to redirect the error stream to the output stream.protected Closeable getInnerCloseable()
getInnerCloseable in class AbstractChannelpublic java.util.Set<ClientChannelEvent> waitFor(java.util.Collection<ClientChannelEvent> mask, long timeout)
ClientChannelwaitFor in interface ClientChannelmask - The ClientChannelEvents masktimeout - The timeout to wait (msec.) - if non-positive then foreverClientChannelEvent.TIMEOUT if timeout expired before
the expected event was signaledpublic java.util.Set<ClientChannelEvent> getChannelState()
getChannelState in interface ClientChannelClientChannel.waitFor(Collection, long)protected <C extends java.util.Collection<ClientChannelEvent>> C updateCurrentChannelState(C state)
public OpenFuture open() throws java.io.IOException
open in interface ClientChanneljava.io.IOExceptionpublic OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer)
Channelrecipient - Recipient identifier (UINT32 represented as a long)rwSize - Read/Write window size (uint32)packetSize - Preferred maximum packet size (uint32)buffer - Incoming Buffer that triggered the call. Note: the buffer's read position is
exactly after the information that read to this call was decodedOpenFuture for the channel open requestpublic void handleOpenSuccess(long recipient,
long rwSize,
long packetSize,
Buffer buffer)
Channelrecipient - Recipient identifier (UINT32 represented as a long)rwSize - Read/Write window size (uint32)packetSize - Preferred maximum packet size (uint32)buffer - Incoming Buffer that triggered the call. Note: the buffer's read position is
exactly after the information that read to this call was decodedprotected abstract void doOpen()
throws java.io.IOException
java.io.IOExceptionpublic void handleOpenFailure(Buffer buffer)
Channelbuffer - Incoming Buffer that triggered the call. Note: the buffer's read position is
exactly after the information that read to this call was decodedprotected void doWriteData(byte[] data,
int off,
long len)
throws java.io.IOException
doWriteData in class AbstractChanneljava.io.IOExceptionprotected void doWriteExtendedData(byte[] data,
int off,
long len)
throws java.io.IOException
doWriteExtendedData in class AbstractChanneljava.io.IOExceptionpublic void handleWindowAdjust(Buffer buffer) throws java.io.IOException
ChannelSSH_MSG_CHANNEL_WINDOW_ADJUST receivedhandleWindowAdjust in class AbstractChannelbuffer - The rest of the message data Buffer after decoding the channel identifiersjava.io.IOException - If failed to handle the messageprotected boolean mayWrite()
mayWrite in class AbstractChannelpublic java.lang.Integer getExitStatus()
getExitStatus in interface ClientChannelnull if not signaledpublic java.lang.String getExitSignal()
getExitSignal in interface ClientChannelnull if not signaled