com.codahale.metrics.collectd.Sender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metrics-collectd Show documentation
Show all versions of metrics-collectd Show documentation
A reporter for Metrics which announces measurements to Collectd.
The newest version!
package com.codahale.metrics.collectd;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
public class Sender {
private final String host;
private final int port;
private InetSocketAddress address;
private DatagramChannel channel;
public Sender(String host, int port) {
this.host = host;
this.port = port;
}
public void connect() throws IOException {
if (isConnected()) {
throw new IllegalStateException("Already connected");
}
if (host != null) {
address = new InetSocketAddress(host, port);
}
channel = DatagramChannel.open();
}
public boolean isConnected() {
return channel != null && !channel.socket().isClosed();
}
public void send(ByteBuffer buffer) throws IOException {
channel.send(buffer, address);
}
public void disconnect() throws IOException {
if (channel == null) {
return;
}
try {
channel.close();
} finally {
channel = null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy