Skip to content

Commit 5ae2ce6

Browse files
anuragagarwal561994iluwatar
authored andcommitted
Resolves checkstyle errors for event-* (iluwatar#1070)
* Reduces checkstyle errors in event-aggregator * Reduces checkstyle errors in event-asynchronous * Reduces checkstyle errors in event-driven-architecture * Reduces checkstyle errors in event-queue * Reduces checkstyle errors in event-sourcing
1 parent 7c888e8 commit 5ae2ce6

38 files changed

+208
-229
lines changed

event-aggregator/src/main/java/com/iluwatar/event/aggregator/App.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,22 @@
2727
import java.util.List;
2828

2929
/**
30-
*
3130
* A system with lots of objects can lead to complexities when a client wants to subscribe to
3231
* events. The client has to find and register for each object individually, if each object has
3332
* multiple events then each event requires a separate subscription.
34-
* <p>
35-
* An Event Aggregator acts as a single source of events for many objects. It registers for all the
36-
* events of the many objects allowing clients to register with just the aggregator.
37-
* <p>
38-
* In the example {@link LordBaelish}, {@link LordVarys} and {@link Scout} deliver events to
39-
* {@link KingsHand}. {@link KingsHand}, the event aggregator, then delivers the events to
40-
* {@link KingJoffrey}.
4133
*
34+
* <p>An Event Aggregator acts as a single source of events for many objects. It registers for all
35+
* the events of the many objects allowing clients to register with just the aggregator.
36+
*
37+
* <p>In the example {@link LordBaelish}, {@link LordVarys} and {@link Scout} deliver events to
38+
* {@link KingsHand}. {@link KingsHand}, the event aggregator, then delivers the events to {@link
39+
* KingJoffrey}.
4240
*/
4341
public class App {
4442

4543
/**
46-
* Program entry point
47-
*
44+
* Program entry point.
45+
*
4846
* @param args command line args
4947
*/
5048
public static void main(String[] args) {

event-aggregator/src/main/java/com/iluwatar/event/aggregator/Event.java

-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.event.aggregator;
2525

2626
/**
27-
*
2827
* Event enumeration.
29-
*
3028
*/
3129
public enum Event {
3230

event-aggregator/src/main/java/com/iluwatar/event/aggregator/EventEmitter.java

-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import java.util.List;
2828

2929
/**
30-
*
3130
* EventEmitter is the base class for event producers that can be observed.
32-
*
3331
*/
3432
public abstract class EventEmitter {
3533

event-aggregator/src/main/java/com/iluwatar/event/aggregator/EventObserver.java

-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.event.aggregator;
2525

2626
/**
27-
*
2827
* Observers of events implement this interface.
29-
*
3028
*/
3129
public interface EventObserver {
3230

event-aggregator/src/main/java/com/iluwatar/event/aggregator/KingJoffrey.java

-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
30-
*
3130
* KingJoffrey observes events from {@link KingsHand}.
32-
*
3331
*/
3432
public class KingJoffrey implements EventObserver {
3533

event-aggregator/src/main/java/com/iluwatar/event/aggregator/KingsHand.java

-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.event.aggregator;
2525

2626
/**
27-
*
2827
* KingsHand observes events from multiple sources and delivers them to listeners.
29-
*
3028
*/
3129
public class KingsHand extends EventEmitter implements EventObserver {
3230

event-aggregator/src/main/java/com/iluwatar/event/aggregator/LordBaelish.java

-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.event.aggregator;
2525

2626
/**
27-
*
2827
* LordBaelish produces events.
29-
*
3028
*/
3129
public class LordBaelish extends EventEmitter {
3230

event-aggregator/src/main/java/com/iluwatar/event/aggregator/LordVarys.java

-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.event.aggregator;
2525

2626
/**
27-
*
2827
* LordVarys produces events.
29-
*
3028
*/
3129
public class LordVarys extends EventEmitter {
3230

event-aggregator/src/main/java/com/iluwatar/event/aggregator/Scout.java

-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.event.aggregator;
2525

2626
/**
27-
*
2827
* Scout produces events.
29-
*
3028
*/
3129
public class Scout extends EventEmitter {
3230

event-aggregator/src/main/java/com/iluwatar/event/aggregator/Weekday.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.event.aggregator;
2525

2626
/**
27-
*
28-
* Weekday enumeration
29-
*
27+
* Weekday enumeration.
3028
*/
3129
public enum Weekday {
3230

event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/App.java

+43-42
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,38 @@
2323

2424
package com.iluwatar.event.asynchronous;
2525

26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
28-
2926
import java.io.IOException;
3027
import java.io.InputStream;
3128
import java.util.Properties;
3229
import java.util.Scanner;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3332

3433
/**
34+
* This application demonstrates the <b>Event-based Asynchronous</b> pattern. Essentially, users (of
35+
* the pattern) may choose to run events in an Asynchronous or Synchronous mode. There can be
36+
* multiple Asynchronous events running at once but only one Synchronous event can run at a time.
37+
* Asynchronous events are synonymous to multi-threads. The key point here is that the threads run
38+
* in the background and the user is free to carry on with other processes. Once an event is
39+
* complete, the appropriate listener/callback method will be called. The listener then proceeds to
40+
* carry out further processing depending on the needs of the user.
3541
*
36-
* This application demonstrates the <b>Event-based Asynchronous</b> pattern. Essentially, users (of the pattern) may
37-
* choose to run events in an Asynchronous or Synchronous mode. There can be multiple Asynchronous events running at
38-
* once but only one Synchronous event can run at a time. Asynchronous events are synonymous to multi-threads. The key
39-
* point here is that the threads run in the background and the user is free to carry on with other processes. Once an
40-
* event is complete, the appropriate listener/callback method will be called. The listener then proceeds to carry out
41-
* further processing depending on the needs of the user.
42+
* <p>The {@link EventManager} manages the events/threads that the user creates. Currently, the
43+
* supported event operations are: <code>start</code>, <code>stop</code>, <code>getStatus</code>.
44+
* For Synchronous events, the user is unable to start another (Synchronous) event if one is already
45+
* running at the time. The running event would have to either be stopped or completed before a new
46+
* event can be started.
4247
*
43-
* The {@link EventManager} manages the events/threads that the user creates. Currently, the supported event operations
44-
* are: <code>start</code>, <code>stop</code>, <code>getStatus</code>. For Synchronous events, the user is unable to
45-
* start another (Synchronous) event if one is already running at the time. The running event would have to either be
46-
* stopped or completed before a new event can be started.
47-
*
48-
* The Event-based Asynchronous Pattern makes available the advantages of multithreaded applications while hiding many
49-
* of the complex issues inherent in multithreaded design. Using a class that supports this pattern can allow you to:-
50-
* (1) Perform time-consuming tasks, such as downloads and database operations, "in the background," without
51-
* interrupting your application. (2) Execute multiple operations simultaneously, receiving notifications when each
52-
* completes. (3) Wait for resources to become available without stopping ("hanging") your application. (4) Communicate
53-
* with pending asynchronous operations using the familiar events-and-delegates model.
48+
* <p>The Event-based Asynchronous Pattern makes available the advantages of multithreaded
49+
* applications while hiding many of the complex issues inherent in multithreaded design. Using a
50+
* class that supports this pattern can allow you to:- (1) Perform time-consuming tasks, such as
51+
* downloads and database operations, "in the background," without interrupting your application.
52+
* (2) Execute multiple operations simultaneously, receiving notifications when each completes. (3)
53+
* Wait for resources to become available without stopping ("hanging") your application. (4)
54+
* Communicate with pending asynchronous operations using the familiar events-and-delegates model.
5455
*
5556
* @see EventManager
5657
* @see Event
57-
*
5858
*/
5959
public class App {
6060

@@ -67,8 +67,7 @@ public class App {
6767
/**
6868
* Program entry point.
6969
*
70-
* @param args
71-
* command line args
70+
* @param args command line args
7271
*/
7372
public static void main(String[] args) {
7473
App app = new App();
@@ -78,8 +77,9 @@ public static void main(String[] args) {
7877
}
7978

8079
/**
81-
* App can run in interactive mode or not. Interactive mode == Allow user interaction with command line.
82-
* Non-interactive is a quick sequential run through the available {@link EventManager} operations.
80+
* App can run in interactive mode or not. Interactive mode == Allow user interaction with command
81+
* line. Non-interactive is a quick sequential run through the available {@link EventManager}
82+
* operations.
8383
*/
8484
public void setUp() {
8585
Properties prop = new Properties();
@@ -118,24 +118,24 @@ public void quickRun() {
118118

119119
try {
120120
// Create an Asynchronous event.
121-
int aEventId = eventManager.createAsync(60);
122-
LOGGER.info("Async Event [{}] has been created.", aEventId);
123-
eventManager.start(aEventId);
124-
LOGGER.info("Async Event [{}] has been started.", aEventId);
121+
int asyncEventId = eventManager.createAsync(60);
122+
LOGGER.info("Async Event [{}] has been created.", asyncEventId);
123+
eventManager.start(asyncEventId);
124+
LOGGER.info("Async Event [{}] has been started.", asyncEventId);
125125

126126
// Create a Synchronous event.
127-
int sEventId = eventManager.create(60);
128-
LOGGER.info("Sync Event [{}] has been created.", sEventId);
129-
eventManager.start(sEventId);
130-
LOGGER.info("Sync Event [{}] has been started.", sEventId);
127+
int syncEventId = eventManager.create(60);
128+
LOGGER.info("Sync Event [{}] has been created.", syncEventId);
129+
eventManager.start(syncEventId);
130+
LOGGER.info("Sync Event [{}] has been started.", syncEventId);
131131

132-
eventManager.status(aEventId);
133-
eventManager.status(sEventId);
132+
eventManager.status(asyncEventId);
133+
eventManager.status(syncEventId);
134134

135-
eventManager.cancel(aEventId);
136-
LOGGER.info("Async Event [{}] has been stopped.", aEventId);
137-
eventManager.cancel(sEventId);
138-
LOGGER.info("Sync Event [{}] has been stopped.", sEventId);
135+
eventManager.cancel(asyncEventId);
136+
LOGGER.info("Async Event [{}] has been stopped.", asyncEventId);
137+
eventManager.cancel(syncEventId);
138+
LOGGER.info("Sync Event [{}] has been stopped.", syncEventId);
139139

140140
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException
141141
| InvalidOperationException e) {
@@ -211,16 +211,17 @@ private void processOption1(EventManager eventManager, Scanner s) {
211211
int eventId = eventManager.createAsync(eventTime);
212212
eventManager.start(eventId);
213213
LOGGER.info("Egg [{}] is being boiled.", eventId);
214-
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
214+
} catch (MaxNumOfEventsAllowedException | LongRunningEventException
215+
| EventDoesNotExistException e) {
215216
LOGGER.error(e.getMessage());
216217
}
217218
} else if (eventType.equalsIgnoreCase("S")) {
218219
try {
219220
int eventId = eventManager.create(eventTime);
220221
eventManager.start(eventId);
221222
LOGGER.info("Egg [{}] is being boiled.", eventId);
222-
} catch (MaxNumOfEventsAllowedException | InvalidOperationException | LongRunningEventException
223-
| EventDoesNotExistException e) {
223+
} catch (MaxNumOfEventsAllowedException | InvalidOperationException
224+
| LongRunningEventException | EventDoesNotExistException e) {
224225
LOGGER.error(e.getMessage());
225226
}
226227
} else {

event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/Event.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
30-
*
3130
* Each Event runs as a separate/individual thread.
32-
*
3331
*/
3432
public class Event implements IEvent, Runnable {
3533

@@ -43,9 +41,10 @@ public class Event implements IEvent, Runnable {
4341
private ThreadCompleteListener eventListener;
4442

4543
/**
44+
* Constructor.
4645
*
47-
* @param eventId event ID
48-
* @param eventTime event time
46+
* @param eventId event ID
47+
* @param eventTime event time
4948
* @param isSynchronous is of synchronous type
5049
*/
5150
public Event(final int eventId, final int eventTime, final boolean isSynchronous) {

event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/EventDoesNotExistException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
package com.iluwatar.event.asynchronous;
2525

2626
/**
27-
* Custom Exception Class for Non Existent Event
27+
* Custom Exception Class for Non Existent Event.
2828
*/
2929
public class EventDoesNotExistException extends Exception {
3030

event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/EventManager.java

+21-18
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,28 @@
2929
import java.util.concurrent.ConcurrentHashMap;
3030

3131
/**
32-
*
33-
* EventManager handles and maintains a pool of event threads. {@link Event} threads are created upon user request. Thre
34-
* are two types of events; Asynchronous and Synchronous. There can be multiple Asynchronous events running at once but
35-
* only one Synchronous event running at a time. Currently supported event operations are: start, stop, and getStatus.
36-
* Once an event is complete, it then notifies EventManager through a listener. The EventManager then takes the event
37-
* out of the pool.
38-
*
32+
* EventManager handles and maintains a pool of event threads. {@link Event} threads are created
33+
* upon user request. Thre are two types of events; Asynchronous and Synchronous. There can be
34+
* multiple Asynchronous events running at once but only one Synchronous event running at a time.
35+
* Currently supported event operations are: start, stop, and getStatus. Once an event is complete,
36+
* it then notifies EventManager through a listener. The EventManager then takes the event out of
37+
* the pool.
3938
*/
4039
public class EventManager implements ThreadCompleteListener {
4140

42-
public static final int MAX_RUNNING_EVENTS = 1000; // Just don't wanna have too many running events. :)
41+
public static final int MAX_RUNNING_EVENTS = 1000;
42+
// Just don't wanna have too many running events. :)
4343
public static final int MIN_ID = 1;
4444
public static final int MAX_ID = MAX_RUNNING_EVENTS;
4545
public static final int MAX_EVENT_TIME = 1800; // in seconds / 30 minutes.
4646
private int currentlyRunningSyncEvent = -1;
4747
private Random rand;
4848
private Map<Integer, Event> eventPool;
49-
49+
5050
private static final String DOES_NOT_EXIST = " does not exist.";
5151

5252
/**
5353
* EventManager constructor.
54-
*
5554
*/
5655
public EventManager() {
5756
rand = new Random(1);
@@ -65,14 +64,15 @@ public EventManager() {
6564
* @param eventTime Time an event should run for.
6665
* @return eventId
6766
* @throws MaxNumOfEventsAllowedException When too many events are running at a time.
68-
* @throws InvalidOperationException No new synchronous events can be created when one is already running.
69-
* @throws LongRunningEventException Long running events are not allowed in the app.
67+
* @throws InvalidOperationException No new synchronous events can be created when one is
68+
* already running.
69+
* @throws LongRunningEventException Long running events are not allowed in the app.
7070
*/
7171
public int create(int eventTime)
7272
throws MaxNumOfEventsAllowedException, InvalidOperationException, LongRunningEventException {
7373
if (currentlyRunningSyncEvent != -1) {
74-
throw new InvalidOperationException(
75-
"Event [" + currentlyRunningSyncEvent + "] is still running. Please wait until it finishes and try again.");
74+
throw new InvalidOperationException("Event [" + currentlyRunningSyncEvent + "] is still"
75+
+ " running. Please wait until it finishes and try again.");
7676
}
7777

7878
int eventId = createEvent(eventTime, true);
@@ -87,16 +87,18 @@ public int create(int eventTime)
8787
* @param eventTime Time an event should run for.
8888
* @return eventId
8989
* @throws MaxNumOfEventsAllowedException When too many events are running at a time.
90-
* @throws LongRunningEventException Long running events are not allowed in the app.
90+
* @throws LongRunningEventException Long running events are not allowed in the app.
9191
*/
92-
public int createAsync(int eventTime) throws MaxNumOfEventsAllowedException, LongRunningEventException {
92+
public int createAsync(int eventTime) throws MaxNumOfEventsAllowedException,
93+
LongRunningEventException {
9394
return createEvent(eventTime, false);
9495
}
9596

9697
private int createEvent(int eventTime, boolean isSynchronous)
9798
throws MaxNumOfEventsAllowedException, LongRunningEventException {
9899
if (eventPool.size() == MAX_RUNNING_EVENTS) {
99-
throw new MaxNumOfEventsAllowedException("Too many events are running at the moment. Please try again later.");
100+
throw new MaxNumOfEventsAllowedException("Too many events are running at the moment."
101+
+ " Please try again later.");
100102
}
101103

102104
if (eventTime >= MAX_EVENT_TIME) {
@@ -185,7 +187,8 @@ public void shutdown() {
185187
}
186188

187189
/**
188-
* Returns a pseudo-random number between min and max, inclusive. The difference between min and max can be at most
190+
* Returns a pseudo-random number between min and max, inclusive. The difference between min and
191+
* max can be at most
189192
* <code>Integer.MAX_VALUE - 1</code>.
190193
*/
191194
private int generateId() {

event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/IEvent.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
package com.iluwatar.event.asynchronous;
2525

2626
/**
27-
* Events that fulfill the start stop and list out current status behaviour
28-
* follow this interface
27+
* Events that fulfill the start stop and list out current status behaviour follow this interface.
2928
*/
3029
public interface IEvent {
3130

0 commit comments

Comments
 (0)