Class ThrottlingChannelStreamWriter

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.contrib.common.channel.throttle.ThrottlingChannelStreamWriter
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, EventListener, ChannelStreamWriter, SshFutureListener<IoWriteFuture>, SshdEventListener

public class ThrottlingChannelStreamWriter extends AbstractLoggingBean implements ChannelStreamWriter, SshFutureListener<IoWriteFuture>
A ChannelStreamWriter delegate implementation that "throttles" the output by having a limit on the outstanding packets that have not been sent yet. The writePacket implementation make sure that the limit has not been exceeded - if so, then it waits until pending packets have been successfully sent before sending the next packet. Note: closing the throttler does not close the delegate writer
  • Field Details

    • WAIT_TIME

      public static final Property<Duration> WAIT_TIME
      Timeout (seconds) for throttling packet writer to wait for pending packets send
    • MAX_PEND_COUNT

      public static final Property<Integer> MAX_PEND_COUNT
      Max. pending packets count
    • delegate

      private final ChannelStreamWriter delegate
    • maxPendingPackets

      private final int maxPendingPackets
    • maxWait

      private final long maxWait
    • open

      private final AtomicBoolean open
    • availableCount

      private final AtomicInteger availableCount
  • Constructor Details

    • ThrottlingChannelStreamWriter

      public ThrottlingChannelStreamWriter(Channel channel)
    • ThrottlingChannelStreamWriter

      public ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, PropertyResolver resolver)
    • ThrottlingChannelStreamWriter

      public ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, TimeUnit waitUnit, long waitCount)
    • ThrottlingChannelStreamWriter

      public ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, Duration maxWait)
    • ThrottlingChannelStreamWriter

      public ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, long maxWait)
  • Method Details

    • getDelegate

      public ChannelStreamWriter getDelegate()
    • getMaxPendingPackets

      public int getMaxPendingPackets()
    • getAvailablePacketsCount

      public int getAvailablePacketsCount()
    • getMaxWait

      public long getMaxWait()
    • isOpen

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

      public IoWriteFuture writeData(Buffer buffer) throws IOException
      Description copied from interface: ChannelStreamWriter
      Encode and send the given data packet buffer. Note: the buffer has to have 5 bytes free at the beginning to allow the encoding to take place. Also, the write position of the buffer has to be set to the position of the last byte to write.
      Specified by:
      writeData in interface ChannelStreamWriter
      Parameters:
      buffer - the buffer to encode and send. NOTE: the buffer must not be touched until the returned write future is completed.
      Returns:
      An IoWriteFuture that can be used to check when the packet has actually been sent
      Throws:
      IOException - if an error occurred when encoding or sending the packet
    • operationComplete

      public void operationComplete(IoWriteFuture 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<IoWriteFuture>
      Parameters:
      future - The source SshFuture which called this callback.
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object