Package org.apache.sshd.common.channel
Class Window
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.common.channel.Window
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,ChannelHolder
public class Window extends AbstractLoggingBean implements Channel, ChannelHolder
A Window for a given channel. Windows are used to not overflow the client or server when sending datas. Both clients and servers have a local and remote window and won't send anymore data until the window has been expanded. When the local window is- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description static Predicate<Window>SPACE_AVAILABLE_PREDICATEDefaultPredicateused to test if space became available-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description Window(AbstractChannel channel, Object lock, boolean client, boolean local)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheck(long maxFree)protected voidcheckInitialized(String location)voidclose()voidconsume(long len)voidconsumeAndCheck(long len)voidexpand(int window)AbstractChannelgetChannel()longgetMaxSize()longgetPacketSize()longgetSize()voidinit(long size, long packetSize, PropertyResolver resolver)voidinit(PropertyResolver resolver)booleanisOpen()StringtoString()protected voidupdateSize(long size)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 sizeprotected 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 expires
-
-
-
Constructor Detail
-
Window
public Window(AbstractChannel channel, Object lock, boolean client, boolean local)
-
-
Method Detail
-
getChannel
public AbstractChannel getChannel()
- Specified by:
getChannelin interfaceChannelHolder- Returns:
- The associated
Channelinstance
-
getSize
public long getSize()
-
getMaxSize
public long getMaxSize()
-
getPacketSize
public long getPacketSize()
-
init
public void init(PropertyResolver resolver)
-
init
public void init(long size, long packetSize, PropertyResolver resolver)
-
expand
public void expand(int window)
-
consume
public void consume(long len)
-
consumeAndCheck
public void consumeAndCheck(long len) throws IOException- Throws:
IOException
-
check
public void check(long maxFree) throws IOException- Throws:
IOException
-
waitAndConsume
public void waitAndConsume(long len, long maxWaitTime) throws InterruptedException, WindowClosedException, SocketTimeoutExceptionWaits 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:
waitForCondition(Predicate, Duration),consume(long)
-
waitAndConsume
public void waitAndConsume(long len, Duration maxWaitTime) throws InterruptedException, WindowClosedException, SocketTimeoutExceptionWaits for enough data to become available to consume the specified size- 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:
waitForCondition(Predicate, Duration),consume(long)
-
waitForSpace
public long waitForSpace(long maxWaitTime) throws InterruptedException, WindowClosedException, SocketTimeoutExceptionWaits 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:
waitForCondition(Predicate, Duration)
-
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(Predicate, Duration)
-
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:
isOpen()
-
updateSize
protected void updateSize(long size)
-
checkInitialized
protected void checkInitialized(String location)
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-