Class Window

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.channel.Window
All Implemented Interfaces:
Closeable, AutoCloseable, ChannelHolder
Direct Known Subclasses:
LocalWindow, RemoteWindow

public abstract class Window extends org.apache.sshd.common.util.logging.AbstractLoggingBean implements ChannelHolder, Closeable
A Channel implements a sliding window flow control for data packets (SSH_MSG_CHANNEL_DATA and SSH_MSG_CHANNEL_EXTENDED_DATA packets). Each channel has two windows, a local window describing how much data it is prepared to receive (and the peer is allowed to send), and a remote window that reflects this side's view of the peer's local window. When the local window size is zero, no data should be received; when the remote window size is zero, no data should be sent. Peers update the other's remote window periodically, but at the latest when a window is exhausted, by sending SSH_MSG_CHANNEL_WINDOW_ADJUST messages.
Author:
Apache MINA SSHD Project
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Object
     

    Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean

    log
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Window(Channel channel, boolean isClient)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    void
     
    abstract long
    consume(long len)
    Consume len bytes from the window.
    long
    Consume all bytes from the window.
     
    long
     
    long
     
    long
    Retrieves the current size of the window; i.e., the maximum number of bytes available for consumption via consume(long).
    protected void
    init(long size, long packetSize, org.apache.sshd.common.PropertyResolver resolver)
     
    boolean
     
    protected static Predicate<Window>
    largerThan(long minSize)
     
     
    protected void
    updateSize(long size)
     

    Methods 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, warn

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • lock

      protected final Object lock
  • Constructor Details

    • Window

      protected Window(Channel channel, boolean isClient)
  • Method Details

    • largerThan

      protected static Predicate<Window> largerThan(long minSize)
    • getChannel

      public Channel getChannel()
      Specified by:
      getChannel in interface ChannelHolder
      Returns:
      The associated Channel instance
    • getSize

      public long getSize()
      Retrieves the current size of the window; i.e., the maximum number of bytes available for consumption via consume(long).

      The value is outdated immediately; you cannot rely on

      long toConsume = ...;
      if (toConsume < window.getSize()) {
        window.consume(toConsume); // Might throw an exception if some other thread consumed some space already
      }
      

      not to throw an exception. Use the return value only for informative purposes, such as logging.

      Returns:
      the currently available window size
    • getMaxSize

      public long getMaxSize()
    • getPacketSize

      public long getPacketSize()
    • init

      protected void init(long size, long packetSize, org.apache.sshd.common.PropertyResolver resolver)
    • consume

      public abstract long consume(long len) throws IOException
      Consume len bytes from the window.
      Parameters:
      len - number of bytes to consume
      Returns:
      the number of bytes by which the window was actually reduced
      Throws:
      IOException - if the request cannot be honored
    • consumeAll

      public long consumeAll()
      Consume all bytes from the window.
      Returns:
      the number of bytes consumed
    • updateSize

      protected void updateSize(long size)
    • checkInitialized

      protected void checkInitialized(String location)
    • isOpen

      public boolean isOpen()
    • close

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

      public String toString()
      Overrides:
      toString in class Object