001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.monitoring.counters;
019    
020    import org.apache.commons.monitoring.Role;
021    
022    import java.util.concurrent.atomic.AtomicInteger;
023    
024    /**
025     * A <code>Metric</code> is a numerical indicator of some monitored application state with support for simple
026     * statistics.
027     *
028     * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
029     */
030    public interface Counter {
031        Key getKey();
032    
033        void reset();
034    
035        void add(double delta);
036    
037        void add(double delta, Unit unit);
038    
039        AtomicInteger currentConcurrency();
040    
041        void updateConcurrency(int concurrency);
042    
043        int getMaxConcurrency();
044    
045        // --- Statistical indicators --------------------------------------------
046    
047        double getMax();
048    
049        double getMin();
050    
051        long getHits();
052    
053        double getSum();
054    
055        double getStandardDeviation();
056    
057        double getVariance();
058    
059        double getMean();
060    
061        double getGeometricMean();
062    
063        double getSumOfLogs();
064    
065        double getSumOfSquares();
066    
067        public static class Key {
068            private final String name;
069            private final Role role;
070    
071            public Key(final Role role, final String name) {
072                this.role = role;
073                this.name = name;
074            }
075    
076            @Override
077            public String toString() {
078                return "name=" + name;
079            }
080    
081            @Override
082            public boolean equals(Object o) {
083                if (this == o) return true;
084                if (o == null || getClass() != o.getClass()) return false;
085    
086                final Key key = (Key) o;
087                return name.equals(key.name) && role.equals(key.role);
088    
089            }
090    
091            @Override
092            public int hashCode() {
093                int result = name.hashCode();
094                result = 31 * result + role.hashCode();
095                return result;
096            }
097    
098            public String getName() {
099                return name;
100            }
101    
102            public Role getRole() {
103                return role;
104            }
105        }
106    }