-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added class diagram - added more comments
- Loading branch information
chris
committed
Nov 23, 2015
1 parent
b4aeca3
commit 321e9d4
Showing
22 changed files
with
123 additions
and
158 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
event-driven-architecture/src/main/java/com/iluwatar/eda/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.iluwatar.eda; | ||
|
||
import com.iluwatar.eda.event.Event; | ||
import com.iluwatar.eda.event.UserCreatedEvent; | ||
import com.iluwatar.eda.event.UserUpdatedEvent; | ||
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. | ||
* <p/> | ||
* 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()); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
event-driven-architecture/src/main/java/com/iluwatar/eda/EventDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.iluwatar.eda; | ||
|
||
import com.iluwatar.eda.event.Event; | ||
import com.iluwatar.eda.framework.Channel; | ||
import com.iluwatar.eda.framework.DynamicRouter; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* 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<Event> { | ||
|
||
private Map<Class<? extends Event>, Channel> handlers; | ||
|
||
public EventDispatcher() { | ||
handlers = new HashMap<Class<? extends Event>, 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); | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
event-driven-architecture/src/main/java/com/iluwatar/eda/advanced/App.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
event-driven-architecture/src/main/java/com/iluwatar/eda/advanced/EventDispatcher.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...-driven-architecture/src/main/java/com/iluwatar/eda/advanced/events/UserCreatedEvent.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
...-driven-architecture/src/main/java/com/iluwatar/eda/advanced/events/UserUpdatedEvent.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
event-driven-architecture/src/main/java/com/iluwatar/eda/advanced/framework/Channel.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
...-driven-architecture/src/main/java/com/iluwatar/eda/advanced/framework/DynamicRouter.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
event-driven-architecture/src/main/java/com/iluwatar/eda/advanced/framework/Message.java
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...m/iluwatar/eda/advanced/events/Event.java → ...in/java/com/iluwatar/eda/event/Event.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserCreatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.iluwatar.eda.event; | ||
|
||
/** | ||
* @author cfarrugia | ||
*/ | ||
public class UserCreatedEvent extends Event { | ||
} |
4 changes: 4 additions & 0 deletions
4
event-driven-architecture/src/main/java/com/iluwatar/eda/event/UserUpdatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.iluwatar.eda.event; | ||
|
||
public class UserUpdatedEvent extends Event { | ||
} |
9 changes: 9 additions & 0 deletions
9
event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Channel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.iluwatar.eda.framework; | ||
|
||
/** | ||
* Channels are delivery points for messages. | ||
* Every {@link Channel} is responsible for a single type of message | ||
*/ | ||
public interface Channel<E extends Message> { | ||
void dispatch(E message); | ||
} |
11 changes: 11 additions & 0 deletions
11
event-driven-architecture/src/main/java/com/iluwatar/eda/framework/DynamicRouter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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. | ||
*/ | ||
public interface DynamicRouter<E extends Message> { | ||
void registerChannel(Class<? extends E> contentType, Channel channel); | ||
void dispatch(E content); | ||
} |
9 changes: 9 additions & 0 deletions
9
event-driven-architecture/src/main/java/com/iluwatar/eda/framework/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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} | ||
*/ | ||
public interface Message { | ||
Class<? extends Message> getType(); | ||
} |
8 changes: 4 additions & 4 deletions
8
...nced/handler/UserCreatedEventHandler.java → .../eda/handler/UserCreatedEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...nced/handler/UserUpdatedEventHandler.java → .../eda/handler/UserUpdatedEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
event-driven-architecture/src/main/java/com/iluwatar/eda/simple/App.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
event-driven-architecture/src/main/java/com/iluwatar/eda/simple/Event.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
event-driven-architecture/src/main/java/com/iluwatar/eda/simple/EventHandler.java
This file was deleted.
Oops, something went wrong.