aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/metrics/simple/Sample.java
blob: eea2d752582470572071d2a3d4f88b51a8d5636b (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.metrics.simple;

import com.yahoo.metrics.simple.UntypedMetric.AssumedType;

/**
 * A single metric measurement and all the meta data needed to route it
 * correctly.
 *
 * @author Steinar Knutsen
 */
public class Sample {

    private final Identifier identifier;
    private final Measurement measurement;
    private final AssumedType metricType;
    private MetricReceiver metricReceiver = null;

    public Sample(Measurement measurement, Identifier id, AssumedType t) {
        this.identifier = id;
        this.measurement = measurement;
        this.metricType = t;
    }

    Identifier getIdentifier() {
        return identifier;
    }

    Measurement getMeasurement() {
        return measurement;
    }

    AssumedType getMetricType() {
        return metricType;
    }

    void setReceiver(MetricReceiver metricReceiver) {
        this.metricReceiver = metricReceiver;
    }

    /**
     * Get histogram definition for an arbitrary metric. Caveat emptor: This
     * involves reading a volatile.
     *
     * @param metricName name of the metric to get histogram definition for
     * @return how to define a new histogram or null
     */
    MetricSettings getHistogramDefinition(String metricName) {
        if (metricReceiver == null) {
            return null;
        } else {
            return metricReceiver.getMetricDefinition(metricName);
        }
    }

}