|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.connection.MessageQueue
A priority queue for messages. Used by ManagedConnection to implement the SACHRIFC flow-control algorithm. Subclasses override the add, removeNextInternal, and size template methods to implement different prioritization policies. NOT THREAD SAFE.
This class is designed for speed; hence the somewhat awkward use of resetCycle/extractMax instead of a simple iterator. Likewise, this class has a resetDropped() method instead of returning a (Message, int) pair in removeNext();
Field Summary | |
protected int |
_dropped
The number of messages dropped since the last call to resetDropped(). |
Constructor Summary | |
protected |
MessageQueue(int cycle,
int timeout)
|
Method Summary | |
void |
add(Message m)
Adds m to this. |
protected abstract Message |
addInternal(Message m)
Add m to this, returns any message that had to dropped to make room in a queue. |
boolean |
isEmpty()
Returns true if this has any queued messages. |
Message |
removeNext()
Removes and returns the next message to send from this during this cycle. |
protected abstract Message |
removeNextInternal()
Same as removeNext, but ignores message age and cycle. |
void |
resetCycle()
Resets the cycle counter used to control removeNext(). |
int |
resetDropped()
Returns the number of dropped messages since the last call to resetDropped(). |
abstract int |
size()
Returns the number of queued messages. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int _dropped
Constructor Detail |
protected MessageQueue(int cycle, int timeout) throws java.lang.IllegalArgumentException
cycle
- the number of messages to return per cycle, i.e., between
calls to resetCycle. This is used to tweak the ratios of various
message types.timeout
- the max time to keep queued messages, in milliseconds.
Set this to Integer.MAX_VALUE to avoid timeouts.Method Detail |
public void add(Message m)
protected abstract Message addInternal(Message m)
public Message removeNext()
protected abstract Message removeNextInternal()
public void resetCycle()
public final int resetDropped()
public abstract int size()
public boolean isEmpty()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |