Class ThrottlingChannelStreamWriter
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.contrib.common.channel.throttle.ThrottlingChannelStreamWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,java.util.EventListener,ChannelStreamWriter,SshFutureListener<IoWriteFuture>,SshdEventListener
public class ThrottlingChannelStreamWriter extends AbstractLoggingBean implements ChannelStreamWriter, SshFutureListener<IoWriteFuture>
AChannelStreamWriterdelegate implementation that "throttles" the output by having a limit on the outstanding packets that have not been sent yet. ThewritePacketimplementation 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:closingthe throttler does not close the delegate writer
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicIntegeravailableCountprivate ChannelStreamWriterdelegatestatic Property<java.lang.Integer>MAX_PEND_COUNTMax.private intmaxPendingPacketsprivate longmaxWaitprivate java.util.concurrent.atomic.AtomicBooleanopenstatic Property<java.time.Duration>WAIT_TIMETimeout (seconds) for throttling packet writer to wait for pending packets send-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description ThrottlingChannelStreamWriter(Channel channel)ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, long maxWait)ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, java.time.Duration maxWait)ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, java.util.concurrent.TimeUnit waitUnit, long waitCount)ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, PropertyResolver resolver)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()intgetAvailablePacketsCount()ChannelStreamWritergetDelegate()intgetMaxPendingPackets()longgetMaxWait()booleanisOpen()voidoperationComplete(IoWriteFuture future)Invoked when the operation associated with theSshFuturehas been completed even if you add the listener after the completion.java.lang.StringtoString()IoWriteFuturewriteData(Buffer buffer)Encode and send the given data packet buffer.
-
-
-
Field Detail
-
WAIT_TIME
public static final Property<java.time.Duration> WAIT_TIME
Timeout (seconds) for throttling packet writer to wait for pending packets send
-
MAX_PEND_COUNT
public static final Property<java.lang.Integer> MAX_PEND_COUNT
Max. pending packets count
-
delegate
private final ChannelStreamWriter delegate
-
maxPendingPackets
private final int maxPendingPackets
-
maxWait
private final long maxWait
-
open
private final java.util.concurrent.atomic.AtomicBoolean open
-
availableCount
private final java.util.concurrent.atomic.AtomicInteger availableCount
-
-
Constructor Detail
-
ThrottlingChannelStreamWriter
public ThrottlingChannelStreamWriter(Channel channel)
-
ThrottlingChannelStreamWriter
public ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, PropertyResolver resolver)
-
ThrottlingChannelStreamWriter
public ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, java.util.concurrent.TimeUnit waitUnit, long waitCount)
-
ThrottlingChannelStreamWriter
public ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, java.time.Duration maxWait)
-
ThrottlingChannelStreamWriter
public ThrottlingChannelStreamWriter(ChannelStreamWriter delegate, int maxPendingPackets, long maxWait)
-
-
Method Detail
-
getDelegate
public ChannelStreamWriter getDelegate()
-
getMaxPendingPackets
public int getMaxPendingPackets()
-
getAvailablePacketsCount
public int getAvailablePacketsCount()
-
getMaxWait
public long getMaxWait()
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
writeData
public IoWriteFuture writeData(Buffer buffer) throws java.io.IOException
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:
java.io.IOException- if an error occurred when encoding or sending the packet
-
operationComplete
public void operationComplete(IoWriteFuture future)
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
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-