Skip to content

Commit 42e4c32

Browse files
committed
Checkstyle fix try 2
1 parent 9415119 commit 42e4c32

File tree

6 files changed

+43
-25
lines changed

6 files changed

+43
-25
lines changed

microservices-log-aggregation/src/main/java/com/iluwatar/logaggregation/LogAggregator.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class LogAggregator {
4646
private final ConcurrentLinkedQueue<LogEntry> buffer = new ConcurrentLinkedQueue<>();
4747
private final LogLevel minLogLevel;
4848
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
49-
private final Object bufferWait=new Object();
49+
private final Object bufferWait = new Object();
5050
private final AtomicInteger logCount = new AtomicInteger(0);
5151

5252
/**
@@ -124,9 +124,12 @@ private void startBufferFlusher() {
124124
}
125125
});
126126
}
127-
public void bufferWake(){
128-
synchronized (bufferWait)
129-
{
127+
128+
/**
129+
* Wakes up buffer.
130+
*/
131+
public void bufferWake() {
132+
synchronized (bufferWait) {
130133
bufferWait.notify();
131134
}
132135
}

queue-based-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/ServiceExecutor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ public void run() {
5050
LOGGER.info(msg + " is served.");
5151
} else {
5252
LOGGER.info("Service Executor: Waiting for Messages to serve .. ");
53-
synchronized (msgQueue.serviceExecutorWait)
54-
{
55-
msgQueue.serviceExecutorWait.wait();
53+
synchronized (msgQueue.serviceExecutorWait) {
54+
msgQueue.serviceExecutorWait.wait();
5655
}
5756
}
5857
}

server-session/src/main/java/com/iluwatar/sessionserver/App.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public class App {
5656

5757
// Map to store session data (simulated using a HashMap)
5858

59-
private static Map<String, Integer> sessions = new HashMap<String,Integer>();
60-
private static Map<String, Instant> sessionCreationTimes = new HashMap<String,Instant>();
59+
private static Map<String, Integer> sessions = new HashMap<String, Integer>();
60+
private static Map<String, Instant> sessionCreationTimes = new HashMap<String, Instant>();
6161
private static final long SESSION_EXPIRATION_TIME = 10000;
62-
private static final Object sessionExpirationWait=new Object(); // used to make expiration task wait or work based on event (login request sent or not)
62+
private static final Object sessionExpirationWait = new Object(); // used to make expiration task wait or work based on event (login request sent or not)
6363

6464
/**
6565
* Main entry point.
@@ -84,16 +84,15 @@ public static void main(String[] args) throws IOException {
8484
}
8585

8686
private static void sessionExpirationTask() {
87-
new Thread(() -> {
87+
new Thread(() -> {
8888
while (true) {
8989
try {
90-
synchronized (sessions)
91-
{
92-
if(sessions.isEmpty())
93-
synchronized (sessionExpirationWait)
94-
{
95-
sessionExpirationWait.wait(); // Make Session expiration Checker wait until at least a single login request is sent.
90+
synchronized (sessions) {
91+
if (sessions.isEmpty()) {
92+
synchronized (sessionExpirationWait) {
93+
sessionExpirationWait.wait();
9694
}
95+
}
9796
}
9897
LOGGER.info("Session expiration checker started...");
9998
Thread.sleep(SESSION_EXPIRATION_TIME); // Sleep for expiration time
@@ -121,12 +120,13 @@ private static void sessionExpirationTask() {
121120
}).start();
122121
}
123122

124-
public static void expirationTaskWake() //Wake up sleeping Expiration task thread
125-
{
126-
synchronized (sessionExpirationWait)
127-
{
128-
sessionExpirationWait.notify();
129-
}
123+
/**
124+
* allows sessionExpirationTask to run again, called when a login request is sent.
125+
*/
126+
public static void expirationTaskWake() {
127+
synchronized (sessionExpirationWait) {
128+
sessionExpirationWait.notify();
130129
}
130+
}
131131

132132
}

server-session/src/main/java/com/iluwatar/sessionserver/LoginHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class LoginHandler implements HttpHandler {
4242
private Map<String, Integer> sessions;
4343
private Map<String, Instant> sessionCreationTimes;
4444

45+
/**
46+
* Handles new login requests.
47+
*/
4548
public LoginHandler(Map<String, Integer> sessions, Map<String, Instant> sessionCreationTimes) {
4649
this.sessions = sessions;
4750
this.sessionCreationTimes = sessionCreationTimes;

server-session/src/main/java/com/iluwatar/sessionserver/LogoutHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public class LogoutHandler implements HttpHandler {
4141
private Map<String, Integer> sessions;
4242
private Map<String, Instant> sessionCreationTimes;
4343

44+
/**
45+
* Handles logging out requests.
46+
*/
4447
public LogoutHandler(Map<String, Integer> sessions, Map<String, Instant> sessionCreationTimes) {
4548
this.sessions = sessions;
4649
this.sessionCreationTimes = sessionCreationTimes;

twin/src/main/java/com/iluwatar/twin/BallThread.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void run() {
5353
if (isSuspended) {
5454
synchronized (lock) {
5555
try {
56-
lock.wait(); //Wait until resumed :: busy loop fix
56+
lock.wait();
5757
} catch (InterruptedException e) {
5858
throw new RuntimeException(e);
5959
}
@@ -69,20 +69,30 @@ public void run() {
6969
}
7070
}
7171
}
72-
72+
/**
73+
* suspend the thread.
74+
*/
7375
public void suspendMe() {
7476
isSuspended = true;
7577
LOGGER.info("Begin to suspend BallThread");
7678
}
7779

80+
/**
81+
* notify run to resume.
82+
*/
83+
7884
public void resumeMe() {
7985
isSuspended = false;
8086
LOGGER.info("Begin to resume BallThread");
87+
8188
synchronized (lock) {
8289
lock.notify();
8390
}
8491
}
8592

93+
/**
94+
* Stop running thread.
95+
*/
8696
public void stopMe() {
8797
this.isRunning = false;
8898
this.isSuspended = true;

0 commit comments

Comments
 (0)