1 package org.objectweb.celtix.bus.ws.rm; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 import java.util.logging.Logger ; 6 7 import org.objectweb.celtix.common.logging.LogUtils; 8 9 public class SequenceMonitor { 10 11 private static final long DEFAULT_MONITOR_INTERVAL = 60000L; 12 private static final Logger LOG = LogUtils.getL7dLogger(SequenceMonitor.class); 13 private long monitorInterval = DEFAULT_MONITOR_INTERVAL; 14 private long firstCheck; 15 private List <Long > receiveTimes = new ArrayList <Long >(); 16 17 public void acknowledgeMessage() { 18 long now = System.currentTimeMillis(); 19 if (0 == firstCheck) { 20 firstCheck = now + monitorInterval; 21 } 22 receiveTimes.add(new Long (now)); 23 } 24 25 public int getMPM() { 26 long now = System.currentTimeMillis(); 27 int mpm = 0; 28 if (firstCheck > 0 && now >= firstCheck) { 29 long threshold = now - monitorInterval; 30 while (!receiveTimes.isEmpty()) { 31 if (receiveTimes.get(0).longValue() <= threshold) { 32 receiveTimes.remove(0); 33 } else { 34 break; 35 } 36 } 37 mpm = receiveTimes.size(); 38 } 39 40 return mpm; 41 } 42 43 protected void setMonitorInterval(long i) { 44 if (receiveTimes.size() == 0) { 45 firstCheck = 0; 46 monitorInterval = i; 47 } else { 48 LOG.warning("Cannot change monitor interval at this point."); 49 } 50 } 51 } 52 | Popular Tags |