1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.monitoring.counters;
19
20 import org.apache.commons.monitoring.Role;
21
22 import java.util.concurrent.atomic.AtomicInteger;
23
24 /**
25 * A <code>Metric</code> is a numerical indicator of some monitored application state with support for simple
26 * statistics.
27 *
28 * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
29 */
30 public interface Counter {
31 Key getKey();
32
33 void reset();
34
35 void add(double delta);
36
37 void add(double delta, Unit unit);
38
39 AtomicInteger currentConcurrency();
40
41 void updateConcurrency(int concurrency);
42
43 int getMaxConcurrency();
44
45 // --- Statistical indicators --------------------------------------------
46
47 double getMax();
48
49 double getMin();
50
51 long getHits();
52
53 double getSum();
54
55 double getStandardDeviation();
56
57 double getVariance();
58
59 double getMean();
60
61 double getGeometricMean();
62
63 double getSumOfLogs();
64
65 double getSumOfSquares();
66
67 public static class Key {
68 private final String name;
69 private final Role role;
70
71 public Key(final Role role, final String name) {
72 this.role = role;
73 this.name = name;
74 }
75
76 @Override
77 public String toString() {
78 return "name=" + name;
79 }
80
81 @Override
82 public boolean equals(Object o) {
83 if (this == o) return true;
84 if (o == null || getClass() != o.getClass()) return false;
85
86 final Key key = (Key) o;
87 return name.equals(key.name) && role.equals(key.role);
88
89 }
90
91 @Override
92 public int hashCode() {
93 int result = name.hashCode();
94 result = 31 * result + role.hashCode();
95 return result;
96 }
97
98 public String getName() {
99 return name;
100 }
101
102 public Role getRole() {
103 return role;
104 }
105 }
106 }