Package com.newrelic.telemetry.metrics
Class MetricBuffer
- java.lang.Object
-
- com.newrelic.telemetry.metrics.MetricBuffer
-
public final class MetricBuffer extends java.lang.ObjectA buffer for collectingMetrics.One instance of this class can collect many
Metrics. To send them to the Metrics API, callcreateBatch()and thenMetricBatchSender.sendBatch(MetricBatch).This class is thread-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMetricBuffer.Builder
-
Constructor Summary
Constructors Constructor Description MetricBuffer(Attributes commonAttributes)Create a new buffer with the provided common set of attributes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMetric(Metric metric)Append aMetricto this buffer, to be sent in the nextMetricBatch.static MetricBuffer.Builderbuilder()Returns a new Builder instance for help with creating new MetricBatch instancesMetricBatchcreateBatch()Creates a newMetricBatchfrom the contents of this buffer, then clears the contents of this buffer.booleanequals(java.lang.Object o)inthashCode()intsize()Get the size of theMetricsbuffer.java.lang.StringtoString()
-
-
-
Constructor Detail
-
MetricBuffer
public MetricBuffer(Attributes commonAttributes)
Create a new buffer with the provided common set of attributes.- Parameters:
commonAttributes- These attributes will be appended (by the New Relic backend) to everyMetricin this buffer.
-
-
Method Detail
-
addMetric
public void addMetric(Metric metric)
Append aMetricto this buffer, to be sent in the nextMetricBatch.- Parameters:
metric- The newMetricinstance to be sent.
-
createBatch
public MetricBatch createBatch()
Creates a newMetricBatchfrom the contents of this buffer, then clears the contents of this buffer.Metricsadded to this buffer by other threads during this method call will either be added to theMetricBatchbeing created, or will be saved for the nextMetricBatch.- Returns:
- A new
MetricBatchwith an immutable collection ofMetrics.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
builder
public static MetricBuffer.Builder builder()
Returns a new Builder instance for help with creating new MetricBatch instances- Returns:
- a new instance of MetricBatch.Builder
-
-