01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.ws.rm;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22: import java.util.logging.Logger;
23:
24: import org.apache.cxf.common.logging.LogUtils;
25:
26: public class SequenceMonitor {
27:
28: private static final long DEFAULT_MONITOR_INTERVAL = 60000L;
29: private static final Logger LOG = LogUtils
30: .getL7dLogger(SequenceMonitor.class);
31: private long monitorInterval = DEFAULT_MONITOR_INTERVAL;
32: private long firstCheck;
33: private List<Long> receiveTimes = new ArrayList<Long>();
34:
35: public void acknowledgeMessage() {
36: long now = System.currentTimeMillis();
37: if (0 == firstCheck) {
38: firstCheck = now + monitorInterval;
39: }
40: receiveTimes.add(new Long(now));
41: }
42:
43: public int getMPM() {
44: long now = System.currentTimeMillis();
45: int mpm = 0;
46: if (firstCheck > 0 && now >= firstCheck) {
47: long threshold = now - monitorInterval;
48: while (!receiveTimes.isEmpty()) {
49: if (receiveTimes.get(0).longValue() <= threshold) {
50: receiveTimes.remove(0);
51: } else {
52: break;
53: }
54: }
55: mpm = receiveTimes.size();
56: }
57:
58: return mpm;
59: }
60:
61: public synchronized long getLastArrivalTime() {
62: if (receiveTimes.size() > 0) {
63: return receiveTimes.get(receiveTimes.size() - 1)
64: .longValue();
65: }
66: return 0;
67: }
68:
69: protected void setMonitorInterval(long i) {
70: if (receiveTimes.size() == 0) {
71: firstCheck = 0;
72: monitorInterval = i;
73: } else {
74: LOG
75: .warning("Cannot change monitor interval at this point.");
76: }
77: }
78: }
|