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:
Anurag Agarwal
2019-11-10 23:07:10 +05:30
committed by Ilkka Seppälä
parent 7c888e8886
commit 5ae2ce6e2e
38 changed files with 208 additions and 229 deletions

View File

@@ -23,38 +23,38 @@
package com.iluwatar.event.asynchronous;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Scanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This application demonstrates the <b>Event-based Asynchronous</b> pattern. Essentially, users (of
* the pattern) may choose to run events in an Asynchronous or Synchronous mode. There can be
* multiple Asynchronous events running at once but only one Synchronous event can run at a time.
* Asynchronous events are synonymous to multi-threads. The key point here is that the threads run
* in the background and the user is free to carry on with other processes. Once an event is
* complete, the appropriate listener/callback method will be called. The listener then proceeds to
* carry out further processing depending on the needs of the user.
*
* This application demonstrates the <b>Event-based Asynchronous</b> pattern. Essentially, users (of the pattern) may
* choose to run events in an Asynchronous or Synchronous mode. There can be multiple Asynchronous events running at
* once but only one Synchronous event can run at a time. Asynchronous events are synonymous to multi-threads. The key
* point here is that the threads run in the background and the user is free to carry on with other processes. Once an
* event is complete, the appropriate listener/callback method will be called. The listener then proceeds to carry out
* further processing depending on the needs of the user.
* <p>The {@link EventManager} manages the events/threads that the user creates. Currently, the
* supported event operations are: <code>start</code>, <code>stop</code>, <code>getStatus</code>.
* For Synchronous events, the user is unable to start another (Synchronous) event if one is already
* running at the time. The running event would have to either be stopped or completed before a new
* event can be started.
*
* The {@link EventManager} manages the events/threads that the user creates. Currently, the supported event operations
* are: <code>start</code>, <code>stop</code>, <code>getStatus</code>. For Synchronous events, the user is unable to
* start another (Synchronous) event if one is already running at the time. The running event would have to either be
* stopped or completed before a new event can be started.
*
* The Event-based Asynchronous Pattern makes available the advantages of multithreaded applications while hiding many
* of the complex issues inherent in multithreaded design. Using a class that supports this pattern can allow you to:-
* (1) Perform time-consuming tasks, such as downloads and database operations, "in the background," without
* interrupting your application. (2) Execute multiple operations simultaneously, receiving notifications when each
* completes. (3) Wait for resources to become available without stopping ("hanging") your application. (4) Communicate
* with pending asynchronous operations using the familiar events-and-delegates model.
* <p>The Event-based Asynchronous Pattern makes available the advantages of multithreaded
* applications while hiding many of the complex issues inherent in multithreaded design. Using a
* class that supports this pattern can allow you to:- (1) Perform time-consuming tasks, such as
* downloads and database operations, "in the background," without interrupting your application.
* (2) Execute multiple operations simultaneously, receiving notifications when each completes. (3)
* Wait for resources to become available without stopping ("hanging") your application. (4)
* Communicate with pending asynchronous operations using the familiar events-and-delegates model.
*
* @see EventManager
* @see Event
*
*/
public class App {
@@ -67,8 +67,7 @@ public class App {
/**
* Program entry point.
*
* @param args
* command line args
* @param args command line args
*/
public static void main(String[] args) {
App app = new App();
@@ -78,8 +77,9 @@ public class App {
}
/**
* App can run in interactive mode or not. Interactive mode == Allow user interaction with command line.
* Non-interactive is a quick sequential run through the available {@link EventManager} operations.
* App can run in interactive mode or not. Interactive mode == Allow user interaction with command
* line. Non-interactive is a quick sequential run through the available {@link EventManager}
* operations.
*/
public void setUp() {
Properties prop = new Properties();
@@ -118,24 +118,24 @@ public class App {
try {
// Create an Asynchronous event.
int aEventId = eventManager.createAsync(60);
LOGGER.info("Async Event [{}] has been created.", aEventId);
eventManager.start(aEventId);
LOGGER.info("Async Event [{}] has been started.", aEventId);
int asyncEventId = eventManager.createAsync(60);
LOGGER.info("Async Event [{}] has been created.", asyncEventId);
eventManager.start(asyncEventId);
LOGGER.info("Async Event [{}] has been started.", asyncEventId);
// Create a Synchronous event.
int sEventId = eventManager.create(60);
LOGGER.info("Sync Event [{}] has been created.", sEventId);
eventManager.start(sEventId);
LOGGER.info("Sync Event [{}] has been started.", sEventId);
int syncEventId = eventManager.create(60);
LOGGER.info("Sync Event [{}] has been created.", syncEventId);
eventManager.start(syncEventId);
LOGGER.info("Sync Event [{}] has been started.", syncEventId);
eventManager.status(aEventId);
eventManager.status(sEventId);
eventManager.status(asyncEventId);
eventManager.status(syncEventId);
eventManager.cancel(aEventId);
LOGGER.info("Async Event [{}] has been stopped.", aEventId);
eventManager.cancel(sEventId);
LOGGER.info("Sync Event [{}] has been stopped.", sEventId);
eventManager.cancel(asyncEventId);
LOGGER.info("Async Event [{}] has been stopped.", asyncEventId);
eventManager.cancel(syncEventId);
LOGGER.info("Sync Event [{}] has been stopped.", syncEventId);
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException
| InvalidOperationException e) {
@@ -211,7 +211,8 @@ public class App {
int eventId = eventManager.createAsync(eventTime);
eventManager.start(eventId);
LOGGER.info("Egg [{}] is being boiled.", eventId);
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
} catch (MaxNumOfEventsAllowedException | LongRunningEventException
| EventDoesNotExistException e) {
LOGGER.error(e.getMessage());
}
} else if (eventType.equalsIgnoreCase("S")) {
@@ -219,8 +220,8 @@ public class App {
int eventId = eventManager.create(eventTime);
eventManager.start(eventId);
LOGGER.info("Egg [{}] is being boiled.", eventId);
} catch (MaxNumOfEventsAllowedException | InvalidOperationException | LongRunningEventException
| EventDoesNotExistException e) {
} catch (MaxNumOfEventsAllowedException | InvalidOperationException
| LongRunningEventException | EventDoesNotExistException e) {
LOGGER.error(e.getMessage());
}
} else {