use of org.collectd.api.Notification in project jcollectd by collectd.
the class UdpReceiver method parse.
public void parse(byte[] packet) throws IOException {
int total = packet.length;
ByteArrayInputStream buffer = new ByteArrayInputStream(packet);
DataInputStream is = new DataInputStream(buffer);
PacketObject obj = new PacketObject();
while ((0 < total) && (total > Network.HEADER_LEN)) {
int type = is.readUnsignedShort();
int len = is.readUnsignedShort();
if (len < Network.HEADER_LEN) {
//packet was filled to the brim
break;
}
total -= len;
len -= Network.HEADER_LEN;
if (type == Network.TYPE_VALUES) {
readValues(is, obj.getValueList());
} else if (type == Network.TYPE_TIME) {
obj.pd.setTime(is.readLong() * 1000);
} else if (type == Network.TYPE_INTERVAL) {
obj.getValueList().setInterval(is.readLong());
} else if (type == Network.TYPE_HOST) {
obj.pd.setHost(readString(is, len));
} else if (type == Network.TYPE_PLUGIN) {
obj.pd.setPlugin(readString(is, len));
} else if (type == Network.TYPE_PLUGIN_INSTANCE) {
obj.pd.setPluginInstance(readString(is, len));
} else if (type == Network.TYPE_TYPE) {
obj.pd.setType(readString(is, len));
} else if (type == Network.TYPE_TYPE_INSTANCE) {
obj.pd.setTypeInstance(readString(is, len));
} else if (type == Network.TYPE_MESSAGE) {
Notification notif = obj.getNotification();
notif.setMessage(readString(is, len));
if (_dispatcher != null) {
_dispatcher.dispatch(notif);
}
} else if (type == Network.TYPE_SEVERITY) {
obj.getNotification().setSeverity((int) is.readLong());
} else {
break;
}
}
}
use of org.collectd.api.Notification in project metrics by dropwizard.
the class Receiver method before.
@Override
protected void before() throws Throwable {
receiver = new UdpReceiver(new Dispatcher() {
@Override
public void dispatch(ValueList values) {
queue.offer(new ValueList(values));
}
@Override
public void dispatch(Notification notification) {
throw new UnsupportedOperationException();
}
});
receiver.setPort(port);
new Thread(() -> {
try {
receiver.listen();
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
Aggregations