Package io.undertow.conduits
Class RateLimitingStreamSinkConduit
- java.lang.Object
-
- org.xnio.conduits.AbstractConduit<D>
-
- org.xnio.conduits.AbstractSinkConduit<D>
-
- org.xnio.conduits.AbstractStreamSinkConduit<org.xnio.conduits.StreamSinkConduit>
-
- io.undertow.conduits.RateLimitingStreamSinkConduit
-
- All Implemented Interfaces:
org.xnio.conduits.Conduit
,org.xnio.conduits.SinkConduit
,org.xnio.conduits.StreamSinkConduit
public class RateLimitingStreamSinkConduit extends org.xnio.conduits.AbstractStreamSinkConduit<org.xnio.conduits.StreamSinkConduit>
Class that implements the token bucket algorithm.Allows send speed to be throttled
Note that throttling is applied after an initial write, so if a big write is performed initially it may be a while before it can write again.
- Author:
- Stuart Douglas
-
-
Constructor Summary
Constructors Constructor Description RateLimitingStreamSinkConduit(org.xnio.conduits.StreamSinkConduit next, int bytes, long time, TimeUnit timeUnit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
awaitWritable()
void
awaitWritable(long time, TimeUnit timeUnit)
boolean
isWriteResumed()
void
resumeWrites()
void
suspendWrites()
long
transferFrom(FileChannel src, long position, long count)
long
transferFrom(org.xnio.channels.StreamSourceChannel source, long count, ByteBuffer throughBuffer)
void
wakeupWrites()
int
write(ByteBuffer src)
long
write(ByteBuffer[] srcs, int offs, int len)
int
writeFinal(ByteBuffer src)
long
writeFinal(ByteBuffer[] srcs, int offs, int len)
-
Methods inherited from class org.xnio.conduits.AbstractSinkConduit
flush, getWriteThread, isWriteShutdown, setWriteReadyHandler, terminateWrites, truncateWrites
-
-
-
-
Constructor Detail
-
RateLimitingStreamSinkConduit
public RateLimitingStreamSinkConduit(org.xnio.conduits.StreamSinkConduit next, int bytes, long time, TimeUnit timeUnit)
- Parameters:
next
- The next conduitbytes
- The number of bytes that are allowed per time frametime
- The time frametimeUnit
- The time unit
-
-
Method Detail
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
write
in interfaceorg.xnio.conduits.StreamSinkConduit
- Overrides:
write
in classorg.xnio.conduits.AbstractStreamSinkConduit<org.xnio.conduits.StreamSinkConduit>
- Throws:
IOException
-
transferFrom
public long transferFrom(FileChannel src, long position, long count) throws IOException
- Specified by:
transferFrom
in interfaceorg.xnio.conduits.StreamSinkConduit
- Overrides:
transferFrom
in classorg.xnio.conduits.AbstractStreamSinkConduit<org.xnio.conduits.StreamSinkConduit>
- Throws:
IOException
-
transferFrom
public long transferFrom(org.xnio.channels.StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException
- Specified by:
transferFrom
in interfaceorg.xnio.conduits.StreamSinkConduit
- Overrides:
transferFrom
in classorg.xnio.conduits.AbstractStreamSinkConduit<org.xnio.conduits.StreamSinkConduit>
- Throws:
IOException
-
write
public long write(ByteBuffer[] srcs, int offs, int len) throws IOException
- Specified by:
write
in interfaceorg.xnio.conduits.StreamSinkConduit
- Overrides:
write
in classorg.xnio.conduits.AbstractStreamSinkConduit<org.xnio.conduits.StreamSinkConduit>
- Throws:
IOException
-
writeFinal
public int writeFinal(ByteBuffer src) throws IOException
- Specified by:
writeFinal
in interfaceorg.xnio.conduits.StreamSinkConduit
- Overrides:
writeFinal
in classorg.xnio.conduits.AbstractStreamSinkConduit<org.xnio.conduits.StreamSinkConduit>
- Throws:
IOException
-
writeFinal
public long writeFinal(ByteBuffer[] srcs, int offs, int len) throws IOException
- Specified by:
writeFinal
in interfaceorg.xnio.conduits.StreamSinkConduit
- Overrides:
writeFinal
in classorg.xnio.conduits.AbstractStreamSinkConduit<org.xnio.conduits.StreamSinkConduit>
- Throws:
IOException
-
resumeWrites
public void resumeWrites()
- Specified by:
resumeWrites
in interfaceorg.xnio.conduits.SinkConduit
- Overrides:
resumeWrites
in classorg.xnio.conduits.AbstractSinkConduit<org.xnio.conduits.StreamSinkConduit>
-
suspendWrites
public void suspendWrites()
- Specified by:
suspendWrites
in interfaceorg.xnio.conduits.SinkConduit
- Overrides:
suspendWrites
in classorg.xnio.conduits.AbstractSinkConduit<org.xnio.conduits.StreamSinkConduit>
-
wakeupWrites
public void wakeupWrites()
- Specified by:
wakeupWrites
in interfaceorg.xnio.conduits.SinkConduit
- Overrides:
wakeupWrites
in classorg.xnio.conduits.AbstractSinkConduit<org.xnio.conduits.StreamSinkConduit>
-
isWriteResumed
public boolean isWriteResumed()
- Specified by:
isWriteResumed
in interfaceorg.xnio.conduits.SinkConduit
- Overrides:
isWriteResumed
in classorg.xnio.conduits.AbstractSinkConduit<org.xnio.conduits.StreamSinkConduit>
-
awaitWritable
public void awaitWritable() throws IOException
- Specified by:
awaitWritable
in interfaceorg.xnio.conduits.SinkConduit
- Overrides:
awaitWritable
in classorg.xnio.conduits.AbstractSinkConduit<org.xnio.conduits.StreamSinkConduit>
- Throws:
IOException
-
awaitWritable
public void awaitWritable(long time, TimeUnit timeUnit) throws IOException
- Specified by:
awaitWritable
in interfaceorg.xnio.conduits.SinkConduit
- Overrides:
awaitWritable
in classorg.xnio.conduits.AbstractSinkConduit<org.xnio.conduits.StreamSinkConduit>
- Throws:
IOException
-
-