org.xnap.io
Class ThrottleSupport

java.lang.Object
  extended by org.xnap.io.ThrottleSupport

public class ThrottleSupport
extends java.lang.Object

Provides a throttle implementation based on time ticks. Clients can allocate a limited amount of bytes for each tick. If all bandwidth has been allocated clients are stalled until the next tick.


Field Summary
protected  long allocated
           
protected  long bandwidth
          bytes per tick
protected  java.lang.Object lock
           
static long TICK_LENGTH
          The default length of a tick.
protected  long tickStart
           
 
Constructor Summary
ThrottleSupport()
           
 
Method Summary
 int allocate(int bytes)
          Returns the number of bytes that the calling thread is allowed to send.
 int getPreferredBlocksize()
          Returns the preferred block size each client should try to allocate at a time.
 void setBandwidth(long bandwidth)
          Sets the maximum bandwidth.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TICK_LENGTH

public static final long TICK_LENGTH
The default length of a tick.

See Also:
Constant Field Values

bandwidth

protected long bandwidth
bytes per tick


allocated

protected long allocated

tickStart

protected long tickStart

lock

protected java.lang.Object lock
Constructor Detail

ThrottleSupport

public ThrottleSupport()
Method Detail

getPreferredBlocksize

public int getPreferredBlocksize()
Returns the preferred block size each client should try to allocate at a time. This makes sure each client gets a fair share of the bandwidth.

See Also:
allocate(int)

setBandwidth

public void setBandwidth(long bandwidth)
Sets the maximum bandwidth.

Parameters:
bandwidth - byte / s

allocate

public int allocate(int bytes)
Returns the number of bytes that the calling thread is allowed to send. Blocks until at least one byte could be allocated.

Returns:
-1, if interrupted;


Copyright © 2001-2005 XNap Team. All Rights Reserved.