#596 Add more logging to Reactor
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,13 @@ package com.iluwatar.reactor.app;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.iluwatar.reactor.framework.NioReactor;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.reactor.framework.SameThreadDispatcher;
|
||||
import com.iluwatar.reactor.framework.ThreadPoolDispatcher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -36,6 +39,8 @@ import com.iluwatar.reactor.framework.ThreadPoolDispatcher;
|
||||
*/
|
||||
public class ReactorTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ReactorTest.class);
|
||||
|
||||
/**
|
||||
* Test the application using pooled thread dispatcher.
|
||||
*
|
||||
@ -44,6 +49,7 @@ public class ReactorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testAppUsingThreadPoolDispatcher() throws IOException, InterruptedException {
|
||||
LOGGER.info("testAppUsingThreadPoolDispatcher start");
|
||||
App app = new App(new ThreadPoolDispatcher(2));
|
||||
app.start();
|
||||
|
||||
@ -54,12 +60,13 @@ public class ReactorTest {
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("sleep interrupted", e);
|
||||
}
|
||||
|
||||
client.stop();
|
||||
|
||||
app.stop();
|
||||
LOGGER.info("testAppUsingThreadPoolDispatcher stop");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,6 +77,7 @@ public class ReactorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testAppUsingSameThreadDispatcher() throws IOException, InterruptedException {
|
||||
LOGGER.info("testAppUsingSameThreadDispatcher start");
|
||||
App app = new App(new SameThreadDispatcher());
|
||||
app.start();
|
||||
|
||||
@ -80,11 +88,12 @@ public class ReactorTest {
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("sleep interrupted", e);
|
||||
}
|
||||
|
||||
client.stop();
|
||||
|
||||
app.stop();
|
||||
LOGGER.info("testAppUsingSameThreadDispatcher stop");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user