
com.newrelic.insights.publish.Event Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of insights_client Show documentation
Show all versions of insights_client Show documentation
a java client library for posting events to New Relic Insights
package com.newrelic.insights.publish;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class Event {
private static final String PROPERTY_NAME_EVENT_TYPE = "eventType";
private static ObjectMapper mapper = new ObjectMapper();
private ObjectNode objectNode;
public Event(String eventType) {
objectNode = mapper.createObjectNode();
objectNode.put(PROPERTY_NAME_EVENT_TYPE, eventType);
}
public static Event create(String eventType) {
Event event = new Event(eventType);
return event;
}
public Event put(String key, String value) {
objectNode.put(key, value);
return this;
}
public Event put(String key, Number value) {
if(value == null) {
return this;
}
if(value instanceof Double) {
objectNode.put(key, (Double)value);
} else if(value instanceof Float) {
objectNode.put(key, (Float)value);
} else if(value instanceof Integer) {
objectNode.put(key, (Integer)value);
} else if(value instanceof Long) {
objectNode.put(key, (Float)value);
} else {
objectNode.putPOJO(key, value);
}
return this;
}
protected ObjectNode getObjectNode() {
return objectNode;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy