public abstract class AbstractClientChannel extends AbstractChannel implements ClientChannel
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulState, AbstractChannel.PacketValidatorAbstractCloseable.StateAttributeRepository.AttributeKey<T>StreamingChannel.Streaming| Modifier and Type | Field and Description |
|---|---|
protected ChannelAsyncInputStream |
asyncErr |
protected ChannelAsyncOutputStream |
asyncIn |
protected ChannelAsyncInputStream |
asyncOut |
protected OutputStream |
err |
protected AtomicReference<String> |
exitSignalHolder |
protected AtomicReference<Integer> |
exitStatusHolder |
protected InputStream |
in |
protected InputStream |
invertedErr |
protected OutputStream |
invertedIn |
protected InputStream |
invertedOut |
protected AtomicBoolean |
opened |
protected String |
openFailureLang |
protected String |
openFailureMsg |
protected int |
openFailureReason |
protected OpenFuture |
openFuture |
protected OutputStream |
out |
protected boolean |
redirectErrorStream |
protected StreamingChannel.Streaming |
streaming |
channelListenerProxy, channelListeners, closeSignaled, DEFAULT_PACKET_VALIDATOR, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaledcloseFuture, futureLock, statelogCHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMEMPTYNONE| Modifier | Constructor and Description |
|---|---|
protected |
AbstractClientChannel(String type) |
protected |
AbstractClientChannel(String type,
Collection<? extends RequestHandler<Channel>> handlers) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addChannelSignalRequestHandlers(EventNotifier<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() |
Set<ClientChannelEvent> |
getChannelState() |
String |
getChannelType() |
OutputStream |
getErr() |
String |
getExitSignal() |
Integer |
getExitStatus() |
InputStream |
getIn() |
protected Closeable |
getInnerCloseable() |
InputStream |
getInvertedErr()
Obtains an
InputStream to read received SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA data directly
from the channel. |
OutputStream |
getInvertedIn()
Obtains an
OutputStream to send data directly to the remote end of the channel. |
InputStream |
getInvertedOut()
Obtains an
InputStream to read received SshConstants.SSH_MSG_CHANNEL_DATA data directly from the
channel. |
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(OutputStream err)
Sets an output stream for the channel to write received
SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA data
to. |
void |
setIn(InputStream in)
Sets an
InputStream that will be read by this channel and forwarded to the remote channel. |
void |
setOut(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 Collection<ClientChannelEvent>> |
updateCurrentChannelState(C state) |
Set<ClientChannelEvent> |
waitFor(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, getPacketValidator, 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, setPacketValidator, 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, removeCloseFutureListenerprotected final AtomicBoolean opened
protected StreamingChannel.Streaming streaming
protected ChannelAsyncOutputStream asyncIn
protected ChannelAsyncInputStream asyncOut
protected ChannelAsyncInputStream asyncErr
protected InputStream in
protected OutputStream invertedIn
protected OutputStream out
protected InputStream invertedOut
protected OutputStream err
protected InputStream invertedErr
protected boolean redirectErrorStream
protected final AtomicReference<Integer> exitStatusHolder
protected final AtomicReference<String> exitSignalHolder
protected int openFailureReason
protected String openFailureMsg
protected String openFailureLang
protected OpenFuture openFuture
protected AbstractClientChannel(String type)
protected AbstractClientChannel(String type, Collection<? extends RequestHandler<Channel>> handlers)
protected void addChannelSignalRequestHandlers(EventNotifier<String> notifier)
public 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 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 InputStream getIn()
public void setIn(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. If the stream should not be closed (for instance, if it is System.in), wrap it in an NoCloseInputStream.
setIn in interface ClientChannelin - an InputStream to be polled and forwardedClientChannel.getInvertedIn()public 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 OutputStream getOut()
public void setOut(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 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 OutputStream getErr()
public void setErr(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 Set<ClientChannelEvent> waitFor(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 Set<ClientChannelEvent> getChannelState()
getChannelState in interface ClientChannelClientChannel.waitFor(Collection, long)protected <C extends Collection<ClientChannelEvent>> C updateCurrentChannelState(C state)
public OpenFuture open() throws IOException
open in interface ClientChannelIOExceptionpublic 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 IOException
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 IOException
doWriteData in class AbstractChannelIOExceptionprotected void doWriteExtendedData(byte[] data,
int off,
long len)
throws IOException
doWriteExtendedData in class AbstractChannelIOExceptionpublic void handleWindowAdjust(Buffer buffer) throws IOException
ChannelSSH_MSG_CHANNEL_WINDOW_ADJUST receivedhandleWindowAdjust in class AbstractChannelbuffer - The rest of the message data Buffer after decoding the channel identifiersIOException - If failed to handle the messageprotected boolean mayWrite()
mayWrite in class AbstractChannelpublic Integer getExitStatus()
getExitStatus in interface ClientChannelnull if not signaledpublic String getExitSignal()
getExitSignal in interface ClientChannelnull if not signaledCopyright © 2008–2024 The Apache Software Foundation. All rights reserved.