Class AbstractClientChannel
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,ClientChannel,ClientSessionHolder,AttributeRepository,AttributeStore,Channel,ChannelIdentifier,ChannelListenerManager,StreamingChannel,ChannelStreamWriterResolver,ChannelStreamWriterResolverManager,Closeable,PropertyResolver,SessionContextHolder,SessionHolder<Session>,ExecutorServiceCarrier
- Direct Known Subclasses:
AgentForwardedChannel,ChannelDirectTcpip,ChannelForwardedX11,ChannelSession,TcpipClientChannel
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.sshd.common.channel.AbstractChannel
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulState, AbstractChannel.PacketValidatorNested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>Nested classes/interfaces inherited from interface org.apache.sshd.common.channel.StreamingChannel
StreamingChannel.Streaming -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChannelAsyncInputStreamprotected ChannelAsyncOutputStreamprotected ChannelAsyncInputStreamprivate final Stringprotected OutputStreamprotected final AtomicReference<String> protected final AtomicReference<Integer> protected InputStreamprotected InputStreamprotected OutputStreamprotected InputStreamprivate static final InputStreamprotected final AtomicBooleanprotected Stringprotected Stringprotected intprotected OpenFutureprotected OutputStreamprotected booleanprotected StreamingChannel.StreamingFields inherited from class org.apache.sshd.common.channel.AbstractChannel
channelListenerProxy, channelListeners, closeSignaled, DEFAULT_PACKET_VALIDATOR, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaledFields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.common.channel.Channel
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMFields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONEFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractClientChannel(String type) protectedAbstractClientChannel(String type, Collection<? extends RequestHandler<Channel>> handlers) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddChannelSignalRequestHandlers(EventNotifier<String> notifier) protected abstract voiddoOpen()protected voiddoWriteData(byte[] data, int off, long len) protected voiddoWriteExtendedData(byte[] data, int off, long len) getErr()getIn()protected CloseableObtains anInputStreamto read receivedSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata directly from the channel.Obtains anOutputStreamto send data directly to the remote end of the channel.Obtains anInputStreamto read receivedSshConstants.SSH_MSG_CHANNEL_DATAdata directly from the channel.getOut()voidhandleOpenFailure(Buffer buffer) For a client channel, this method will be called internally by the session when the server has rejected this channel opening.voidhandleOpenSuccess(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.voidhandleWindowAdjust(Buffer buffer) Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUSTreceivedbooleanprotected booleanmayWrite()open()For a server channel, this method will actually open the channelvoidsetErr(OutputStream err) Sets an output stream for the channel to write receivedSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata to.voidsetIn(InputStream in) Sets anInputStreamthat will be read by this channel and forwarded to the remote channel.voidsetOut(OutputStream out) Sets an output stream for the channel to write receivedSshConstants.SSH_MSG_CHANNEL_DATAdata to.voidsetRedirectErrorStream(boolean redirectErrorStream) Defines whether to redirect the error stream into the output stream; has no effect ifClientChannel.setErr(OutputStream)has also been called by the time the channel is opened.voidsetStreaming(StreamingChannel.Streaming streaming) protected <C extends Collection<ClientChannelEvent>>
CupdateCurrentChannelState(C state) waitFor(Collection<ClientChannelEvent> mask, long timeout) Waits until any of the specified events in the mask is signaledMethods inherited from class org.apache.sshd.common.channel.AbstractChannel
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, writePacketMethods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenerMethods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCountMethods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeMethods inherited from interface org.apache.sshd.common.channel.Channel
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, writePacketMethods inherited from interface org.apache.sshd.common.channel.ChannelIdentifier
getChannelIdMethods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface org.apache.sshd.client.channel.ClientChannel
getClientSession, waitForMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface org.apache.sshd.common.session.SessionHolder
getSession, getSessionContext
-
Field Details
-
NULL_INPUT_STREAM
-
opened
-
streaming
-
asyncIn
-
asyncOut
-
asyncErr
-
in
-
invertedIn
-
out
-
invertedOut
-
err
-
invertedErr
-
redirectErrorStream
protected boolean redirectErrorStream -
exitStatusHolder
-
exitSignalHolder
-
openFailureReason
protected int openFailureReason -
openFailureMsg
-
openFailureLang
-
openFuture
-
channelType
-
-
Constructor Details
-
AbstractClientChannel
-
AbstractClientChannel
protected AbstractClientChannel(String type, Collection<? extends RequestHandler<Channel>> handlers)
-
-
Method Details
-
addChannelSignalRequestHandlers
-
getChannelType
- Specified by:
getChannelTypein interfaceClientChannel- Returns:
- The type of channel reported when it was created
-
getStreaming
- Specified by:
getStreamingin interfaceStreamingChannel
-
setStreaming
- Specified by:
setStreamingin interfaceStreamingChannel
-
getAsyncIn
- Specified by:
getAsyncInin interfaceClientChannel
-
getAsyncOut
- Specified by:
getAsyncOutin interfaceClientChannel
-
getAsyncErr
- Specified by:
getAsyncErrin interfaceClientChannel
-
getInvertedIn
Description copied from interface:ClientChannelObtains anOutputStreamto send data directly to the remote end of the channel. This can be used instead of usingClientChannel.setIn(InputStream)method and having the channel polling for data in that stream.When the channel closes, it will
closethe returned stream.This method should be called only after the channel has been opened.
- Specified by:
getInvertedInin interfaceClientChannel- Returns:
- an
OutputStreamfor sending data, ornullif an input stream was set viaClientChannel.setIn(InputStream) - See Also:
-
getIn
-
setIn
Description copied from interface:ClientChannelSets anInputStreamthat 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 theClientChannel.getInvertedIn()method instead and write data directly.The stream must be set before the channel is opened. When the channel closes, it will
closethe given stream.- Specified by:
setInin interfaceClientChannel- Parameters:
in- anInputStreamto be polled and forwarded- See Also:
-
getInvertedOut
Description copied from interface:ClientChannelObtains anInputStreamto read receivedSshConstants.SSH_MSG_CHANNEL_DATAdata directly from the channel. This is an alternative toClientChannel.setOut(OutputStream). If the error stream is redirected to the output stream viasetRedirectErrorStream(true), this stream will also receiveSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata.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.
- Specified by:
getInvertedOutin interfaceClientChannel- Returns:
- an
InputStreamfor reading received data, ornullif an output stream was set viaClientChannel.setOut(OutputStream) - See Also:
-
getOut
-
setOut
Description copied from interface:ClientChannelSets an output stream for the channel to write receivedSshConstants.SSH_MSG_CHANNEL_DATAdata to. For remote command execution, this is typically the remote command'sstdout. If the error stream is redirected to the output stream viasetRedirectErrorStream(true), this stream will also receiveSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata.The stream must be set before the channel is opened. When the channel closes, it will
closethe 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
InputStreamobtained viaClientChannel.getInvertedOut().- Specified by:
setOutin interfaceClientChannel- Parameters:
out- theOutputStream- See Also:
-
getInvertedErr
Description copied from interface:ClientChannelObtains anInputStreamto read receivedSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata directly from the channel. This is an alternative toClientChannel.setErr(OutputStream). If the error stream is redirected to the output stream viasetRedirectErrorStream(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.
- Specified by:
getInvertedErrin interfaceClientChannel- Returns:
- an
InputStreamfor reading received data, ornullif an output stream was set viaClientChannel.setErr(OutputStream) - See Also:
-
getErr
-
setErr
Description copied from interface:ClientChannelSets an output stream for the channel to write receivedSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata to. For remote command execution, this is typically the remote command'sstderr.The stream must be set before the channel is opened. When the channel closes, it will
closethe 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
InputStreamobtained viaClientChannel.getInvertedErr(). (Or it might forward the data to the output stream ifsetRedirectErrorStream(true)is set.)- Specified by:
setErrin interfaceClientChannel- Parameters:
err- theOutputStream- See Also:
-
isRedirectErrorStream
public boolean isRedirectErrorStream() -
setRedirectErrorStream
public void setRedirectErrorStream(boolean redirectErrorStream) Description copied from interface:ClientChannelDefines whether to redirect the error stream into the output stream; has no effect ifClientChannel.setErr(OutputStream)has also been called by the time the channel is opened.- Specified by:
setRedirectErrorStreamin interfaceClientChannel- Parameters:
redirectErrorStream- whether to redirect the error stream to the output stream.
-
getInnerCloseable
- Overrides:
getInnerCloseablein classAbstractChannel
-
waitFor
Description copied from interface:ClientChannelWaits until any of the specified events in the mask is signaled- Specified by:
waitForin interfaceClientChannel- Parameters:
mask- TheClientChannelEvents masktimeout- The timeout to wait (msec.) - if non-positive then forever- Returns:
- The actual signaled event - includes
ClientChannelEvent.TIMEOUTif timeout expired before the expected event was signaled
-
getChannelState
- Specified by:
getChannelStatein interfaceClientChannel- Returns:
- A snapshot of the current channel state
- See Also:
-
updateCurrentChannelState
-
open
- Specified by:
openin interfaceClientChannel- Throws:
IOException
-
open
Description copied from interface:ChannelFor a server channel, this method will actually open the channel- Specified by:
openin interfaceChannel- Parameters:
recipient- Recipient identifier (UINT32 represented as along)rwSize- Read/Write window size (uint32)packetSize- Preferred maximum packet size (uint32)buffer- IncomingBufferthat triggered the call. Note: the buffer's read position is exactly after the information that read to this call was decoded- Returns:
- An
OpenFuturefor the channel open request
-
handleOpenSuccess
Description copied from interface:ChannelFor a client channel, this method will be called internally by the session when the confirmation has been received.- Specified by:
handleOpenSuccessin interfaceChannel- Parameters:
recipient- Recipient identifier (UINT32 represented as along)rwSize- Read/Write window size (uint32)packetSize- Preferred maximum packet size (uint32)buffer- IncomingBufferthat triggered the call. Note: the buffer's read position is exactly after the information that read to this call was decoded
-
doOpen
- Throws:
IOException
-
handleOpenFailure
Description copied from interface:ChannelFor a client channel, this method will be called internally by the session when the server has rejected this channel opening.- Specified by:
handleOpenFailurein interfaceChannel- Parameters:
buffer- IncomingBufferthat triggered the call. Note: the buffer's read position is exactly after the information that read to this call was decoded
-
doWriteData
- Specified by:
doWriteDatain classAbstractChannel- Throws:
IOException
-
doWriteExtendedData
- Specified by:
doWriteExtendedDatain classAbstractChannel- Throws:
IOException
-
handleWindowAdjust
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_WINDOW_ADJUSTreceived- Specified by:
handleWindowAdjustin interfaceChannel- Overrides:
handleWindowAdjustin classAbstractChannel- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
IOException- If failed to handle the message
-
mayWrite
protected boolean mayWrite()- Overrides:
mayWritein classAbstractChannel
-
getExitStatus
- Specified by:
getExitStatusin interfaceClientChannel- Returns:
- The signaled exit status via "exit-status" request -
nullif not signaled
-
getExitSignal
- Specified by:
getExitSignalin interfaceClientChannel- Returns:
- The signaled exit signal via "exit-signal" -
nullif not signaled
-