📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
		| @@ -35,17 +35,15 @@ import java.net.UnknownHostException; | ||||
| import java.util.concurrent.ExecutorService; | ||||
| import java.util.concurrent.Executors; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * Represents the clients of Reactor pattern. Multiple clients are run concurrently and send logging | ||||
|  * requests to Reactor. | ||||
|  */ | ||||
| @Slf4j | ||||
| public class AppClient { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(AppClient.class); | ||||
|  | ||||
|   private final ExecutorService service = Executors.newFixedThreadPool(4); | ||||
|  | ||||
|   /** | ||||
|   | ||||
| @@ -28,17 +28,15 @@ import com.iluwatar.reactor.framework.ChannelHandler; | ||||
| import com.iluwatar.reactor.framework.NioDatagramChannel.DatagramPacket; | ||||
| import java.nio.ByteBuffer; | ||||
| import java.nio.channels.SelectionKey; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * Logging server application logic. It logs the incoming requests on standard console and returns a | ||||
|  * canned acknowledgement back to the remote peer. | ||||
|  */ | ||||
| @Slf4j | ||||
| public class LoggingHandler implements ChannelHandler { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(LoggingHandler.class); | ||||
|  | ||||
|   private static final byte[] ACK = "Data logged successfully".getBytes(); | ||||
|  | ||||
|   /** | ||||
|   | ||||
| @@ -30,16 +30,14 @@ import java.net.SocketAddress; | ||||
| import java.nio.ByteBuffer; | ||||
| import java.nio.channels.DatagramChannel; | ||||
| import java.nio.channels.SelectionKey; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * A wrapper over {@link DatagramChannel} which can read and write data on a DatagramChannel. | ||||
|  */ | ||||
| @Slf4j | ||||
| public class NioDatagramChannel extends AbstractNioChannel { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(NioDatagramChannel.class); | ||||
|  | ||||
|   private final int port; | ||||
|  | ||||
|   /** | ||||
|   | ||||
| @@ -32,8 +32,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; | ||||
| import java.util.concurrent.ExecutorService; | ||||
| import java.util.concurrent.Executors; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * This class acts as Synchronous Event De-multiplexer and Initiation Dispatcher of Reactor pattern. | ||||
| @@ -50,10 +49,9 @@ import org.slf4j.LoggerFactory; | ||||
|  * possible edge cases which are required in a real application. This implementation is meant to | ||||
|  * demonstrate the fundamental concepts that lie behind Reactor pattern. | ||||
|  */ | ||||
| @Slf4j | ||||
| public class NioReactor { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(NioReactor.class); | ||||
|  | ||||
|   private final Selector selector; | ||||
|   private final Dispatcher dispatcher; | ||||
|   /** | ||||
|   | ||||
| @@ -30,17 +30,15 @@ import java.nio.ByteBuffer; | ||||
| import java.nio.channels.SelectionKey; | ||||
| import java.nio.channels.ServerSocketChannel; | ||||
| import java.nio.channels.SocketChannel; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
|  | ||||
| /** | ||||
|  * A wrapper over {@link NioServerSocketChannel} which can read and write data on a {@link | ||||
|  * SocketChannel}. | ||||
|  */ | ||||
| @Slf4j | ||||
| public class NioServerSocketChannel extends AbstractNioChannel { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(NioServerSocketChannel.class); | ||||
|  | ||||
|   private final int port; | ||||
|  | ||||
|   /** | ||||
|   | ||||
| @@ -23,23 +23,20 @@ | ||||
|  | ||||
| package com.iluwatar.reactor.app; | ||||
|  | ||||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||||
|  | ||||
| import com.iluwatar.reactor.framework.SameThreadDispatcher; | ||||
| import com.iluwatar.reactor.framework.ThreadPoolDispatcher; | ||||
| import java.io.IOException; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.junit.jupiter.api.Test; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||||
|  | ||||
| /** | ||||
|  * This class tests the Distributed Logging service by starting a Reactor and then sending it | ||||
|  * concurrent logging requests using multiple clients. | ||||
|  */ | ||||
| public class ReactorTest { | ||||
|  | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(ReactorTest.class); | ||||
| @Slf4j | ||||
| class ReactorTest { | ||||
|  | ||||
|   /** | ||||
|    * Test the application using pooled thread dispatcher. | ||||
| @@ -48,7 +45,7 @@ public class ReactorTest { | ||||
|    * @throws InterruptedException if interrupted while stopping the application. | ||||
|    */ | ||||
|   @Test | ||||
|   public void testAppUsingThreadPoolDispatcher() throws IOException, InterruptedException { | ||||
|   void testAppUsingThreadPoolDispatcher() throws IOException, InterruptedException { | ||||
|     LOGGER.info("testAppUsingThreadPoolDispatcher start"); | ||||
|     var app = new App(new ThreadPoolDispatcher(2)); | ||||
|     app.start(); | ||||
| @@ -80,7 +77,7 @@ public class ReactorTest { | ||||
|    * @throws InterruptedException if interrupted while stopping the application. | ||||
|    */ | ||||
|   @Test | ||||
|   public void testAppUsingSameThreadDispatcher() throws IOException, InterruptedException { | ||||
|   void testAppUsingSameThreadDispatcher() throws IOException, InterruptedException { | ||||
|     LOGGER.info("testAppUsingSameThreadDispatcher start"); | ||||
|     var app = new App(new SameThreadDispatcher()); | ||||
|     app.start(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user