com.limegroup.gnutella.connection
Class PriorityMessageQueue

java.lang.Object
  extended bycom.limegroup.gnutella.connection.MessageQueue
      extended bycom.limegroup.gnutella.connection.PriorityMessageQueue

public class PriorityMessageQueue
extends MessageQueue

A message queue that prioritizes messages. These are intended to be heterogenous, i.e., to only contain one type of message at a time, though that is not strictly enforced. Message are preferenced as follows:

  1. QueryReply: messages with low GUID volume are preferred, i.e., GUID's for which few replies have already been routed.
  2. PingReply: messages with high hops [sic] are preferred, since they contain addresses of hosts less likely to be in your horizon.
  3. Others: messages with low hops are preferred, since they have travelled down fewer redundant paths and have received fewer responses.
Then, within any given priority level, newer messages are preferred to older ones (LIFO).

Currently this is implemented with a BucketQueue, which provides LIFO ordering within any given bucket. BinaryHeap could make sense for QueryReply's, but the replacement policy is undefined if the queue fills up.


Field Summary
 
Fields inherited from class com.limegroup.gnutella.connection.MessageQueue
_dropped
 
Constructor Summary
PriorityMessageQueue(int cycle, int timeout, int capacity)
           
 
Method Summary
protected  Message addInternal(Message m)
          Add m to this, returns any message that had to dropped to make room in a queue.
protected  Message removeNextInternal()
          Same as removeNext, but ignores message age and cycle.
 int size()
          Returns the number of queued messages.
 
Methods inherited from class com.limegroup.gnutella.connection.MessageQueue
add, isEmpty, removeNext, resetCycle, resetDropped
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriorityMessageQueue

public PriorityMessageQueue(int cycle,
                            int timeout,
                            int capacity)
Parameters:
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.
capacity - the maximum number of elements this can store.
Method Detail

addInternal

protected Message addInternal(Message m)
Description copied from class: MessageQueue
Add m to this, returns any message that had to dropped to make room in a queue.

Specified by:
addInternal in class MessageQueue

removeNextInternal

protected Message removeNextInternal()
Description copied from class: MessageQueue
Same as removeNext, but ignores message age and cycle.

Specified by:
removeNextInternal in class MessageQueue
Returns:
the next message to send, or null if this is empty

size

public int size()
Description copied from class: MessageQueue
Returns the number of queued messages.

Specified by:
size in class MessageQueue