1 3 package org.jgroups.stack; 4 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.jgroups.Message; 9 10 import java.util.HashMap ; 11 12 13 24 public class AckReceiverWindow { 25 final long initial_seqno; 26 long next_to_remove=0; 27 final HashMap msgs=new HashMap (); static final Log log=LogFactory.getLog(AckReceiverWindow.class); 29 30 31 public AckReceiverWindow(long initial_seqno) { 32 this.initial_seqno=initial_seqno; 33 next_to_remove=initial_seqno; 34 } 35 36 37 public void add(long seqno, Message msg) { 38 if(seqno < next_to_remove) { 39 if(log.isTraceEnabled()) 40 log.trace("discarded msg with seqno=" + seqno + " (next msg to receive is " + next_to_remove + ')'); 41 return; 42 } 43 msgs.put(new Long (seqno), msg); 44 } 45 46 47 52 public Message remove() { 53 Message retval=(Message)msgs.remove(new Long (next_to_remove)); 54 if(retval != null) 55 next_to_remove++; 56 return retval; 57 } 58 59 60 public void reset() { 61 msgs.clear(); 62 next_to_remove=initial_seqno; 63 } 64 65 public int size() { 66 return msgs.size(); 67 } 68 69 public String toString() { 70 return msgs.keySet().toString(); 71 } 72 73 74 75 } 76 | Popular Tags |