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