use of java.nio.channels.ClosedByInterruptException 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, StandardCharsets.UTF_8);
String[] lines = receivedString.split("\n");
for (int i = 0; i < lines.length; i++) {
LOG.debug("{}: {}", i, lines[i]);
}
for (String line : lines) {
QUEUE.put(line);
}
}
}
});
}
Aggregations