blob: 8331846a5bbb6c673fba24c757857215e91256c6 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.apputil.communication.http;
import com.yahoo.jdisc.Metric;
import com.yahoo.vespa.clustercontroller.utils.util.MetricReporter;
public class JDiscMetricWrapper implements MetricReporter {
private final Object lock = new Object();
private Metric m;
private static class ContextWrapper implements MetricReporter.Context {
final Metric.Context wrappedContext;
public ContextWrapper(Metric.Context wrapped) {
this.wrappedContext = wrapped;
}
}
public JDiscMetricWrapper(Metric m) {
this.m = m;
}
public void updateMetricImplementation(Metric m) {
synchronized (lock) {
this.m = m;
}
}
public void set(String s, Number number, MetricReporter.Context context) {
synchronized (lock) {
ContextWrapper cw = (ContextWrapper) context;
m.set(s, number, cw == null ? null : cw.wrappedContext);
}
}
public void add(String s, Number number, MetricReporter.Context context) {
synchronized (lock) {
ContextWrapper cw = (ContextWrapper) context;
m.add(s, number, cw == null ? null : cw.wrappedContext);
}
}
public MetricReporter.Context createContext(java.util.Map<java.lang.String,?> stringMap) {
synchronized (lock) {
return new ContextWrapper(m.createContext(stringMap));
}
}
}
|