#596 Add more logging to Reactor

This commit is contained in:
Ilkka Seppälä
2017-08-19 11:00:34 +03:00
parent 5db6776971
commit ed1a0022b9
3 changed files with 20 additions and 8 deletions
@@ -65,6 +65,7 @@ public class AppClient {
* @throws IOException if any I/O error occurs.
*/
public void start() throws IOException {
LOGGER.info("Starting logging clients");
service.execute(new TcpLoggingClient("Client 1", 6666));
service.execute(new TcpLoggingClient("Client 2", 6667));
service.execute(new UdpLoggingClient("Client 3", 6668));
@@ -81,16 +82,17 @@ public class AppClient {
try {
service.awaitTermination(1000, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER.error("exception awaiting termination", e);
}
}
LOGGER.info("Logging clients stopped");
}
private static void artificialDelayOf(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER.error("sleep interrupted", e);
}
}
@@ -119,7 +121,7 @@ public class AppClient {
PrintWriter writer = new PrintWriter(outputStream);
sendLogRequests(writer, socket.getInputStream());
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("error sending requests", e);
throw new RuntimeException(e);
}
}
@@ -185,7 +187,7 @@ public class AppClient {
artificialDelayOf(100);
}
} catch (IOException e1) {
e1.printStackTrace();
LOGGER.error("error sending packets", e1);
}
}
}
@@ -94,7 +94,7 @@ public class NioReactor {
LOGGER.info("Reactor started, waiting for events...");
eventLoop();
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("exception in event loop", e);
}
});
}
@@ -112,6 +112,7 @@ public class NioReactor {
selector.wakeup();
reactorMain.awaitTermination(4, TimeUnit.SECONDS);
selector.close();
LOGGER.info("Reactor stopped");
}
/**
@@ -206,7 +207,7 @@ public class NioReactor {
try {
key.channel().close();
} catch (IOException e1) {
e1.printStackTrace();
LOGGER.error("error closing channel", e1);
}
}
}