Class ClientChannelPendingMessagesQueue

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.client.channel.ClientChannelPendingMessagesQueue
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, EventListener, ClientChannelHolder, ChannelHolder, SshFutureListener<OpenFuture>, SshdEventListener

public class ClientChannelPendingMessagesQueue extends AbstractLoggingBean implements SshFutureListener<OpenFuture>, Channel, ClientChannelHolder
This is a specialized SshFutureListener that is used to enqueue data that is sent while the channel is being set-up, so that when it is established it will send them in the same order as they have been received. It also serves as a "backstop" in case session is closed (normally) while the packets as still being written.
  • Field Details

  • Constructor Details

    • ClientChannelPendingMessagesQueue

      public ClientChannelPendingMessagesQueue(ClientChannel channel)
  • Method Details

    • getClientChannel

      public ClientChannel getClientChannel()
      Specified by:
      getClientChannel in interface ClientChannelHolder
      Returns:
      The underlying ClientChannel used
    • getCompletedFuture

      public OpenFuture getCompletedFuture()
      Returns:
      An internal OpenFuture that can be used to wait for all internal pending messages to be flushed before actually signaling that operation is complete
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface Channel
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • markClosed

      protected boolean markClosed()
      Marks the queue as closed
      Returns:
      true if was open and now is closed
    • handleIncomingMessage

      public int handleIncomingMessage(Buffer buffer, Consumer<? super Throwable> errHandler) throws IOException
      Checks if the future is already open and manages the message handling accordingly:

      • If channel is not open yet, it enqueues the request
      • If channel is open but there are still pending messages not yet written out, it will wait for them to be written (or exception signaled) before proceeding to write out the incoming message.
      • Otherwise (i.e., channel is open and no pending messages yet) it will write the message to the underlying channel immediately.
      Parameters:
      buffer - The message Buffer
      errHandler - The error handler to invoke it had to enqueue the message and was unsuccessful in writing it. Must be non-null if future not open yet. Otherwise, if null and exception occurs it will be simple re-thrown
      Returns:
      The total number of still pending messages - zero if none and message was written (either immediately or after waiting for the pending ones to be written).
      Throws:
      IOException - If wrote the message directly, encountered an error and no handler was provided.
    • writeMessage

      protected void writeMessage(Buffer buffer, Consumer<? super IOException> errHandler) throws IOException
      Throws:
      IOException
    • operationComplete

      public void operationComplete(OpenFuture future)
      Description copied from interface: SshFutureListener
      Invoked when the operation associated with the SshFuture has been completed even if you add the listener after the completion.
      Specified by:
      operationComplete in interface SshFutureListener<OpenFuture>
      Parameters:
      future - The source SshFuture which called this callback.
    • flushPendingQueue

      protected void flushPendingQueue()
    • markCompletionSuccessful

      protected OpenFuture markCompletionSuccessful()
    • markCompletionException

      protected OpenFuture markCompletionException(Throwable err)
    • clearPendingQueue

      protected int clearPendingQueue()
    • toString

      public String toString()
      Overrides:
      toString in class Object