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.management.counters;
19:
20: import java.util.concurrent.atomic.AtomicInteger;
21:
22: import javax.management.ObjectName;
23:
24: public class ResponseTimeCounter implements ResponseTimeCounterMBean,
25: Counter {
26:
27: private ObjectName objectName;
28: private AtomicInteger invocations = new AtomicInteger();
29: private long totalHandlingTime;
30: private long maxHandlingTime;
31: private long minHandlingTime = Integer.MAX_VALUE;
32:
33: public ResponseTimeCounter(ObjectName on) {
34: objectName = on;
35: }
36:
37: public void increase(MessageHandlingTimeRecorder mhtr) {
38: invocations.getAndIncrement();
39: long handlingTime = 0;
40: if (mhtr.isOneWay()) {
41: // We can count the response time
42: if (mhtr.getEndTime() > 0) {
43: handlingTime = mhtr.getHandlingTime();
44: }
45: } else {
46: handlingTime = mhtr.getHandlingTime();
47: }
48:
49: totalHandlingTime = totalHandlingTime + handlingTime;
50: if (maxHandlingTime < handlingTime) {
51: maxHandlingTime = handlingTime;
52: }
53: if (minHandlingTime > handlingTime) {
54: minHandlingTime = handlingTime;
55: }
56: }
57:
58: public ObjectName getObjectName() {
59: return objectName;
60: }
61:
62: public Number getAvgResponseTime() {
63: return (int) (totalHandlingTime / invocations.get());
64: }
65:
66: public Number getMaxResponseTime() {
67: return maxHandlingTime;
68: }
69:
70: public Number getMinResponseTime() {
71: return minHandlingTime;
72: }
73:
74: public Number getNumInvocations() {
75: return invocations.get();
76: }
77:
78: }
|