use of org.spf4j.base.AbstractRunnable in project spf4j by zolyfarkas.
the class GraphiteUdpStoreTest method runUdpServer.
@BeforeClass
public static void runUdpServer() {
server = org.spf4j.concurrent.DefaultExecutor.INSTANCE.submit(new AbstractRunnable(true) {
@Override
public void doRun() throws IOException, InterruptedException {
DatagramChannel channel = DatagramChannel.open();
final InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 1976);
channel.socket().bind(inetSocketAddress);
ByteBuffer bb = ByteBuffer.allocate(512);
while (!terminated) {
bb.rewind();
try {
channel.receive(bb);
} catch (ClosedByInterruptException ex) {
// this we receive when we interrupt this exec with server.cancel.
break;
}
byte[] rba = new byte[bb.position()];
bb.rewind();
bb.get(rba);
String receivedString = new String(rba, Charsets.UTF_8);
String[] lines = receivedString.split("\n");
LOG.debug("Received = {}", lines);
for (String line : lines) {
QUEUE.put(line);
}
}
}
});
}
Aggregations