net.i2p.router.transport
Class FIFOBandwidthLimiter

java.lang.Object
  extended by net.i2p.router.transport.FIFOBandwidthLimiter

public class FIFOBandwidthLimiter
extends Object

Concurrent plan: It's difficult to get rid of the locks on _pendingInboundRequests since locked_satisyInboundAvailable() leaves Requests on the head of the queue. When we go to Java 6, we can convert from a locked ArrayList to a LinkedBlockingDeque, where locked_sIA will poll() from the head of the queue, and if the request is not fully satisfied, offerFirst() (i.e. push) it back on the head. Ditto outbound of course. In the meantime, for Java 5, we have lockless 'shortcut' methods for the common case where we are under the bandwidth limits. And the volatile counters are now AtomicIntegers / AtomicLongs.


Nested Class Summary
static interface FIFOBandwidthLimiter.CompleteListener
           
static interface FIFOBandwidthLimiter.Request
          This is somewhat complicated by having both inbound and outbound in a single request.
 
Constructor Summary
FIFOBandwidthLimiter(I2PAppContext context)
           
 
Method Summary
 FIFOBandwidthLimiter.Request createRequest()
           
 int getCurrentParticipatingBandwidth()
          Out bandwidth.
 int getInboundBurstBytes()
           
 int getInboundBurstKBytesPerSecond()
          The configured maximum, not the current rate
 int getInboundKBytesPerSecond()
          The configured maximum, not the current rate
 int getOutboundBurstBytes()
           
 int getOutboundBurstKBytesPerSecond()
          The configured maximum, not the current rate
 int getOutboundKBytesPerSecond()
          The configured maximum, not the current rate
 float getReceiveBps()
           
 float getReceiveBps15s()
           
 float getSendBps()
           
 float getSendBps15s()
           
(package private)  StringBuilder getStatus()
           
 long getTotalAllocatedInboundBytes()
           
 long getTotalAllocatedOutboundBytes()
           
 long now()
           
(package private)  void refillBandwidthQueues(List<FIFOBandwidthLimiter.Request> buf, long bytesInbound, long bytesOutbound, long maxBurstIn, long maxBurstOut)
          More bytes are available - add them to the queue and satisfy any requests we can
 void reinitialize()
           
 void renderStatusHTML(Writer out)
          Deprecated. not worth translating
 FIFOBandwidthLimiter.Request requestInbound(int bytesIn, String purpose)
          Request some bytes.
 FIFOBandwidthLimiter.Request requestInbound(int bytesIn, String purpose, FIFOBandwidthLimiter.CompleteListener lsnr, Object attachment)
           
 FIFOBandwidthLimiter.Request requestOutbound(int bytesOut, String purpose)
          Request some bytes.
 FIFOBandwidthLimiter.Request requestOutbound(int bytesOut, String purpose, FIFOBandwidthLimiter.CompleteListener lsnr, Object attachment)
           
 void sentParticipatingMessage(int size)
          We sent a message.
(package private)  void setInboundBurstBytes(int bytes)
           
(package private)  void setInboundBurstKBps(int kbytesPerSecond)
           
(package private)  void setInboundUnlimited(boolean isUnlimited)
          Deprecated. unused for now, we are always limited
(package private)  void setOutboundBurstBytes(int bytes)
           
(package private)  void setOutboundBurstKBps(int kbytesPerSecond)
           
(package private)  void setOutboundUnlimited(boolean isUnlimited)
          Deprecated. unused for now, we are always limited
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FIFOBandwidthLimiter

public FIFOBandwidthLimiter(I2PAppContext context)
Method Detail

now

public long now()

getTotalAllocatedInboundBytes

public long getTotalAllocatedInboundBytes()

getTotalAllocatedOutboundBytes

public long getTotalAllocatedOutboundBytes()

setInboundUnlimited

void setInboundUnlimited(boolean isUnlimited)
Deprecated. unused for now, we are always limited


setOutboundUnlimited

void setOutboundUnlimited(boolean isUnlimited)
Deprecated. unused for now, we are always limited


getSendBps

public float getSendBps()
Returns:
smoothed one second rate

getReceiveBps

public float getReceiveBps()
Returns:
smoothed one second rate

getSendBps15s

public float getSendBps15s()
Returns:
smoothed 15 second rate

getReceiveBps15s

public float getReceiveBps15s()
Returns:
smoothed 15 second rate

getOutboundKBytesPerSecond

public int getOutboundKBytesPerSecond()
The configured maximum, not the current rate


getInboundKBytesPerSecond

public int getInboundKBytesPerSecond()
The configured maximum, not the current rate


getOutboundBurstKBytesPerSecond

public int getOutboundBurstKBytesPerSecond()
The configured maximum, not the current rate


getInboundBurstKBytesPerSecond

public int getInboundBurstKBytesPerSecond()
The configured maximum, not the current rate


reinitialize

public void reinitialize()

shutdown

public void shutdown()
Since:
0.8.8

sentParticipatingMessage

public void sentParticipatingMessage(int size)
We sent a message.

Parameters:
size - bytes
Since:
0.8.12

getCurrentParticipatingBandwidth

public int getCurrentParticipatingBandwidth()
Out bandwidth. Actual bandwidth, not smoothed, not bucketed.

Returns:
Bps in recent period (a few seconds)
Since:
0.8.12

createRequest

public FIFOBandwidthLimiter.Request createRequest()

requestInbound

public FIFOBandwidthLimiter.Request requestInbound(int bytesIn,
                                                   String purpose)
Request some bytes. Does not block.


requestInbound

public FIFOBandwidthLimiter.Request requestInbound(int bytesIn,
                                                   String purpose,
                                                   FIFOBandwidthLimiter.CompleteListener lsnr,
                                                   Object attachment)

requestOutbound

public FIFOBandwidthLimiter.Request requestOutbound(int bytesOut,
                                                    String purpose)
Request some bytes. Does not block.


requestOutbound

public FIFOBandwidthLimiter.Request requestOutbound(int bytesOut,
                                                    String purpose,
                                                    FIFOBandwidthLimiter.CompleteListener lsnr,
                                                    Object attachment)

setInboundBurstKBps

void setInboundBurstKBps(int kbytesPerSecond)

setOutboundBurstKBps

void setOutboundBurstKBps(int kbytesPerSecond)

getInboundBurstBytes

public int getInboundBurstBytes()

getOutboundBurstBytes

public int getOutboundBurstBytes()

setInboundBurstBytes

void setInboundBurstBytes(int bytes)

setOutboundBurstBytes

void setOutboundBurstBytes(int bytes)

getStatus

StringBuilder getStatus()

refillBandwidthQueues

final void refillBandwidthQueues(List<FIFOBandwidthLimiter.Request> buf,
                                 long bytesInbound,
                                 long bytesOutbound,
                                 long maxBurstIn,
                                 long maxBurstOut)
More bytes are available - add them to the queue and satisfy any requests we can

Parameters:
buf - contains satisfied outbound requests, really just to avoid object thrash, not really used
maxBurstIn - allow up to this many bytes in from the burst section for this time period (may be negative)
maxBurstOut - allow up to this many bytes in from the burst section for this time period (may be negative)

renderStatusHTML

public void renderStatusHTML(Writer out)
                      throws IOException
Deprecated. not worth translating

Throws:
IOException