/** Constructs storage for {@code double} valued instruments. */
public static <T> MetricStorage doubleAsynchronousAccumulator(
      View view,
      InstrumentDescriptor instrument,
      Consumer<ObservableDoubleMeasurement> metricUpdater) {
    final MetricDescriptor metricDescriptor = MetricDescriptor.create(view, instrument);
    Aggregator<T> aggregator =
        view.getAggregation().createAggregator(instrument, ExemplarFilter.neverSample());
    final AsyncAccumulator<T> measurementAccumulator = new AsyncAccumulator<>(instrument);
    if (Aggregator.empty() == aggregator) {
      return empty();
    }
    final AttributesProcessor attributesProcessor = view.getAttributesProcessor();
    // TODO: Find a way to grab the measurement JUST ONCE for all async metrics.
    final ObservableDoubleMeasurement result =
        new ObservableDoubleMeasurement() {
          @Override
          public void observe(double value, Attributes attributes) {
            T accumulation =
                aggregator.accumulateDoubleMeasurement(value, attributes, Context.current());
            if (accumulation != null) {
              measurementAccumulator.record(
                  attributesProcessor.process(attributes, Context.current()), accumulation);
            }
          }
          @Override
          public void observe(double value) {
            observe(value, Attributes.empty());
          }
        };
    return new AsynchronousMetricStorage<>(
        metricDescriptor, aggregator, measurementAccumulator, () -> metricUpdater.accept(result));
  }
public static <T> MetricStorage doubleAsynchronousAccumulator(
View view,
InstrumentDescriptor instrument,
Consumer<ObservableDoubleMeasurement> metricUpdater) {
final MetricDescriptor metricDescriptor = MetricDescriptor.create(view, instrument);
Aggregator<T> aggregator =
view.getAggregation().createAggregator(instrument, ExemplarFilter.neverSample());
final AsyncAccumulator<T> measurementAccumulator = new AsyncAccumulator<>(instrument);
if (Aggregator.empty() == aggregator) {
return empty();
}
final AttributesProcessor attributesProcessor = view.getAttributesProcessor();
// TODO: Find a way to grab the measurement JUST ONCE for all async metrics.
final ObservableDoubleMeasurement result =
new ObservableDoubleMeasurement() {
@Override
public void observe(double value, Attributes attributes) {
T accumulation =
aggregator.accumulateDoubleMeasurement(value, attributes, Context.current());
if (accumulation != null) {
measurementAccumulator.record(
attributesProcessor.process(attributes, Context.current()), accumulation);
}
}
@Override
public void observe(double value) {
observe(value, Attributes.empty());
}
};
return new AsynchronousMetricStorage<>(
metricDescriptor, aggregator, measurementAccumulator, () -> metricUpdater.accept(result));
}
public static <T> MetricStorage doubleAsynchronousAccumulator(
View view,
InstrumentDescriptor instrument,
Consumer<ObservableDoubleMeasurement> metricUpdater) {
final MetricDescriptor metricDescriptor = MetricDescriptor.create(view, instrument);
Aggregator<T> aggregator =
view.getAggregation().createAggregator(instrument, ExemplarFilter.neverSample());
final AsyncAccumulator<T> measurementAccumulator = new AsyncAccumulator<>(instrument);
if (Aggregator.empty() == aggregator) {
return empty();
}
final AttributesProcessor attributesProcessor = view.getAttributesProcessor();
// TODO: Find a way to grab the measurement JUST ONCE for all async metrics.
final ObservableDoubleMeasurement result =
new ObservableDoubleMeasurement() {
@Override
public void observe(double value, Attributes attributes) {
T accumulation =
aggregator.accumulateDoubleMeasurement(value, attributes, Context.current());
if (accumulation != null) {
measurementAccumulator.record(
attributesProcessor.process(attributes, Context.current()), accumulation);
}
}
@Override
public void observe(double value) {
observe(value, Attributes.empty());
}
};
return new AsynchronousMetricStorage<>(
metricDescriptor, aggregator, measurementAccumulator, () -> metricUpdater.accept(result));
}
public static <T> MetricStorage doubleAsynchronousAccumulator(
View view,
InstrumentDescriptor instrument,
Consumer<ObservableDoubleMeasurement> metricUpdater) {
final MetricDescriptor metricDescriptor = MetricDescriptor.create(view, instrument);
Aggregator<T> aggregator =
view.getAggregation().createAggregator(instrument, ExemplarFilter.neverSample());
final AsyncAccumulator<T> measurementAccumulator = new AsyncAccumulator<>(instrument);
if (Aggregator.empty() == aggregator) {
return empty();
}
final AttributesProcessor attributesProcessor = view.getAttributesProcessor();
// TODO: Find a way to grab the measurement JUST ONCE for all async metrics.
final ObservableDoubleMeasurement result =
new ObservableDoubleMeasurement() {
@Override
public void observe(double value, Attributes attributes) {
T accumulation =
aggregator.accumulateDoubleMeasurement(value, attributes, Context.current());
if (accumulation != null) {
measurementAccumulator.record(
attributesProcessor.process(attributes, Context.current()), accumulation);
}
}
@Override
public void observe(double value) {
observe(value, Attributes.empty());
}
};
return new AsynchronousMetricStorage<>(
metricDescriptor, aggregator, measurementAccumulator, () -> metricUpdater.accept(result));
}