#502 Replaced usages of System.out with logger.
This commit is contained in:
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.reactor.app;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -41,6 +44,9 @@ import java.util.concurrent.TimeUnit;
|
||||
* requests to Reactor.
|
||||
*/
|
||||
public class AppClient {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AppClient.class);
|
||||
|
||||
private final ExecutorService service = Executors.newFixedThreadPool(4);
|
||||
|
||||
/**
|
||||
@ -126,9 +132,9 @@ public class AppClient {
|
||||
byte[] data = new byte[1024];
|
||||
int read = inputStream.read(data, 0, data.length);
|
||||
if (read == 0) {
|
||||
System.out.println("Read zero bytes");
|
||||
LOGGER.info("Read zero bytes");
|
||||
} else {
|
||||
System.out.println(new String(data, 0, read));
|
||||
LOGGER.info(new String(data, 0, read));
|
||||
}
|
||||
|
||||
artificialDelayOf(100);
|
||||
@ -171,9 +177,9 @@ public class AppClient {
|
||||
DatagramPacket reply = new DatagramPacket(data, data.length);
|
||||
socket.receive(reply);
|
||||
if (reply.getLength() == 0) {
|
||||
System.out.println("Read zero bytes");
|
||||
LOGGER.info("Read zero bytes");
|
||||
} else {
|
||||
System.out.println(new String(reply.getData(), 0, reply.getLength()));
|
||||
LOGGER.info(new String(reply.getData(), 0, reply.getLength()));
|
||||
}
|
||||
|
||||
artificialDelayOf(100);
|
||||
|
@ -28,6 +28,8 @@ import java.nio.channels.SelectionKey;
|
||||
import com.iluwatar.reactor.framework.AbstractNioChannel;
|
||||
import com.iluwatar.reactor.framework.ChannelHandler;
|
||||
import com.iluwatar.reactor.framework.NioDatagramChannel.DatagramPacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Logging server application logic. It logs the incoming requests on standard console and returns a
|
||||
@ -35,6 +37,8 @@ import com.iluwatar.reactor.framework.NioDatagramChannel.DatagramPacket;
|
||||
*/
|
||||
public class LoggingHandler implements ChannelHandler {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingHandler.class);
|
||||
|
||||
private static final byte[] ACK = "Data logged successfully".getBytes();
|
||||
|
||||
/**
|
||||
@ -76,6 +80,6 @@ public class LoggingHandler implements ChannelHandler {
|
||||
|
||||
private static void doLogging(ByteBuffer data) {
|
||||
// assuming UTF-8 :(
|
||||
System.out.println(new String(data.array(), 0, data.limit()));
|
||||
LOGGER.info(new String(data.array(), 0, data.limit()));
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.reactor.framework;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -35,6 +38,8 @@ import java.nio.channels.SelectionKey;
|
||||
*/
|
||||
public class NioDatagramChannel extends AbstractNioChannel {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NioDatagramChannel.class);
|
||||
|
||||
private final int port;
|
||||
|
||||
/**
|
||||
@ -99,7 +104,7 @@ public class NioDatagramChannel extends AbstractNioChannel {
|
||||
public void bind() throws IOException {
|
||||
getJavaChannel().socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), port));
|
||||
getJavaChannel().configureBlocking(false);
|
||||
System.out.println("Bound UDP socket at port: " + port);
|
||||
LOGGER.info("Bound UDP socket at port: {}", port);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.reactor.framework;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
@ -53,6 +56,8 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class NioReactor {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NioReactor.class);
|
||||
|
||||
private final Selector selector;
|
||||
private final Dispatcher dispatcher;
|
||||
/**
|
||||
@ -86,7 +91,7 @@ public class NioReactor {
|
||||
public void start() throws IOException {
|
||||
reactorMain.execute(() -> {
|
||||
try {
|
||||
System.out.println("Reactor started, waiting for events...");
|
||||
LOGGER.info("Reactor started, waiting for events...");
|
||||
eventLoop();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.reactor.framework;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -36,6 +39,8 @@ import java.nio.channels.SocketChannel;
|
||||
*/
|
||||
public class NioServerSocketChannel extends AbstractNioChannel {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NioServerSocketChannel.class);
|
||||
|
||||
private final int port;
|
||||
|
||||
/**
|
||||
@ -96,7 +101,7 @@ public class NioServerSocketChannel extends AbstractNioChannel {
|
||||
((ServerSocketChannel) getJavaChannel()).socket().bind(
|
||||
new InetSocketAddress(InetAddress.getLocalHost(), port));
|
||||
((ServerSocketChannel) getJavaChannel()).configureBlocking(false);
|
||||
System.out.println("Bound TCP socket at port: " + port);
|
||||
LOGGER.info("Bound TCP socket at port: {}", port);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user