aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/jdisc/state/CountMetric.java
blob: 2a692a3da6c7e6ff5baa495a2e754cd19a46d026 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc.state;

/**
 * A metric which is counting an accumulative value
 *
 * @author Simon Thoresen Hult
 */
public final class CountMetric extends MetricValue {

    private long count;

    private CountMetric(long count) {
        this.count = count;
    }

    @Override
    void add(Number num) {
        this.count += num.longValue();
    }

    @Override
    void add(MetricValue value) {
        CountMetric rhs = (CountMetric)value;
        this.count += rhs.count;
    }

    /** Returns the accumulated count of this metric in the time interval */
    public long getCount() {
        return count;
    }

    public static CountMetric newSingleValue(Number val) {
        long lval = val.longValue();
        return new CountMetric(lval);
    }

    public static CountMetric newInstance(long val) {
        return new CountMetric(val);
    }

}