mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 05:25:45 +00:00
#113 Event Driven Architecture
- initial commit includes a simple and advanced example of Event-driven architecture
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
package com.iluwatar.eda.advanced;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EventDispatcher implements DynamicRouter<Event> {
|
||||
private Map<Class<? extends Event>, Handler> handlers;
|
||||
|
||||
public EventDispatcher() {
|
||||
handlers = new HashMap<Class<? extends Event>, Handler>();
|
||||
}
|
||||
|
||||
public void registerChannel(Class<? extends Event> contentType,
|
||||
Channel<? extends Event> channel) {
|
||||
handlers.put(contentType, (Handler)channel);
|
||||
}
|
||||
|
||||
public void dispatch(Event content) {
|
||||
handlers.get(content.getClass()).dispatch(content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user