Class RemoteWindow

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, ChannelHolder

    public class RemoteWindow
    extends Window
    A Window reflecting this side's view of the peer's LocalWindow. A RemoteWindow is initialized when the peer announces its packet and window sizes in the initial message exchange when opening a channel. Whenever this side wants to send data, it checks whether the remote window has still enough space; if not, it sends only as much data as possible. When data is sent, the remote window size is reduced by the number of data bytes sent. When the window size drops to zero, no data is sent at all, and this side will have to wait for an SSH_MSG_CHANNEL_WINDOW_ADJUST message from the peer, which will increase the available window size again.
    • Field Detail

      • SPACE_AVAILABLE_PREDICATE

        private static final java.util.function.Predicate<Window> SPACE_AVAILABLE_PREDICATE
        Default Predicate used to test if space became available
    • Constructor Detail

      • RemoteWindow

        public RemoteWindow​(Channel channel,
                            boolean isClient)
    • Method Detail

      • init

        public void init​(long size,
                         long packetSize,
                         PropertyResolver resolver)
        Initializes the RemoteWindow with the packet and window sizes received from the peer.
        Overrides:
        init in class Window
        Parameters:
        size - the initial window size
        packetSize - the peer's advertised maximum packet size
        resolver - to access properties
      • consume

        public void consume​(long len)
        Specified by:
        consume in class Window
      • expand

        public void expand​(long increment)
      • waitAndConsume

        public void waitAndConsume​(long len,
                                   long maxWaitTime)
                            throws java.lang.InterruptedException,
                                   WindowClosedException,
                                   java.net.SocketTimeoutException
        Waits for enough data to become available to consume the specified size
        Parameters:
        len - Size of data to consume
        maxWaitTime - Max. time (millis) to wait for enough data to become available
        Throws:
        java.lang.InterruptedException - If interrupted while waiting
        WindowClosedException - If window closed while waiting
        java.net.SocketTimeoutException - If timeout expired before enough data became available
        See Also:
        waitForCondition(Predicate, Duration), consume(long)
      • waitAndConsume

        public void waitAndConsume​(long len,
                                   java.time.Duration maxWaitTime)
                            throws java.lang.InterruptedException,
                                   WindowClosedException,
                                   java.net.SocketTimeoutException
        Waits for enough data to become available to consume the specified size
        Parameters:
        len - Size of data to consume
        maxWaitTime - Max. time to wait for enough data to become available
        Throws:
        java.lang.InterruptedException - If interrupted while waiting
        WindowClosedException - If window closed while waiting
        java.net.SocketTimeoutException - If timeout expired before enough data became available
        See Also:
        waitForCondition(Predicate, Duration), consume(long)
      • waitForSpace

        public long waitForSpace​(long maxWaitTime)
                          throws java.lang.InterruptedException,
                                 WindowClosedException,
                                 java.net.SocketTimeoutException
        Waits until some data becomes available or timeout expires
        Parameters:
        maxWaitTime - Max. time (millis) to wait for space to become available
        Returns:
        Amount of available data - always positive
        Throws:
        java.lang.InterruptedException - If interrupted while waiting
        WindowClosedException - If window closed while waiting
        java.net.SocketTimeoutException - If timeout expired before space became available
        See Also:
        waitForCondition(Predicate, Duration)
      • waitForSpace

        public long waitForSpace​(java.time.Duration maxWaitTime)
                          throws java.lang.InterruptedException,
                                 WindowClosedException,
                                 java.net.SocketTimeoutException
        Waits until some data becomes available or timeout expires
        Parameters:
        maxWaitTime - Max. time to wait for space to become available
        Returns:
        Amount of available data - always positive
        Throws:
        java.lang.InterruptedException - If interrupted while waiting
        WindowClosedException - If window closed while waiting
        java.net.SocketTimeoutException - If timeout expired before space became available
        See Also:
        waitForCondition(Predicate, Duration)
      • waitForCondition

        protected void waitForCondition​(java.util.function.Predicate<? super Window> predicate,
                                        java.time.Duration maxWaitTime)
                                 throws WindowClosedException,
                                        java.lang.InterruptedException,
                                        java.net.SocketTimeoutException
        Waits up to a specified amount of time for a condition to be satisfied and signaled via the lock. Note: assumes that lock is acquired when this method is called.
        Parameters:
        predicate - The Predicate to check if the condition has been satisfied - the argument to the predicate is this reference
        maxWaitTime - Max. time to wait for the condition to be satisfied
        Throws:
        WindowClosedException - If window closed while waiting
        java.lang.InterruptedException - If interrupted while waiting
        java.net.SocketTimeoutException - If timeout expired before condition was satisfied
        See Also:
        Window.isOpen()