public class StreamManager extends Object implements BandwidthLimiter
setDownstreamKbps(long).
The maximum Upstream kilobits per sec speed can be set via setUpstreamKbps(long).
Additional latency can be added via setLatency(long).
It is possible to fine tune the amount of payload that gets actually sent to the pipe
via setPayloadPercentage(int).
Note: there is no fairness in how the bandwidth is currently assigned to the registered streams.
If this causes problems for your purposes you have to override/change
registerStream(InputStream)
registerStream(OutputStream)
getAllowedBytesRead(org.java_bandwidthlimiter.StreamManager.ManagedInputStream, int)
getAllowedBytesWrite(org.java_bandwidthlimiter.StreamManager.ManagedOutputStream, int)
and implement fairness there.OneKbps, OneMbps, OneSecond| Constructor and Description |
|---|
StreamManager(long maxBitsPerSecond)
Create an instance of StreamManager.
|
| Modifier and Type | Method and Description |
|---|---|
void |
disable()
Calling this method to stop throttling all registered streams.
|
void |
enable()
Calling this method to start throttling all registered streams.
|
long |
getLatency() |
long |
getMaxDownstreamKB() |
long |
getMaxUpstreamKB() |
long |
getRemainingDownstreamKB() |
long |
getRemainingUpstreamKB() |
InputStream |
registerStream(InputStream in)
Register an input stream.
|
OutputStream |
registerStream(OutputStream out)
Register an output stream.
|
void |
setDownstreamKbps(long downstreamKbps)
setting the max kilobits per seconds this StreamManager should apply in downstream,
as aggregate bandwidth of all the InputStream registered.
|
void |
setDownstreamMaxKB(long downstreamMaxKB)
Specifies how many kilobytes in total the client is allowed to download.
|
void |
setLatency(long latency)
setting the additional (simulated) latency that the streams will suffer.
|
void |
setMaxBitsPerSecondThreshold(long maxBitsPerSecond)
This function sets the max bits per second threshold
setDownstreamKbps(long) and setDownstreamKbps(long) won't be allowed
to set a bandwidth higher than what specified here. |
void |
setPayloadPercentage(int payloadPercentage)
To take into account overhead due to underlying protocols (e.g.
|
void |
setUpstreamKbps(long upstreamKbps)
setting the max kilobits per seconds this StreamManager should apply in upstream,
as aggregate bandwidth of all the OutputStream registered.
|
void |
setUpstreamMaxKB(long upstreamMaxKB)
Specifies how many kilobytes in total the client is allowed to upload.
|
public StreamManager(long maxBitsPerSecond)
registerStream(java.io.InputStream)
and/or registerStream(java.io.OutputStream).
It is disabled by default, hence to begin throttling enable() has to be called first.maxBitsPerSecond - the default and max speed this instance of StreamManager will throttle to.
It is an upper bound to what setDownstreamKbps(long) and setUpstreamKbps(long)
can request.
This upper bound can _only_ be changed via setMaxBitsPerSecondThreshold(long)public void enable()
public void disable()
public void setDownstreamKbps(long downstreamKbps)
setDownstreamKbps in interface BandwidthLimiterdownstreamKbps - the desired max kilobits per second downstream rate.public void setUpstreamKbps(long upstreamKbps)
setUpstreamKbps in interface BandwidthLimiterupstreamKbps - the desired max kilobits per second upstream rate.public void setLatency(long latency)
setLatency in interface BandwidthLimiterlatency - the desired additional latency in millisecondspublic void setDownstreamMaxKB(long downstreamMaxKB)
setDownstreamMaxKB in interface BandwidthLimiterdownstreamMaxKB - public void setUpstreamMaxKB(long upstreamMaxKB)
setUpstreamMaxKB in interface BandwidthLimiterupstreamMaxKB - public long getLatency()
public void setPayloadPercentage(int payloadPercentage)
payloadPercentage - a ] 0 , 100] value. where 100 means that the required
downstream/upstream bandwidth will be full used for
sending payload.
Default value is 95%.
The default value is applied if an out of boundaries value is passed in.public InputStream registerStream(InputStream in)
in - The InputStream that will throttledpublic OutputStream registerStream(OutputStream out)
out - The OutputStream that will be throttledpublic void setMaxBitsPerSecondThreshold(long maxBitsPerSecond)
setDownstreamKbps(long) and setDownstreamKbps(long) won't be allowed
to set a bandwidth higher than what specified here.maxBitsPerSecond - The max bits per seconds you want this instance of StreamManager to respect.public long getMaxUpstreamKB()
public long getRemainingUpstreamKB()
public long getMaxDownstreamKB()
public long getRemainingDownstreamKB()
Copyright © 2015. All Rights Reserved.