Make {Metric,Counter,Distribution}Cell public These classes may be useful to hold on to within a runner where the step context is known to be unchanging and there may be a desire to avoid the extra indirection of using {Counter,Distribution} directly.
Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/cfd1633a Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/cfd1633a Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/cfd1633a Branch: refs/heads/gearpump-runner Commit: cfd1633a441f98d100bd995bd811b6b8fa2cd62d Parents: cc28f0c Author: bchambers <bchamb...@google.com> Authored: Wed Dec 14 15:46:50 2016 -0800 Committer: bchambers <bchamb...@google.com> Committed: Fri Dec 16 14:26:35 2016 -0800 ---------------------------------------------------------------------- .../org/apache/beam/sdk/metrics/CounterCell.java | 10 +++++++++- .../apache/beam/sdk/metrics/DistributionCell.java | 15 +++++++++++++-- .../java/org/apache/beam/sdk/metrics/MetricCell.java | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/cfd1633a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/CounterCell.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/CounterCell.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/CounterCell.java index bb65833..93700e6 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/CounterCell.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/CounterCell.java @@ -26,13 +26,21 @@ import org.apache.beam.sdk.annotations.Experimental.Kind; * * <p>This class generally shouldn't be used directly. The only exception is within a runner where * a counter is being reported for a specific step (rather than the counter in the current context). + * In that case retrieving the underlying cell and reporting directly to it avoids a step of + * indirection. */ @Experimental(Kind.METRICS) -class CounterCell implements MetricCell<Counter, Long>, Counter { +public class CounterCell implements MetricCell<Counter, Long>, Counter { private final DirtyState dirty = new DirtyState(); private final AtomicLong value = new AtomicLong(); + /** + * Package-visibility because all {@link CounterCell CounterCells} should be created by + * {@link MetricsContainer#getCounter(MetricName)}. + */ + CounterCell() {} + /** Increment the counter by the given amount. */ private void add(long n) { value.addAndGet(n); http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/cfd1633a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/DistributionCell.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/DistributionCell.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/DistributionCell.java index f0074a9..e095158 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/DistributionCell.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/DistributionCell.java @@ -23,14 +23,25 @@ import org.apache.beam.sdk.annotations.Experimental.Kind; /** * Tracks the current value (and delta) for a Distribution metric. + * + * <p>This class generally shouldn't be used directly. The only exception is within a runner where + * a distribution is being reported for a specific step (rather than the distribution in the current + * context). In that case retrieving the underlying cell and reporting directly to it avoids a step + * of indirection. */ @Experimental(Kind.METRICS) -class DistributionCell implements MetricCell<Distribution, DistributionData>, Distribution { +public class DistributionCell implements MetricCell<Distribution, DistributionData>, Distribution { private final DirtyState dirty = new DirtyState(); private final AtomicReference<DistributionData> value = new AtomicReference<DistributionData>(DistributionData.EMPTY); + /** + * Package-visibility because all {@link DistributionCell DistributionCells} should be created by + * {@link MetricsContainer#getDistribution(MetricName)}. + */ + DistributionCell() {} + /** Increment the counter by the given amount. */ @Override public void update(long n) { @@ -55,4 +66,4 @@ class DistributionCell implements MetricCell<Distribution, DistributionData>, Di public Distribution getInterface() { return this; } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/cfd1633a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricCell.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricCell.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricCell.java index 211b2dd..7cf9710 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricCell.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricCell.java @@ -28,7 +28,7 @@ import org.apache.beam.sdk.annotations.Experimental.Kind; * @param <DataT> The type of metric data stored (and extracted) from this cell. */ @Experimental(Kind.METRICS) -interface MetricCell<UserT extends Metric, DataT> { +public interface MetricCell<UserT extends Metric, DataT> { /** * Return the {@link DirtyState} tracking whether this metric cell contains uncommitted changes.