Class AbstractClientChannel

    • Field Detail

      • NULL_INPUT_STREAM

        private static final java.io.InputStream NULL_INPUT_STREAM
      • opened

        protected final java.util.concurrent.atomic.AtomicBoolean opened
      • in

        protected java.io.InputStream in
      • invertedIn

        protected java.io.OutputStream invertedIn
      • out

        protected java.io.OutputStream out
      • invertedOut

        protected java.io.InputStream invertedOut
      • err

        protected java.io.OutputStream err
      • invertedErr

        protected java.io.InputStream invertedErr
      • redirectErrorStream

        protected boolean redirectErrorStream
      • exitStatusHolder

        protected final java.util.concurrent.atomic.AtomicReference<java.lang.Integer> exitStatusHolder
      • exitSignalHolder

        protected final java.util.concurrent.atomic.AtomicReference<java.lang.String> exitSignalHolder
      • openFailureReason

        protected int openFailureReason
      • openFailureMsg

        protected java.lang.String openFailureMsg
      • openFailureLang

        protected java.lang.String openFailureLang
      • channelType

        private final java.lang.String channelType
    • Constructor Detail

      • AbstractClientChannel

        protected AbstractClientChannel​(java.lang.String type)
      • AbstractClientChannel

        protected AbstractClientChannel​(java.lang.String type,
                                        java.util.Collection<? extends RequestHandler<Channel>> handlers)
    • Method Detail

      • addChannelSignalRequestHandlers

        protected void addChannelSignalRequestHandlers​(EventNotifier<java.lang.String> notifier)
      • getChannelType

        public java.lang.String getChannelType()
        Specified by:
        getChannelType in interface ClientChannel
        Returns:
        The type of channel reported when it was created
      • getIn

        public java.io.InputStream getIn()
      • setIn

        public void setIn​(java.io.InputStream in)
        Description copied from interface: ClientChannel
        Sets an 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.

        Specified by:
        setIn in interface ClientChannel
        Parameters:
        in - an InputStream to be polled and forwarded
        See Also:
        ClientChannel.getInvertedIn()
      • getInvertedOut

        public java.io.InputStream getInvertedOut()
        Description copied from interface: ClientChannel
        Obtains an 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.

        Specified by:
        getInvertedOut in interface ClientChannel
        Returns:
        an InputStream for reading received data, or null if an output stream was set via ClientChannel.setOut(OutputStream)
        See Also:
        ClientChannel.setOut(OutputStream), ClientChannel.setRedirectErrorStream(boolean)
      • getOut

        public java.io.OutputStream getOut()
      • getInvertedErr

        public java.io.InputStream getInvertedErr()
        Description copied from interface: ClientChannel
        Obtains an 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.

        Specified by:
        getInvertedErr in interface ClientChannel
        Returns:
        an InputStream for reading received data, or null if an output stream was set via ClientChannel.setErr(OutputStream)
        See Also:
        ClientChannel.setErr(OutputStream), ClientChannel.setRedirectErrorStream(boolean)
      • getErr

        public java.io.OutputStream getErr()
      • isRedirectErrorStream

        public boolean isRedirectErrorStream()
      • setRedirectErrorStream

        public void setRedirectErrorStream​(boolean redirectErrorStream)
        Description copied from interface: ClientChannel
        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.
        Specified by:
        setRedirectErrorStream in interface ClientChannel
        Parameters:
        redirectErrorStream - whether to redirect the error stream to the output stream.
      • updateCurrentChannelState

        protected <C extends java.util.Collection<ClientChannelEvent>> C updateCurrentChannelState​(C state)
      • open

        public OpenFuture open()
                        throws java.io.IOException
        Specified by:
        open in interface ClientChannel
        Throws:
        java.io.IOException
      • open

        public OpenFuture open​(long recipient,
                               long rwSize,
                               long packetSize,
                               Buffer buffer)
        Description copied from interface: Channel
        For a server channel, this method will actually open the channel
        Specified by:
        open in interface Channel
        Parameters:
        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 decoded
        Returns:
        An OpenFuture for the channel open request
      • handleOpenSuccess

        public void handleOpenSuccess​(long recipient,
                                      long rwSize,
                                      long packetSize,
                                      Buffer buffer)
        Description copied from interface: Channel
        For a client channel, this method will be called internally by the session when the confirmation has been received.
        Specified by:
        handleOpenSuccess in interface Channel
        Parameters:
        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 decoded
      • doOpen

        protected abstract void doOpen()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • handleOpenFailure

        public void handleOpenFailure​(Buffer buffer)
        Description copied from interface: Channel
        For a client channel, this method will be called internally by the session when the server has rejected this channel opening.
        Specified by:
        handleOpenFailure in interface Channel
        Parameters:
        buffer - Incoming Buffer that triggered the call. Note: the buffer's read position is exactly after the information that read to this call was decoded
      • doWriteData

        protected void doWriteData​(byte[] data,
                                   int off,
                                   long len)
                            throws java.io.IOException
        Specified by:
        doWriteData in class AbstractChannel
        Throws:
        java.io.IOException
      • doWriteExtendedData

        protected void doWriteExtendedData​(byte[] data,
                                           int off,
                                           long len)
                                    throws java.io.IOException
        Specified by:
        doWriteExtendedData in class AbstractChannel
        Throws:
        java.io.IOException
      • handleWindowAdjust

        public void handleWindowAdjust​(Buffer buffer)
                                throws java.io.IOException
        Description copied from interface: Channel
        Invoked when SSH_MSG_CHANNEL_WINDOW_ADJUST received
        Specified by:
        handleWindowAdjust in interface Channel
        Overrides:
        handleWindowAdjust in class AbstractChannel
        Parameters:
        buffer - The rest of the message data Buffer after decoding the channel identifiers
        Throws:
        java.io.IOException - If failed to handle the message
      • getExitStatus

        public java.lang.Integer getExitStatus()
        Specified by:
        getExitStatus in interface ClientChannel
        Returns:
        The signaled exit status via "exit-status" request - null if not signaled
      • getExitSignal

        public java.lang.String getExitSignal()
        Specified by:
        getExitSignal in interface ClientChannel
        Returns:
        The signaled exit signal via "exit-signal" - null if not signaled