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 Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerprivate final ChannelStreamWriterMax.private final intprivate final longprivate final AtomicBooleanTimeout (seconds) for throttling packet writer to wait for pending packets sendFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log -
Constructor Summary
ConstructorsConstructorDescriptionThrottlingChannelStreamWriter(Channel channel) ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, long maxWait) ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, Duration maxWait) ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, TimeUnit waitUnit, long waitCount) ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, PropertyResolver resolver) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intintlongbooleanisOpen()voidoperationComplete(IoWriteFuture future) Invoked when the operation associated with theSshFuturehas been completed even if you add the listener after the completion.toString()Encode and send the given data packet buffer.
-
Field Details
-
WAIT_TIME
Timeout (seconds) for throttling packet writer to wait for pending packets send -
MAX_PEND_COUNT
Max. pending packets count -
delegate
-
maxPendingPackets
private final int maxPendingPackets -
maxWait
private final long maxWait -
open
-
availableCount
-
-
Constructor Details
-
ThrottlingChannelStreamWriter
-
ThrottlingChannelStreamWriter
-
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
-
getMaxPendingPackets
public int getMaxPendingPackets() -
getAvailablePacketsCount
public int getAvailablePacketsCount() -
getMaxWait
public long getMaxWait() -
isOpen
public boolean isOpen() -
writeData
Description copied from interface:ChannelStreamWriterEncode 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:
writeDatain interfaceChannelStreamWriter- Parameters:
buffer- the buffer to encode and send. NOTE: the buffer must not be touched until the returned write future is completed.- Returns:
- An
IoWriteFuturethat 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
Description copied from interface:SshFutureListenerInvoked when the operation associated with theSshFuturehas been completed even if you add the listener after the completion.- Specified by:
operationCompletein interfaceSshFutureListener<IoWriteFuture>- Parameters:
future- The sourceSshFuturewhich called this callback.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
toString
-