com.eg.agent.android.measurement.producer.BaseMeasurementProducer Maven / Gradle / Ivy
package com.eg.agent.android.measurement.producer;
import com.eg.agent.android.logging.AgentLog;
import com.eg.agent.android.logging.AgentLogManager;
import com.eg.agent.android.measurement.Measurement;
import com.eg.agent.android.measurement.MeasurementType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class BaseMeasurementProducer implements MeasurementProducer {
private static final AgentLog log = AgentLogManager.getAgentLog();
private final MeasurementType producedMeasurementType;
private final ArrayList producedMeasurements = new ArrayList();
public BaseMeasurementProducer(MeasurementType measurementType) {
this.producedMeasurementType = measurementType;
}
public MeasurementType getMeasurementType() {
return this.producedMeasurementType;
}
public void produceMeasurement(Measurement measurement) {
synchronized (this.producedMeasurements) {
if (measurement != null) {
this.producedMeasurements.add(measurement);
}
}
}
public void produceMeasurements(Collection measurements) {
synchronized (this.producedMeasurements) {
if (measurements != null) {
this.producedMeasurements.addAll(measurements);
do {
} while (this.producedMeasurements.remove(null));
}
}
}
public Collection drainMeasurements() {
Collection emptyList;
synchronized (this.producedMeasurements) {
if (this.producedMeasurements.size() == 0) {
emptyList = Collections.emptyList();
} else {
emptyList = new ArrayList(this.producedMeasurements);
this.producedMeasurements.clear();
}
}
return emptyList;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy