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 creates a
SubscribingEventProcessor
instance for all Event Handlers that have the same Processing Group name. |
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, more
explicit, rule matches and no
ProcessingGroup annotation is found. |
EventHandlingConfiguration |
byDefaultAssignTo(String name)
Registers the Event Processor name to assign Event Handler beans to when no other, more explicit, rule matches
and no
ProcessingGroup annotation is found. |
EventHandlingConfiguration |
configureMessageMonitor(String name,
Function<Configuration,MessageMonitor<Message<?>>> messageMonitorBuilder)
Configures the builder function to create the Message Monitor for the
EventProcessor of the given name. |
EventHandlingConfiguration |
configureMessageMonitor(String name,
MessageMonitorFactory messageMonitorFactory)
Configures the factory to create the Message Monitor for the
EventProcessor of the given name. |
<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 |
registerTokenStore(String name,
Function<Configuration,TokenStore> tokenStore)
Register the TokenStore to use for a processor of given
name . |
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. |
EventHandlingConfiguration |
registerTrackingProcessor(String name,
Function<Configuration,StreamableMessageSource<TrackedEventMessage<?>>> source,
Function<Configuration,TrackingEventProcessorConfiguration> processorConfiguration,
Function<Configuration,SequencingPolicy<? super EventMessage<?>>> sequencingPolicy)
Registers a TrackingProcessor with the given
name , reading from the given source and using the
given processorConfiguration . |
EventHandlingConfiguration |
registerTrackingProcessor(String name,
Function<Configuration,TrackingEventProcessorConfiguration> processorConfiguration,
Function<Configuration,SequencingPolicy<? super EventMessage<?>>> sequencingPolicy)
Registers a TrackingProcessor with the given
name , reading from the Event Bus (or Store) from the main
configuration and using the given processorConfiguration . |
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.
|
EventHandlingConfiguration |
usingTrackingProcessors(Function<Configuration,TrackingEventProcessorConfiguration> config,
Function<Configuration,SequencingPolicy<? super EventMessage<?>>> sequencingPolicy)
Configure the use of Tracking Event Processors, instead of the default Subscribing ones.
|
public EventHandlingConfiguration()
SubscribingEventProcessor
instance for all Event Handlers that have the same Processing Group name. The Processing Group name is determined
by inspecting the ProcessingGroup
annotation; if no annotation is present, the package name is used as
the Processing Group name. This default behavior can be overridden in the instance returned.
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.
The processors will use the a TrackingEventProcessorConfiguration
registered with the configuration, or
otherwise to a single threaded configuration (which means the processor will run in a single Thread and a batch
size of 1).
public EventHandlingConfiguration usingTrackingProcessors(Function<Configuration,TrackingEventProcessorConfiguration> config, Function<Configuration,SequencingPolicy<? super EventMessage<?>>> sequencingPolicy)
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.
config
- The configuration for the processors to usesequencingPolicy
- The policy for processing events sequentiallypublic 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 registerTrackingProcessor(String name, Function<Configuration,TrackingEventProcessorConfiguration> processorConfiguration, Function<Configuration,SequencingPolicy<? super EventMessage<?>>> sequencingPolicy)
name
, reading from the Event Bus (or Store) from the main
configuration and using the given processorConfiguration
. The given sequencingPolicy
defines
the policy for events that need to be executed sequentially.name
- The name of the Tracking ProcessorprocessorConfiguration
- The configuration for the processorsequencingPolicy
- The sequencing policy to apply when processing events in parallelpublic EventHandlingConfiguration registerTrackingProcessor(String name, Function<Configuration,StreamableMessageSource<TrackedEventMessage<?>>> source, Function<Configuration,TrackingEventProcessorConfiguration> processorConfiguration, Function<Configuration,SequencingPolicy<? super EventMessage<?>>> sequencingPolicy)
name
, reading from the given source
and using the
given processorConfiguration
. The given sequencingPolicy
defines the policy for events that need
to be executed sequentially.name
- The name of the Tracking Processorsource
- The source to read Events fromprocessorConfiguration
- The configuration for the processorsequencingPolicy
- The sequencing policy to apply when processing events in parallelpublic 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 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(String name)
ProcessingGroup
annotation is found.name
- The Event Processor name to assign Event Handlers topublic EventHandlingConfiguration byDefaultAssignTo(Function<Object,String> assignmentFunction)
ProcessingGroup
annotation is found.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 rulecriteria
- 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 EventHandlingConfiguration registerTokenStore(String name, Function<Configuration,TokenStore> tokenStore)
name
.
If no explicit TokenStore implementation is available for a Processor, it is taken from the main Configuration.
Note that this configuration is ignored if the processor with given name isn't a Tracking Processor.
name
- The name of the processor to configure the token store fortokenStore
- The function providing the TokenStore based on a given Configurationpublic 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 returnpublic EventHandlingConfiguration configureMessageMonitor(String name, Function<Configuration,MessageMonitor<Message<?>>> messageMonitorBuilder)
EventProcessor
of the given name.
This overrides any Message Monitor configured through Configurer
.name
- The name of the event processormessageMonitorBuilder
- The builder function to usepublic EventHandlingConfiguration configureMessageMonitor(String name, MessageMonitorFactory messageMonitorFactory)
EventProcessor
of the given name. This
overrides any Message Monitor configured through Configurer
.name
- The name of the event processormessageMonitorFactory
- The factory to useCopyright © 2010–2017. All rights reserved.