📍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.event.asynchronous;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Scanner;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* This application demonstrates the <b>Event-based Asynchronous</b> pattern. Essentially, users (of
|
||||
@ -55,10 +54,9 @@ import org.slf4j.LoggerFactory;
|
||||
* @see EventManager
|
||||
* @see Event
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
public static final String PROP_FILE_NAME = "config.properties";
|
||||
|
||||
boolean interactiveMode = false;
|
||||
|
@ -23,40 +23,25 @@
|
||||
|
||||
package com.iluwatar.event.asynchronous;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Each Event runs as a separate/individual thread.
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class Event implements IEvent, Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Event.class);
|
||||
|
||||
private final int eventId;
|
||||
private final int eventTime;
|
||||
private final boolean isSynchronous;
|
||||
@Getter
|
||||
private final boolean synchronous;
|
||||
private Thread thread;
|
||||
private boolean isComplete = false;
|
||||
private ThreadCompleteListener eventListener;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param eventId event ID
|
||||
* @param eventTime event time
|
||||
* @param isSynchronous is of synchronous type
|
||||
*/
|
||||
public Event(final int eventId, final int eventTime, final boolean isSynchronous) {
|
||||
this.eventId = eventId;
|
||||
this.eventTime = eventTime;
|
||||
this.isSynchronous = isSynchronous;
|
||||
}
|
||||
|
||||
public boolean isSynchronous() {
|
||||
return isSynchronous;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
thread = new Thread(this);
|
||||
@ -88,6 +73,7 @@ public class Event implements IEvent, Runnable {
|
||||
try {
|
||||
Thread.sleep(1000); // Sleep for 1 second.
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class EventManager implements ThreadCompleteListener {
|
||||
*/
|
||||
public EventManager() {
|
||||
rand = new SecureRandom();
|
||||
eventPool = new ConcurrentHashMap<Integer, Event>(MAX_RUNNING_EVENTS);
|
||||
eventPool = new ConcurrentHashMap<>(MAX_RUNNING_EVENTS);
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,11 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
public class EventAsynchronousTest {
|
||||
class EventAsynchronousTest {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(EventAsynchronousTest.class);
|
||||
|
||||
@Test
|
||||
public void testAsynchronousEvent() {
|
||||
void testAsynchronousEvent() {
|
||||
var eventManager = new EventManager();
|
||||
try {
|
||||
var aEventId = eventManager.createAsync(60);
|
||||
@ -55,7 +55,7 @@ public class EventAsynchronousTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSynchronousEvent() {
|
||||
void testSynchronousEvent() {
|
||||
var eventManager = new EventManager();
|
||||
try {
|
||||
var sEventId = eventManager.create(60);
|
||||
@ -72,7 +72,7 @@ public class EventAsynchronousTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsuccessfulSynchronousEvent() {
|
||||
void testUnsuccessfulSynchronousEvent() {
|
||||
assertThrows(InvalidOperationException.class, () -> {
|
||||
var eventManager = new EventManager();
|
||||
try {
|
||||
@ -87,7 +87,7 @@ public class EventAsynchronousTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullSynchronousEvent() {
|
||||
void testFullSynchronousEvent() {
|
||||
var eventManager = new EventManager();
|
||||
try {
|
||||
var eventTime = 1;
|
||||
@ -110,7 +110,7 @@ public class EventAsynchronousTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullAsynchronousEvent() {
|
||||
void testFullAsynchronousEvent() {
|
||||
var eventManager = new EventManager();
|
||||
try {
|
||||
var eventTime = 1;
|
||||
|
Reference in New Issue
Block a user