Class AbstractClientChannel

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.util.closeable.IoBaseCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.util.closeable.AbstractInnerCloseable
org.apache.sshd.common.channel.AbstractChannel
org.apache.sshd.client.channel.AbstractClientChannel
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ClientChannel, ClientSessionHolder, org.apache.sshd.common.AttributeRepository, org.apache.sshd.common.AttributeStore, Channel, ChannelIdentifier, ChannelListenerManager, StreamingChannel, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, org.apache.sshd.common.Closeable, org.apache.sshd.common.PropertyResolver, org.apache.sshd.common.session.SessionContextHolder, SessionHolder<Session>, org.apache.sshd.common.util.threads.ExecutorServiceCarrier
Direct Known Subclasses:
AgentForwardedChannel, AgentForwardedChannel, AsyncCapableClientChannel, ChannelForwardedX11, TcpipClientChannel

public abstract class AbstractClientChannel extends AbstractChannel implements ClientChannel
TODO Add javadoc
Author:
Apache MINA SSHD Project
  • Field Details

  • Constructor Details

  • Method Details

    • addChannelSignalRequestHandlers

      protected void addChannelSignalRequestHandlers(org.apache.sshd.common.util.EventNotifier<String> notifier)
    • getChannelType

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

      public StreamingChannel.Streaming getStreaming()
      Specified by:
      getStreaming in interface StreamingChannel
    • setStreaming

      public void setStreaming(StreamingChannel.Streaming streaming)
      Specified by:
      setStreaming in interface StreamingChannel
    • getAsyncIn

      public org.apache.sshd.common.io.IoOutputStream getAsyncIn()
      Specified by:
      getAsyncIn in interface ClientChannel
    • getAsyncOut

      public org.apache.sshd.common.io.IoInputStream getAsyncOut()
      Specified by:
      getAsyncOut in interface ClientChannel
    • getAsyncErr

      public org.apache.sshd.common.io.IoInputStream getAsyncErr()
      Specified by:
      getAsyncErr in interface ClientChannel
    • getInvertedIn

      public OutputStream getInvertedIn()
      Description copied from interface: ClientChannel
      Obtains an 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.

      Specified by:
      getInvertedIn in interface ClientChannel
      Returns:
      an OutputStream for sending data, or null if an input stream was set via ClientChannel.setIn(InputStream)
      See Also:
    • getIn

      public InputStream getIn()
    • setIn

      public void setIn(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. If the stream should not be closed (for instance, if it is System.in), wrap it in an NoCloseInputStream.

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

      public 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:
    • getOut

      public OutputStream getOut()
    • setOut

      public void setOut(OutputStream out)
      Description copied from interface: ClientChannel
      Sets an output stream for the channel to write received 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().

      Specified by:
      setOut in interface ClientChannel
      Parameters:
      out - the OutputStream
      See Also:
    • getInvertedErr

      public 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:
    • getErr

      public OutputStream getErr()
    • setErr

      public void setErr(OutputStream err)
      Description copied from interface: ClientChannel
      Sets an output stream for the channel to write received 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.)

      Specified by:
      setErr in interface ClientChannel
      Parameters:
      err - the OutputStream
      See Also:
    • 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.
    • getInnerCloseable

      protected org.apache.sshd.common.Closeable getInnerCloseable()
      Overrides:
      getInnerCloseable in class AbstractChannel
    • waitFor

      public Set<ClientChannelEvent> waitFor(Collection<ClientChannelEvent> mask, long timeout)
      Description copied from interface: ClientChannel
      Waits until any of the specified events in the mask is signaled
      Specified by:
      waitFor in interface ClientChannel
      Parameters:
      mask - The ClientChannelEvents mask
      timeout - The timeout to wait (msec.) - if non-positive then forever
      Returns:
      The actual signaled event - includes ClientChannelEvent.TIMEOUT if timeout expired before the expected event was signaled
    • getChannelState

      public Set<ClientChannelEvent> getChannelState()
      Specified by:
      getChannelState in interface ClientChannel
      Returns:
      A snapshot of the current channel state
      See Also:
    • updateCurrentChannelState

      protected <C extends Collection<ClientChannelEvent>> C updateCurrentChannelState(C state)
    • open

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

      public OpenFuture open(long recipient, long rwSize, long packetSize, org.apache.sshd.common.util.buffer.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, org.apache.sshd.common.util.buffer.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 IOException
      Throws:
      IOException
    • handleOpenFailure

      public void handleOpenFailure(org.apache.sshd.common.util.buffer.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 IOException
      Specified by:
      doWriteData in class AbstractChannel
      Throws:
      IOException
    • doWriteExtendedData

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

      public void handleWindowAdjust(org.apache.sshd.common.util.buffer.Buffer buffer) throws 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:
      IOException - If failed to handle the message
    • mayWrite

      protected boolean mayWrite()
      Overrides:
      mayWrite in class AbstractChannel
    • getExitStatus

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

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