diff --git a/event-driven-architecture/pom.xml b/event-driven-architecture/pom.xml
index fdea3855f..0c72f2157 100644
--- a/event-driven-architecture/pom.xml
+++ b/event-driven-architecture/pom.xml
@@ -19,4 +19,28 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.15
+
+
+ validate
+
+ check
+
+ validate
+
+ checkstyle.xml
+ UTF-8
+ true
+ true
+
+
+
+
+
+
\ No newline at end of file
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/App.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/App.java
index e8b8d2d09..ab4b2e489 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/App.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/App.java
@@ -7,22 +7,21 @@ import com.iluwatar.eda.handler.UserCreatedEventHandler;
import com.iluwatar.eda.handler.UserUpdatedEventHandler;
/**
- * An event-driven architecture (EDA) is a framework that orchestrates behavior around the production,
- * detection and consumption of events as well as the responses they evoke.
- * An event is any identifiable occurrence that has significance for system hardware or software.
- *
- * The example below we uses an {@link EventDispatcher} to link/register {@link Event} objects to
- * their respective handlers Once an {@link Event} is dispatched,
- * it's respective handler is invoked and the {@link Event} is handled accordingly
+ * An event-driven architecture (EDA) is a framework that orchestrates behavior around the
+ * production, detection and consumption of events as well as the responses they evoke. An event is
+ * any identifiable occurrence that has significance for system hardware or software. The
+ * example below we uses an {@link EventDispatcher} to link/register {@link Event} objects to their
+ * respective handlers Once an {@link Event} is dispatched, it's respective handler is invoked and
+ * the {@link Event} is handled accordingly
*/
public class App {
- public static void main(String[] args) {
- EventDispatcher dispatcher = new EventDispatcher();
- dispatcher.registerChannel(UserCreatedEvent.class, new UserCreatedEventHandler());
- dispatcher.registerChannel(UserUpdatedEvent.class, new UserUpdatedEventHandler());
- dispatcher.dispatch(new UserCreatedEvent());
- dispatcher.dispatch(new UserUpdatedEvent());
- }
+ public static void main(String[] args) {
+ EventDispatcher dispatcher = new EventDispatcher();
+ dispatcher.registerChannel(UserCreatedEvent.class, new UserCreatedEventHandler());
+ dispatcher.registerChannel(UserUpdatedEvent.class, new UserUpdatedEventHandler());
+ dispatcher.dispatch(new UserCreatedEvent());
+ dispatcher.dispatch(new UserUpdatedEvent());
+ }
}
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/EventDispatcher.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/EventDispatcher.java
index f947773d0..3b44a414a 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/EventDispatcher.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/EventDispatcher.java
@@ -8,32 +8,36 @@ import java.util.HashMap;
import java.util.Map;
/**
- * The {@link Event Dispatcher} handles routing of {@link Event} messages to associated channels.
+ * The {@link Event Dispatcher} handles routing of {@link Event} messages
+ * to associated channels.
* A {@link HashMap} is used to store the association between events and their respective handlers.
+ *
*/
public class EventDispatcher implements DynamicRouter {
- private Map, Channel> handlers;
+ private Map, Channel> handlers;
- public EventDispatcher() {
- handlers = new HashMap, Channel>();
- }
+ public EventDispatcher() {
+ handlers = new HashMap<>();
+ }
- /**
- * Links an {@link Event} to a specific {@link Channel}
- * @param contentType The {@link Event} to be registered
- * @param channel The {@link Channel} that will be handling the {@link Event}
- */
- public void registerChannel(Class extends Event> contentType,
- Channel channel) {
- handlers.put(contentType, channel);
- }
+ /**
+ * Links an {@link Event} to a specific {@link Channel}
+ *
+ * @param contentType The {@link Event} to be registered
+ * @param channel The {@link Channel} that will be handling the {@link Event}
+ */
+ public void registerChannel(Class extends Event> contentType,
+ Channel> channel) {
+ handlers.put(contentType, channel);
+ }
- /**
- * Dispathes an {@link Event} depending on it's type.
- * @param content The {@link Event} to be dispatched
- */
- public void dispatch(Event content) {
- handlers.get(content.getClass()).dispatch(content);
- }
+ /**
+ * Dispatches an {@link Event} depending on it's type.
+ *
+ * @param content The {@link Event} to be dispatched
+ */
+ public void dispatch(Event content) {
+ handlers.get(content.getClass()).dispatch(content);
+ }
}
\ No newline at end of file
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/event/Event.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/event/Event.java
index 5f3db28e8..9a2518ebf 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/event/Event.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/event/Event.java
@@ -2,8 +2,25 @@ package com.iluwatar.eda.event;
import com.iluwatar.eda.framework.Message;
+/**
+ * The {@link Event} class serves as a base class for defining custom events happening with your
+ * system. In this example we have two types of events defined.
+ *
+ * - {@link UserCreatedEvent} - used when a user is created
+ * - {@link UserUpdatedEvent} - used when a user is updated
+ *
+ * Events can be distinguished using the {@link #getType() getType} method.
+ */
public class Event implements Message {
- public Class extends Message> getType() {
- return getClass();
- }
+
+ /**
+ * Returns the event type as a {@link Class} object
+ * In this example, this method is used by the {@link com.iluwatar.eda.EventDispatcher} to
+ * dispatch events depending on their type.
+ *
+ * @return the Event type as a {@link Class}.
+ */
+ public Class extends Message> getType() {
+ return getClass();
+ }
}
\ No newline at end of file
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserCreatedEvent.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserCreatedEvent.java
index 14d83a783..1a61dfa59 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserCreatedEvent.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserCreatedEvent.java
@@ -1,7 +1,8 @@
package com.iluwatar.eda.event;
/**
- * @author cfarrugia
+ * The {@link UserCreatedEvent} class should should be dispatched whenever a user has been created.
+ * This class can be extended to contain details about the user has been created.
*/
public class UserCreatedEvent extends Event {
}
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserUpdatedEvent.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserUpdatedEvent.java
index e0e3c3cd6..3b401ecd1 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserUpdatedEvent.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserUpdatedEvent.java
@@ -1,4 +1,8 @@
package com.iluwatar.eda.event;
+/**
+ * The {@link UserUpdatedEvent} class should should be dispatched whenever a user has been updated.
+ * This class can be extended to contain details about the user has been updated.
+ */
public class UserUpdatedEvent extends Event {
}
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Channel.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Channel.java
index a8dd97044..32eca09d4 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Channel.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Channel.java
@@ -1,9 +1,11 @@
package com.iluwatar.eda.framework;
+import com.iluwatar.eda.event.Event;
+
/**
- * Channels are delivery points for messages.
- * Every {@link Channel} is responsible for a single type of message
+ * Channels are delivery points for messages. Every {@link Channel} is responsible for a single type
+ * of message
*/
public interface Channel {
- void dispatch(E message);
+ void dispatch(E message);
}
\ No newline at end of file
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/DynamicRouter.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/DynamicRouter.java
index 751318ada..23fd6044f 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/DynamicRouter.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/DynamicRouter.java
@@ -2,10 +2,12 @@ package com.iluwatar.eda.framework;
/**
* A {@link DynamicRouter} is responsible for selecting the proper path of a {@link Message}
- * Messages can be associated to Channels through the registerChannel method and dispatched by calling
- * the dispatch method.
+ * Messages can be associated to Channels through the registerChannel method and dispatched by
+ * calling the dispatch method.
*/
public interface DynamicRouter {
- void registerChannel(Class extends E> contentType, Channel channel);
- void dispatch(E content);
+
+ void registerChannel(Class extends E> contentType, Channel> channel);
+
+ void dispatch(E content);
}
\ No newline at end of file
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Message.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Message.java
index 61880e9cd..2f8acb343 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Message.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Message.java
@@ -1,9 +1,9 @@
package com.iluwatar.eda.framework;
/**
- * A {@link Message} is an object with a specific type that is associated to a
- * specific {@link Channel}
+ * A {@link Message} is an object with a specific type that is associated
+ * to a specific {@link Channel}.
*/
public interface Message {
- Class extends Message> getType();
+ Class extends Message> getType();
}
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/handler/UserCreatedEventHandler.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/handler/UserCreatedEventHandler.java
index b2e831bf8..e406f7c51 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/handler/UserCreatedEventHandler.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/handler/UserCreatedEventHandler.java
@@ -4,11 +4,10 @@ import com.iluwatar.eda.event.UserCreatedEvent;
import com.iluwatar.eda.framework.Channel;
/**
- * Handles the {@link UserCreatedEvent} message
+ * Handles the {@link UserCreatedEvent} message.
*/
public class UserCreatedEventHandler implements Channel {
-
- public void dispatch(UserCreatedEvent message) {
- System.out.println("User Created!");
- }
+ public void dispatch(UserCreatedEvent message) {
+ System.out.println("User Created!");
+ }
}
diff --git a/event-driven-architecture/src/main/java/com/iluwatar/eda/handler/UserUpdatedEventHandler.java b/event-driven-architecture/src/main/java/com/iluwatar/eda/handler/UserUpdatedEventHandler.java
index c7762d247..d59954806 100644
--- a/event-driven-architecture/src/main/java/com/iluwatar/eda/handler/UserUpdatedEventHandler.java
+++ b/event-driven-architecture/src/main/java/com/iluwatar/eda/handler/UserUpdatedEventHandler.java
@@ -4,11 +4,10 @@ import com.iluwatar.eda.event.UserUpdatedEvent;
import com.iluwatar.eda.framework.Channel;
/**
- * Handles the {@link UserUpdatedEvent} message
+ * Handles the {@link UserUpdatedEvent} message.
*/
public class UserUpdatedEventHandler implements Channel {
-
- public void dispatch(UserUpdatedEvent message) {
- System.out.println("User Updated!");
- }
+ public void dispatch(UserUpdatedEvent message) {
+ System.out.println("User Updated!");
+ }
}
diff --git a/pom.xml b/pom.xml
index e0e6a0cc6..9e4c39bf9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -244,8 +244,8 @@
checkstyle.xml
UTF-8
- false
- false
+ true
+ true