com.wavefront.ingester.PickleProtocolDecoder Maven / Gradle / Ivy
The newest version!
package com.wavefront.ingester;
import com.google.common.base.Preconditions;
import com.wavefront.common.MetricMangler;
import net.razorvine.pickle.Unpickler;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import wavefront.report.ReportPoint;
/**
* Pickle protocol format decoder.
* https://docs.python.org/2/library/pickle.html
* @author Mike McLaughlin ([email protected])
*/
@Deprecated
public class PickleProtocolDecoder implements ReportableEntityDecoder {
protected static final Logger logger = Logger.getLogger(
PickleProtocolDecoder.class.getCanonicalName());
private final int port;
private final String defaultHostName;
private final List customSourceTags;
private final MetricMangler metricMangler;
private final ThreadLocal unpicklerThreadLocal = ThreadLocal.withInitial(
Unpickler::new);
/**
* Constructor.
* @param hostName the default host name.
* @param customSourceTags list of source tags for this host.
* @param mangler the metric mangler object.
* @param port the listening port (for debug logging)
*/
public PickleProtocolDecoder(String hostName, List customSourceTags,
MetricMangler mangler, int port) {
Preconditions.checkNotNull(hostName);
this.defaultHostName = hostName;
Preconditions.checkNotNull(customSourceTags);
this.customSourceTags = customSourceTags;
this.metricMangler = mangler;
this.port = port;
}
@Override
public void decode(byte[] msg, List out, String customerId, IngesterContext ctx) {
InputStream is = new ByteArrayInputStream(msg);
Object dataRaw;
try {
dataRaw = unpicklerThreadLocal.get().load(is);
if (!(dataRaw instanceof List)) {
throw new IllegalArgumentException(
String.format("[%d] unable to unpickle data (unpickle did not return list)", port));
}
} catch (final IOException ioe) {
throw new IllegalArgumentException(String.format("[%d] unable to unpickle data", port), ioe);
}
// [(path, (timestamp, value)), ...]
List