15
15
* See the License for the specific language governing permissions and
16
16
* limitations under the License.
17
17
*/
18
- package org .apache .beam .sdk .metrics ;
18
+
19
+ package org .apache .beam .runners .core .metrics ;
19
20
20
21
import java .util .concurrent .atomic .AtomicReference ;
21
22
import org .apache .beam .sdk .annotations .Experimental ;
23
+ import org .apache .beam .sdk .metrics .Gauge ;
24
+ import org .apache .beam .sdk .metrics .MetricName ;
22
25
23
26
/**
24
27
* Tracks the current value (and delta) for a {@link Gauge} metric.
29
32
* of indirection.
30
33
*/
31
34
@ Experimental (Experimental .Kind .METRICS )
32
- public class GaugeCell implements MetricCell < Gauge , GaugeData > {
35
+ public class GaugeCell implements Gauge , MetricCell < GaugeData > {
33
36
34
37
private final DirtyState dirty = new DirtyState ();
35
38
private final AtomicReference <GaugeData > gaugeValue = new AtomicReference <>(GaugeData .empty ());
39
+ private final MetricName name ;
40
+
41
+ /**
42
+ * Package-visibility because all {@link GaugeCell GaugeCells} should be created by
43
+ * {@link MetricsContainerImpl#getGauge(MetricName)}.
44
+ */
45
+ GaugeCell (MetricName name ) {
46
+ this .name = name ;
47
+ }
36
48
37
49
/** Set the gauge to the given value. */
50
+ @ Override
38
51
public void set (long value ) {
39
52
update (GaugeData .create (value ));
40
53
}
41
54
42
- @ Override
43
- public void update (GaugeData data ) {
55
+ void update (GaugeData data ) {
44
56
GaugeData original ;
45
57
do {
46
58
original = gaugeValue .get ();
47
59
} while (!gaugeValue .compareAndSet (original , original .combine (data )));
48
60
dirty .afterModification ();
49
61
}
50
62
51
- @ Override
52
- public void update (MetricCell <Gauge , GaugeData > other ) {
53
- GaugeData original ;
54
- do {
55
- original = gaugeValue .get ();
56
- } while (!gaugeValue .compareAndSet (original , original .combine (other .getCumulative ())));
57
- dirty .afterModification ();
58
- update (other .getCumulative ());
59
- }
60
-
61
63
@ Override
62
64
public DirtyState getDirty () {
63
65
return dirty ;
@@ -67,4 +69,10 @@ public DirtyState getDirty() {
67
69
public GaugeData getCumulative () {
68
70
return gaugeValue .get ();
69
71
}
72
+
73
+
74
+ @ Override
75
+ public MetricName getName () {
76
+ return name ;
77
+ }
70
78
}
0 commit comments