public class EventHandlingConfiguration extends Object implements ModuleConfiguration
Modifier and Type | Class and Description |
---|---|
static interface |
EventHandlingConfiguration.EventProcessorBuilder
Interface describing a Builder function for Event Processors.
|
Constructor and Description |
---|
EventHandlingConfiguration()
Creates a default configuration for an Event Handling module that assigns Event Handlers to Subscribing Event
Processors based on the package they're in.
|
Modifier and Type | Method and Description |
---|---|
EventHandlingConfiguration |
assignHandlersMatching(String name,
int priority,
Predicate<Object> criteria)
Configures a rule to assign Event Handler beans that match the given
criteria to the Event Processor
with given name , with given priority . |
EventHandlingConfiguration |
assignHandlersMatching(String name,
Predicate<Object> criteria)
Configures a rule to assign Event Handler beans that match the given
criteria to the Event Processor
with given name , with neutral priority (value 0). |
EventHandlingConfiguration |
byDefaultAssignTo(Function<Object,String> assignmentFunction)
Registers a function that defines the Event Processor name to assign Event Handler beans to when no other rule
matches.
|
EventHandlingConfiguration |
byDefaultAssignTo(String name)
Registers the Event Processor name to assign Event Handler beans to when no other, more explicit, rule matches.
|
<T extends EventProcessor> |
getProcessor(String name)
Returns the Event Processor with the given
name , if present. |
List<EventProcessor> |
getProcessors()
Returns a list of Event Processors that have been initialized.
|
void |
initialize(Configuration config)
Initialize the module configuration using the given global
config |
List<MessageHandlerInterceptor<? super EventMessage<?>>> |
interceptorsFor(Configuration configuration,
String processorName)
Returns the list of Message Handler Interceptors registered for the given
processorName . |
EventHandlingConfiguration |
registerEventHandler(Function<Configuration,Object> eventHandlerBuilder)
Register an Event Handler Bean with this configuration.
|
EventHandlingConfiguration |
registerEventProcessor(String name,
EventHandlingConfiguration.EventProcessorBuilder eventProcessorBuilder)
Defines the Event Processor builder for an Event Processor with the given
name . |
EventHandlingConfiguration |
registerEventProcessorFactory(EventHandlingConfiguration.EventProcessorBuilder eventProcessorBuilder)
Allows for more fine-grained definition of the Event Processor to use for each group of Event Listeners.
|
EventHandlingConfiguration |
registerHandlerInterceptor(BiFunction<Configuration,String,MessageHandlerInterceptor<? super EventMessage<?>>> interceptorBuilder)
Register the given
interceptorBuilder to build an Message Handling Interceptor for Event Processors
created in this configuration. |
EventHandlingConfiguration |
registerHandlerInterceptor(String processorName,
Function<Configuration,MessageHandlerInterceptor<? super EventMessage<?>>> interceptorBuilder)
Register the given
interceptorBuilder to build an Message Handling Interceptor for the Event Processor
with given processorName . |
EventHandlingConfiguration |
registerSubscribingEventProcessor(String name)
Register a subscribing processor with given
name that subscribes to the Event Bus. |
EventHandlingConfiguration |
registerSubscribingEventProcessor(String name,
Function<Configuration,SubscribableMessageSource<? extends EventMessage<?>>> messageSource)
Register a subscribing processor with given
name that subscribes to the given messageSource . |
EventHandlingConfiguration |
registerTrackingProcessor(String name)
Register a TrackingProcessor using default configuration for the given
name . |
EventHandlingConfiguration |
registerTrackingProcessor(String name,
Function<Configuration,StreamableMessageSource<TrackedEventMessage<?>>> source)
Registers a TrackingProcessor using the given
source to read messages from. |
void |
shutdown()
Invoked prior to shutdown of the application.
|
void |
start()
Invoked when the Configuration is started.
|
EventHandlingConfiguration |
usingTrackingProcessors()
Configure the use of Tracking Event Processors, instead of the default Subscribing ones.
|
public EventHandlingConfiguration()
At a minimum, the Event Handler beans need to be registered before this component is useful.
public List<MessageHandlerInterceptor<? super EventMessage<?>>> interceptorsFor(Configuration configuration, String processorName)
processorName
.configuration
- The main configurationprocessorName
- The name of the processor to retrieve interceptors forregisterHandlerInterceptor(BiFunction)
,
registerHandlerInterceptor(String, Function)
public EventHandlingConfiguration usingTrackingProcessors()
The processor will use the TokenStore
implementation provided in the global Configuration, and will
default to an InMemoryTokenStore
when no Token Store was defined. Note that it is not recommended to use
the in-memory TokenStore in a production environment.
public EventHandlingConfiguration registerTrackingProcessor(String name)
name
. Unlike
usingTrackingProcessors()
, this method will not default all processors to tracking, but instead only
use tracking for event handler that have been assigned to the processor with given name
.
Events will be read from the EventBus (or EventStore) registered with the main configuration
name
- The name of the processorpublic EventHandlingConfiguration registerTrackingProcessor(String name, Function<Configuration,StreamableMessageSource<TrackedEventMessage<?>>> source)
source
to read messages from.name
- The name of the TrackingProcessorsource
- The source of messages for this processorpublic EventHandlingConfiguration registerEventProcessorFactory(EventHandlingConfiguration.EventProcessorBuilder eventProcessorBuilder)
Note that the processor must be initialized, but shouldn't be started yet. The processor's
EventProcessor.start()
method is invoked when the global configuration is started.
eventProcessorBuilder
- The builder function for the Event Processorpublic EventHandlingConfiguration registerEventProcessor(String name, EventHandlingConfiguration.EventProcessorBuilder eventProcessorBuilder)
name
. Event Processors
registered using this method have priority over those defined in
registerEventProcessorFactory(EventProcessorBuilder)
.
The given builder is expected to create a fully initialized Event Processor implementation based on the name and list of event handler beans. The builder also received the global configuration instance, from which it can retrieve components.
Note that the processor must be initialized, but shouldn't be started yet. The processor's
EventProcessor.start()
method is invoked when the global configuration is started.
name
- The name of the Event Processor for which to use this buildereventProcessorBuilder
- The builder function for the Event Processorpublic EventHandlingConfiguration byDefaultAssignTo(String name)
name
- The Event Processor name to assign Event Handlers to, by default.public EventHandlingConfiguration registerHandlerInterceptor(String processorName, Function<Configuration,MessageHandlerInterceptor<? super EventMessage<?>>> interceptorBuilder)
interceptorBuilder
to build an Message Handling Interceptor for the Event Processor
with given processorName
.
The interceptorBuilder
may return null
, in which case the return value is ignored.
Note that a CorrelationDataInterceptor is registered by default. To change correlation data attached to messages,
see Configurer.configureCorrelationDataProviders(Function)
.
processorName
- The name of the processor to register the interceptor oninterceptorBuilder
- The function providing the interceptor to register, or null
public EventHandlingConfiguration registerHandlerInterceptor(BiFunction<Configuration,String,MessageHandlerInterceptor<? super EventMessage<?>>> interceptorBuilder)
interceptorBuilder
to build an Message Handling Interceptor for Event Processors
created in this configuration.
The interceptorBuilder
is invoked once for each processor created, and may return null
, in which
case the return value is ignored.
Note that a CorrelationDataInterceptor is registered by default. To change correlation data attached to messages,
see Configurer.configureCorrelationDataProviders(Function)
.
interceptorBuilder
- The builder function that provides an interceptor for each available processorpublic EventHandlingConfiguration byDefaultAssignTo(Function<Object,String> assignmentFunction)
assignmentFunction
- The function that returns a Processor Name for each Event Handler beanpublic EventHandlingConfiguration assignHandlersMatching(String name, Predicate<Object> criteria)
criteria
to the Event Processor
with given name
, with neutral priority (value 0).
Note that, when beans match multiple criteria for different processors with equal priority, the outcome is undefined.
name
- The name of the Event Processor to assign matching Event Handlers tocriteria
- The criteria for Event Handler to matchpublic EventHandlingConfiguration assignHandlersMatching(String name, int priority, Predicate<Object> criteria)
criteria
to the Event Processor
with given name
, with given priority
. Rules with higher value of priority
take precedence
over those with a lower value.
Note that, when beans match multiple criteria for different processors with equal priority, the outcome is undefined.
name
- The name of the Event Processor to assign matching Event Handlers topriority
- The priority for this rule.criteria
- The criteria for Event Handler to matchpublic EventHandlingConfiguration registerEventHandler(Function<Configuration,Object> eventHandlerBuilder)
eventHandlerBuilder
- The builder function for the Event Handler beanpublic void initialize(Configuration config)
ModuleConfiguration
config
initialize
in interface ModuleConfiguration
config
- the global configuration, providing access to generic componentspublic void start()
ModuleConfiguration
start
in interface ModuleConfiguration
Configuration.start()
public void shutdown()
ModuleConfiguration
shutdown
in interface ModuleConfiguration
Configuration.shutdown()
public EventHandlingConfiguration registerSubscribingEventProcessor(String name)
name
that subscribes to the Event Bus.name
- The name of the Event Processorpublic EventHandlingConfiguration registerSubscribingEventProcessor(String name, Function<Configuration,SubscribableMessageSource<? extends EventMessage<?>>> messageSource)
name
that subscribes to the given messageSource
.
This allows the use of standard Subscribing Processors that listen to another source than the Event Bus.name
- The name of the Event ProcessormessageSource
- The source the processor should read frompublic List<EventProcessor> getProcessors()
initialized
yet.public <T extends EventProcessor> Optional<T> getProcessor(String name)
name
, if present. This method also returns an unresolved
optional if the Processor was configured, but it hasn't been assigned any Event Handlers.name
- The name of the processor to returnCopyright © 2010–2017. All rights reserved.