Class RemoteWindow
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.channel.Window
org.apache.sshd.common.channel.RemoteWindow
- All Implemented Interfaces:
Closeable, AutoCloseable, ChannelHolder
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.- Author:
- Apache MINA SSHD Project
-
Field Summary
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongconsume(long len) Consumelenbytes from the window.voidexpand(long increment) voidinit(long size, long packetSize, org.apache.sshd.common.PropertyResolver resolver) Initializes theRemoteWindowwith the packet and window sizes received from the peer.voidwaitAndConsume(long len, long maxWaitTime) Waits for enough data to become available to consume the specified sizevoidwaitAndConsume(long len, Duration maxWaitTime) Waits for enough data to become available to consume the specified size, then consumes it.protected voidwaitForCondition(Predicate<? super Window> predicate, Duration maxWaitTime) Waits up to a specified amount of time for a condition to be satisfied and signaled via the lock.longwaitForSpace(long maxWaitTime) Waits until some data becomes available or timeout expireslongwaitForSpace(Duration maxWaitTime) Waits until some data becomes available or timeout expiresMethods inherited from class Window
checkInitialized, close, consumeAll, getChannel, getMaxSize, getPacketSize, getSize, isOpen, largerThan, toString, updateSizeMethods 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
-
Constructor Details
-
RemoteWindow
-
-
Method Details
-
init
public void init(long size, long packetSize, org.apache.sshd.common.PropertyResolver resolver) Initializes theRemoteWindowwith the packet and window sizes received from the peer. -
consume
public long consume(long len) Consumelenbytes from the window.Consumes at most the available space in the window. If
len> the available space, less thanlenbytes are consumed.Also, caps the amount of window space consumed to
Math.min(getMaxSize(), getPacketSize()).Consuming space from the window is a promise to send that much data over an SSH channel. If not all data can be written, this promise has to be retracted by calling
expand(long)with the number of bytes not written. -
expand
public void expand(long increment) -
waitAndConsume
public void waitAndConsume(long len, long maxWaitTime) throws InterruptedException, WindowClosedException, SocketTimeoutException Waits for enough data to become available to consume the specified size- Parameters:
len- Size of data to consumemaxWaitTime- Max. time (millis) to wait for enough data to become available- Throws:
InterruptedException- If interrupted while waitingWindowClosedException- If window closed while waitingSocketTimeoutException- If timeout expired before enough data became available- See Also:
-
waitAndConsume
public void waitAndConsume(long len, Duration maxWaitTime) throws InterruptedException, WindowClosedException, SocketTimeoutException Waits for enough data to become available to consume the specified size, then consumes it.- Parameters:
len- Size of data to consumemaxWaitTime- Max. time to wait for enough data to become available- Throws:
InterruptedException- If interrupted while waitingWindowClosedException- If window closed while waitingSocketTimeoutException- If timeout expired before enough data became available- See Also:
-
waitForSpace
public long waitForSpace(long maxWaitTime) throws InterruptedException, WindowClosedException, 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:
InterruptedException- If interrupted while waitingWindowClosedException- If window closed while waitingSocketTimeoutException- If timeout expired before space became available- See Also:
-
waitForSpace
public long waitForSpace(Duration maxWaitTime) throws InterruptedException, WindowClosedException, 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:
InterruptedException- If interrupted while waitingWindowClosedException- If window closed while waitingSocketTimeoutException- If timeout expired before space became available- See Also:
-
waitForCondition
protected void waitForCondition(Predicate<? super Window> predicate, Duration maxWaitTime) throws WindowClosedException, InterruptedException, 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- ThePredicateto check if the condition has been satisfied - the argument to the predicate isthisreferencemaxWaitTime- Max. time to wait for the condition to be satisfied- Throws:
WindowClosedException- If window closed while waitingInterruptedException- If interrupted while waitingSocketTimeoutException- If timeout expired before condition was satisfied- See Also:
-