public abstract class AbstractClientChannel extends AbstractChannel implements ClientChannel
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulState
AbstractCloseable.State
AttributeRepository.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, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaled
closeFuture, futureLock, state
log
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM
EMPTY
NONE
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, 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, writePacket
doCloseGracefully, doCloseImmediately
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getClientSession, validateCommandExitStatusCode, waitFor
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, resolveAttribute, writePacket
getSession, getSessionContext
getChannelId
addChannelListener, getChannelListenerProxy, removeChannelListener
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty, isEmpty
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
attributeKeys, getAttribute, getAttributesCount, ofAttributesMap, ofKeyValuePair
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolver
addCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListener
protected 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 ClientChannel
public StreamingChannel.Streaming getStreaming()
getStreaming
in interface StreamingChannel
public void setStreaming(StreamingChannel.Streaming streaming)
setStreaming
in interface StreamingChannel
public IoOutputStream getAsyncIn()
getAsyncIn
in interface ClientChannel
public IoInputStream getAsyncOut()
getAsyncOut
in interface ClientChannel
public IoInputStream getAsyncErr()
getAsyncErr
in interface ClientChannel
public OutputStream getInvertedIn()
ClientChannel
OutputStream
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 ClientChannel
OutputStream
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)
ClientChannel
InputStream
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 ClientChannel
in
- an InputStream
to be polled and forwardedClientChannel.getInvertedIn()
public InputStream getInvertedOut()
ClientChannel
InputStream
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 ClientChannel
InputStream
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)
ClientChannel
SshConstants.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 ClientChannel
out
- the OutputStream
ClientChannel.getInvertedOut()
,
ClientChannel.setRedirectErrorStream(boolean)
public InputStream getInvertedErr()
ClientChannel
InputStream
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 ClientChannel
InputStream
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)
ClientChannel
SshConstants.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 ClientChannel
err
- the OutputStream
ClientChannel.getInvertedErr()
,
ClientChannel.setRedirectErrorStream(boolean)
public boolean isRedirectErrorStream()
public void setRedirectErrorStream(boolean redirectErrorStream)
ClientChannel
ClientChannel.setErr(OutputStream)
has also been called by the time the channel is opened.setRedirectErrorStream
in interface ClientChannel
redirectErrorStream
- whether to redirect the error stream to the output stream.protected Closeable getInnerCloseable()
getInnerCloseable
in class AbstractChannel
public Set<ClientChannelEvent> waitFor(Collection<ClientChannelEvent> mask, long timeout)
ClientChannel
waitFor
in interface ClientChannel
mask
- The ClientChannelEvent
s 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 ClientChannel
ClientChannel.waitFor(Collection, long)
protected <C extends Collection<ClientChannelEvent>> C updateCurrentChannelState(C state)
public OpenFuture open() throws IOException
open
in interface ClientChannel
IOException
public OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer)
Channel
recipient
- 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)
Channel
recipient
- 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
IOException
public void handleOpenFailure(Buffer buffer)
Channel
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 void doWriteData(byte[] data, int off, long len) throws IOException
doWriteData
in class AbstractChannel
IOException
protected void doWriteExtendedData(byte[] data, int off, long len) throws IOException
doWriteExtendedData
in class AbstractChannel
IOException
public void handleWindowAdjust(Buffer buffer) throws IOException
Channel
SSH_MSG_CHANNEL_WINDOW_ADJUST
receivedhandleWindowAdjust
in class AbstractChannel
buffer
- The rest of the message data Buffer
after decoding the channel identifiersIOException
- If failed to handle the messageprotected boolean mayWrite()
mayWrite
in class AbstractChannel
public Integer getExitStatus()
getExitStatus
in interface ClientChannel
null
if not signaledpublic String getExitSignal()
getExitSignal
in interface ClientChannel
null
if not signaledCopyright © 2008–2024 The Apache Software Foundation. All rights reserved.