Resolves checkstyle errors for event-* (#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
This commit is contained in:
committed by
Ilkka Seppälä
parent
7c888e8886
commit
5ae2ce6e2e
@ -29,29 +29,28 @@ import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* EventManager handles and maintains a pool of event threads. {@link Event} threads are created upon user request. Thre
|
||||
* are two types of events; Asynchronous and Synchronous. There can be multiple Asynchronous events running at once but
|
||||
* only one Synchronous event running at a time. Currently supported event operations are: start, stop, and getStatus.
|
||||
* Once an event is complete, it then notifies EventManager through a listener. The EventManager then takes the event
|
||||
* out of the pool.
|
||||
*
|
||||
* EventManager handles and maintains a pool of event threads. {@link Event} threads are created
|
||||
* upon user request. Thre are two types of events; Asynchronous and Synchronous. There can be
|
||||
* multiple Asynchronous events running at once but only one Synchronous event running at a time.
|
||||
* Currently supported event operations are: start, stop, and getStatus. Once an event is complete,
|
||||
* it then notifies EventManager through a listener. The EventManager then takes the event out of
|
||||
* the pool.
|
||||
*/
|
||||
public class EventManager implements ThreadCompleteListener {
|
||||
|
||||
public static final int MAX_RUNNING_EVENTS = 1000; // Just don't wanna have too many running events. :)
|
||||
public static final int MAX_RUNNING_EVENTS = 1000;
|
||||
// Just don't wanna have too many running events. :)
|
||||
public static final int MIN_ID = 1;
|
||||
public static final int MAX_ID = MAX_RUNNING_EVENTS;
|
||||
public static final int MAX_EVENT_TIME = 1800; // in seconds / 30 minutes.
|
||||
private int currentlyRunningSyncEvent = -1;
|
||||
private Random rand;
|
||||
private Map<Integer, Event> eventPool;
|
||||
|
||||
|
||||
private static final String DOES_NOT_EXIST = " does not exist.";
|
||||
|
||||
/**
|
||||
* EventManager constructor.
|
||||
*
|
||||
*/
|
||||
public EventManager() {
|
||||
rand = new Random(1);
|
||||
@ -65,14 +64,15 @@ public class EventManager implements ThreadCompleteListener {
|
||||
* @param eventTime Time an event should run for.
|
||||
* @return eventId
|
||||
* @throws MaxNumOfEventsAllowedException When too many events are running at a time.
|
||||
* @throws InvalidOperationException No new synchronous events can be created when one is already running.
|
||||
* @throws LongRunningEventException Long running events are not allowed in the app.
|
||||
* @throws InvalidOperationException No new synchronous events can be created when one is
|
||||
* already running.
|
||||
* @throws LongRunningEventException Long running events are not allowed in the app.
|
||||
*/
|
||||
public int create(int eventTime)
|
||||
throws MaxNumOfEventsAllowedException, InvalidOperationException, LongRunningEventException {
|
||||
if (currentlyRunningSyncEvent != -1) {
|
||||
throw new InvalidOperationException(
|
||||
"Event [" + currentlyRunningSyncEvent + "] is still running. Please wait until it finishes and try again.");
|
||||
throw new InvalidOperationException("Event [" + currentlyRunningSyncEvent + "] is still"
|
||||
+ " running. Please wait until it finishes and try again.");
|
||||
}
|
||||
|
||||
int eventId = createEvent(eventTime, true);
|
||||
@ -87,16 +87,18 @@ public class EventManager implements ThreadCompleteListener {
|
||||
* @param eventTime Time an event should run for.
|
||||
* @return eventId
|
||||
* @throws MaxNumOfEventsAllowedException When too many events are running at a time.
|
||||
* @throws LongRunningEventException Long running events are not allowed in the app.
|
||||
* @throws LongRunningEventException Long running events are not allowed in the app.
|
||||
*/
|
||||
public int createAsync(int eventTime) throws MaxNumOfEventsAllowedException, LongRunningEventException {
|
||||
public int createAsync(int eventTime) throws MaxNumOfEventsAllowedException,
|
||||
LongRunningEventException {
|
||||
return createEvent(eventTime, false);
|
||||
}
|
||||
|
||||
private int createEvent(int eventTime, boolean isSynchronous)
|
||||
throws MaxNumOfEventsAllowedException, LongRunningEventException {
|
||||
if (eventPool.size() == MAX_RUNNING_EVENTS) {
|
||||
throw new MaxNumOfEventsAllowedException("Too many events are running at the moment. Please try again later.");
|
||||
throw new MaxNumOfEventsAllowedException("Too many events are running at the moment."
|
||||
+ " Please try again later.");
|
||||
}
|
||||
|
||||
if (eventTime >= MAX_EVENT_TIME) {
|
||||
@ -185,7 +187,8 @@ public class EventManager implements ThreadCompleteListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pseudo-random number between min and max, inclusive. The difference between min and max can be at most
|
||||
* Returns a pseudo-random number between min and max, inclusive. The difference between min and
|
||||
* max can be at most
|
||||
* <code>Integer.MAX_VALUE - 1</code>.
|
||||
*/
|
||||
private int generateId() {
|
||||
|
Reference in New Issue
Block a user