#113 Event Driven Architecture

Adds more Javadoc and fixes checkstyle issues.
This commit is contained in:
cfarrugia
2015-11-28 15:03:22 +01:00
parent b8b94b697a
commit e1c0731f7e
9 changed files with 90 additions and 40 deletions
@@ -5,23 +5,37 @@ import com.iluwatar.eda.event.UserCreatedEvent;
import com.iluwatar.eda.event.UserUpdatedEvent;
import com.iluwatar.eda.handler.UserCreatedEventHandler;
import com.iluwatar.eda.handler.UserUpdatedEventHandler;
import com.iluwatar.eda.model.User;
/**
* 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
* example below 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 {
/**
* Once the {@link EventDispatcher} is initialised, channels related to specific events have to be
* made known to the dispatcher by registering them. In this case the {@link UserCreatedEvent} is
* bound to the UserCreatedEventHandler, whilst the {@link UserUpdatedEvent} is bound to the
* {@link UserUpdatedEventHandler}. The dispatcher can now be called to dispatch specific events.
* When a user is saved, the {@link UserCreatedEvent} can be dispatched.
* On the other hand, when a user is updated, {@link UserUpdatedEvent} can be dispatched.
*
*/
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());
User user = new User("iluwatar");
dispatcher.dispatch(new UserCreatedEvent(user));
dispatcher.dispatch(new UserUpdatedEvent(user));
}
}