com.neeve.aep
Class AepEventDispatcher

java.lang.Object
  extended by com.neeve.root.RootObject
      extended by com.neeve.aep.AepEventDispatcher
All Implemented Interfaces:
IEventHandler

public final class AepEventDispatcher
extends RootObject
implements IEventHandler


Nested Class Summary
static class AepEventDispatcher.DefaultHandlerDispatchPolicy
          Enumerates the various default handler dispatch policies
 
Method Summary
 void appendEventHandlerDeclarations(Class<?> eventType, String prefix, StringBuilder builder)
          Appends the list of a event handlers for the given type to a StringBuilder.
static AepEventDispatcher create(Set<Object> eventHandlerContainers, IEventHandler defaultEventHandler)
          Create a new event dispatcher This method invokes create(eventHandlerContainers, defaultEventHandler, null)
static AepEventDispatcher create(Set<Object> eventHandlerContainers, IEventHandler defaultEventHandler, IAepApplicationStateFactory stateFactory)
          Create a new event dispatcher
 void dispatchToEventHandlers(Object event)
          Dispatch an event to its handlers.
 AepEventDispatcher.DefaultHandlerDispatchPolicy getDefaultHandlerDispatchPolicy()
          Get the default handler dispatch policy
 Set<Object> getEventHandlerContainers()
          Get the event handler containers
 Set<Class<?>> getHandledEventClasses()
          Get the set of handled events
 void getHandlerMethodsFor(Class<?> eventType, List<Method> results)
          Adds the list of handler methods for a given type to the provide list.
 void onEvent(Event event)
          Implementation of IEventHandler.onEvent(com.neeve.event.Event)
 void setDefaultHandlerDispatchPolicy(AepEventDispatcher.DefaultHandlerDispatchPolicy policy)
          Set the default handler dispatch policy
 
Methods inherited from class com.neeve.root.RootObject
getChecked, getThreaded, getTracer, setChecked, setTracer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static final AepEventDispatcher create(Set<Object> eventHandlerContainers,
                                              IEventHandler defaultEventHandler,
                                              IAepApplicationStateFactory stateFactory)
Create a new event dispatcher

Parameters:
eventHandlerContainers - The objects that contain the event handlers (methods annotated with EventHandler)
defaultEventHandler - The default event handler
stateFactory - A state factory for the dispatcher to use to determine the class of the root state object (repository) to discover event handlers with repository argument. A null value in this parameter will result in the dispatcher not discovering event handlers with a repository argument

create

public static final AepEventDispatcher create(Set<Object> eventHandlerContainers,
                                              IEventHandler defaultEventHandler)
Create a new event dispatcher

This method invokes create(eventHandlerContainers, defaultEventHandler, null)


getEventHandlerContainers

public final Set<Object> getEventHandlerContainers()
Get the event handler containers


getHandledEventClasses

public final Set<Class<?>> getHandledEventClasses()
Get the set of handled events


getHandlerMethodsFor

public final void getHandlerMethodsFor(Class<?> eventType,
                                       List<Method> results)
Adds the list of handler methods for a given type to the provide list.

Parameters:
eventType - The type for which to look up event handlers.
results - The target list to which to add the event handler methods.

appendEventHandlerDeclarations

public final void appendEventHandlerDeclarations(Class<?> eventType,
                                                 String prefix,
                                                 StringBuilder builder)
Appends the list of a event handlers for the given type to a StringBuilder.

Parameters:
eventType - The type for which to look up event handlers.
prefix - A prefix to append to each event handler line listed.
builder - The StringBuilder to which to append.

setDefaultHandlerDispatchPolicy

public final void setDefaultHandlerDispatchPolicy(AepEventDispatcher.DefaultHandlerDispatchPolicy policy)
Set the default handler dispatch policy


getDefaultHandlerDispatchPolicy

public final AepEventDispatcher.DefaultHandlerDispatchPolicy getDefaultHandlerDispatchPolicy()
Get the default handler dispatch policy


dispatchToEventHandlers

public final void dispatchToEventHandlers(Object event)
Dispatch an event to its handlers.

Parameters:
event - The event to dispatch. The event's type (class) determines the event handler to which it will be dispatched.

This method dispatches an event to its registered handlers i.e. methods annotated using the EventHandler annotation. The handlers to which the event is dispatched is identified by the event's type (class). Note: This method does not dispatch to event handlers that contain the application repository as the second argument in its method signature


onEvent

public final void onEvent(Event event)
Implementation of IEventHandler.onEvent(com.neeve.event.Event)

Specified by:
onEvent in interface IEventHandler
Parameters:
event - The event to be handled.


Copyright © 2016 Neeve Research, LLC. All Rights Reserved.