📍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:
@ -26,8 +26,7 @@ package com.iluwatar.queue.load.leveling;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Many solutions in the cloud involve running tasks that invoke services. In this environment, if a
|
||||
@ -58,10 +57,9 @@ import org.slf4j.LoggerFactory;
|
||||
* MessageQueue. The service executor class {@link ServiceExecutor} will pick up one task at a time
|
||||
* from the Queue and execute them.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
//Executor shut down time limit.
|
||||
private static final int SHUTDOWN_TIME = 15;
|
||||
|
||||
|
@ -23,22 +23,17 @@
|
||||
|
||||
package com.iluwatar.queue.load.leveling;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Message class with only one parameter.
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class Message {
|
||||
private final String msg;
|
||||
|
||||
// Parameter constructor.
|
||||
public Message(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
// Get Method for attribute msg.
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return msg;
|
||||
|
@ -25,17 +25,15 @@ package com.iluwatar.queue.load.leveling;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* MessageQueue class. In this class we will create a Blocking Queue and submit/retrieve all the
|
||||
* messages from it.
|
||||
*/
|
||||
@Slf4j
|
||||
public class MessageQueue {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
private final BlockingQueue<Message> blkQueue;
|
||||
|
||||
// Default constructor when called creates Blocking Queue object.
|
||||
|
@ -23,17 +23,15 @@
|
||||
|
||||
package com.iluwatar.queue.load.leveling;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* ServiceExecuotr class. This class will pick up Messages one by one from the Blocking Queue and
|
||||
* process them.
|
||||
*/
|
||||
@Slf4j
|
||||
public class ServiceExecutor implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
private final MessageQueue msgQueue;
|
||||
|
||||
public ServiceExecutor(MessageQueue msgQueue) {
|
||||
|
@ -23,18 +23,15 @@
|
||||
|
||||
package com.iluwatar.queue.load.leveling;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* TaskGenerator class. Each TaskGenerator thread will be a Worker which submit's messages to the
|
||||
* queue. We need to mention the message count for each of the TaskGenerator threads.
|
||||
*/
|
||||
@Slf4j
|
||||
public class TaskGenerator implements Task, Runnable {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
// MessageQueue reference using which we will submit our messages.
|
||||
private final MessageQueue msgQueue;
|
||||
|
||||
|
@ -30,10 +30,10 @@ import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* Test case for submitting and retrieving messages from Blocking Queue.
|
||||
*/
|
||||
public class MessageQueueTest {
|
||||
class MessageQueueTest {
|
||||
|
||||
@Test
|
||||
public void messageQueueTest() {
|
||||
void messageQueueTest() {
|
||||
|
||||
var msgQueue = new MessageQueue();
|
||||
|
||||
|
@ -30,10 +30,10 @@ import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* Test case for creating and checking the Message.
|
||||
*/
|
||||
public class MessageTest {
|
||||
class MessageTest {
|
||||
|
||||
@Test
|
||||
public void messageTest() {
|
||||
void messageTest() {
|
||||
|
||||
// Parameterized constructor test.
|
||||
var testMsg = "Message Test";
|
||||
|
Reference in New Issue
Block a user