public interface Service
Service
is the root consumption API that every Service
instance offers.
It offers the generic emit(EventContext)
method, which is also the basis of more specialized consumption API methods.
Service
interface also offers programmatic registration of handlers
to handle events.
Handlers
can be registered for the three phases BEFORE, ON and AFTER using events and entities, which should be handled.
Handler
are called one after the other and can abort the complete processing of the event at any time by throwing an exception.
If during the BEFORE phase the EventContext.setCompleted()
method is called, the event processing directly jumps to the AFTER phase.
If no Handler
completes the EventContext
during the BEFORE phase, or does not abort the event processing by throwing an exception, the ON phase is started.
Handler
should compute the output parameters based in the input parameters of the event.
Handler
are called one after the other. If a Handler
performs any action during the ON phase, it should call EventContext.setCompleted()
to indicate that the event was successfully processed.
As soon as the EventContext
is completed, the ON phase is finished and the event processing jumps to the AFTER phase.
In case a Handler
throws an exception the event processing is aborted.
If no Handler
completes the EventContext
during the ON phase, it is treated as an error and an exception is thrown.
Handler
are called one after the other. A Handler
in this phase can still abort the event processing by throwing an exception. No further Handler
are called in this case.
Alternatively it can also call ChangeSetContext.markForCancel()
, which cancels the active ChangeSetContext
and causes a rollback of transactions. However it does not abort the event processing itself.Modifier and Type | Method and Description |
---|---|
void |
after(EventPredicate matcher,
Handler handler)
Deprecated.
Use
after(String[], String[], int, Handler) instead. |
default void |
after(String[] events,
String[] entities,
Handler handler)
|
void |
after(String[] events,
String[] entities,
int order,
Handler handler)
|
default void |
after(String event,
String entity,
Handler handler)
|
default void |
after(String event,
String entity,
int order,
Handler handler)
|
void |
before(EventPredicate matcher,
Handler handler)
Deprecated.
Use
before(String[], String[], int, Handler) instead. |
default void |
before(String[] events,
String[] entities,
Handler handler)
|
void |
before(String[] events,
String[] entities,
int order,
Handler handler)
|
default void |
before(String event,
String entity,
Handler handler)
|
default void |
before(String event,
String entity,
int order,
Handler handler)
|
static Service |
create(String name)
Creates a new
Service |
void |
emit(EventContext context)
The generic consumption API to emit arbitrary events, represented by
EventContext objects. |
String |
getName()
Returns the name of the
Service . |
void |
on(EventPredicate matcher,
Handler handler)
Deprecated.
Use
on(String[], String[], int, Handler) instead. |
default void |
on(String[] events,
String[] entities,
Handler handler)
|
void |
on(String[] events,
String[] entities,
int order,
Handler handler)
|
default void |
on(String event,
String entity,
Handler handler)
|
default void |
on(String event,
String entity,
int order,
Handler handler)
|
static Service create(String name)
Service
name
- the name of the serviceService
@Deprecated void before(EventPredicate matcher, Handler handler)
before(String[], String[], int, Handler)
instead.matcher
- the EventPredicate
, defining for which events and entities the Handler
becomes active.handler
- the Handler
implementing the business-logic, which should become active during the BEFORE phase.void before(String[] events, String[] entities, int order, Handler handler)
events
- the events the custom handler is registered forentities
- the entities the custom handler is registered fororder
- the order of the handler. the lower the order the earlier the handler gets called. if two handlers have the same order they get ordered in their registration orderhandler
- the Handler
implementing the business-logic, which should become active during the BEFORE phase.default void before(String[] events, String[] entities, Handler handler)
events
- the events the custom handler is registered forentities
- the entities the custom handler is registered forhandler
- the Handler
implementing the business-logic, which should become active during the BEFORE phase.default void before(String event, String entity, int order, Handler handler)
event
- the event the custom handler is registered forentity
- the entity the custom handler is registered fororder
- the order of the handler. the lower the order the earlier the handler gets called. if two handlers have the same order they get ordered in their registration orderhandler
- the Handler
implementing the business-logic, which should become active during the BEFORE phase.default void before(String event, String entity, Handler handler)
event
- the event the custom handler is registered forentity
- the entity the custom handler is registered forhandler
- the Handler
implementing the business-logic, which should become active during the BEFORE phase.@Deprecated void on(EventPredicate matcher, Handler handler)
on(String[], String[], int, Handler)
instead.matcher
- the EventPredicate
, defining for which events and entities the Handler
becomes active.handler
- the Handler
implementing the business-logic, which should become active during the ON phase.void on(String[] events, String[] entities, int order, Handler handler)
events
- the events the custom handler is registered forentities
- the entities the custom handler is registered fororder
- the order of the handler. the lower the order the earlier the handler gets called. if two handlers have the same order they get ordered in their registration orderhandler
- the Handler
implementing the business-logic, which should become active during the ON phase.default void on(String[] events, String[] entities, Handler handler)
events
- the events the custom handler is registered forentities
- the entities the custom handler is registered forhandler
- the Handler
implementing the business-logic, which should become active during the ON phase.default void on(String event, String entity, int order, Handler handler)
event
- the event the custom handler is registered forentity
- the entity the custom handler is registered fororder
- the order of the handler. the lower the order the earlier the handler gets called. if two handlers have the same order they get ordered in their registration orderhandler
- the Handler
implementing the business-logic, which should become active during the ON phase.default void on(String event, String entity, Handler handler)
event
- the event the custom handler is registered forentity
- the entity the custom handler is registered forhandler
- the Handler
implementing the business-logic, which should become active during the ON phase.@Deprecated void after(EventPredicate matcher, Handler handler)
after(String[], String[], int, Handler)
instead.matcher
- the EventPredicate
, defining for which events and entities the Handler
becomes active.handler
- the Handler
implementing the business-logic, which should become active during the AFTER phase.void after(String[] events, String[] entities, int order, Handler handler)
events
- the events the custom handler is registered forentities
- the entities the custom handler is registered fororder
- the order of the handler. the lower the order the earlier the handler gets called. if two handlers have the same order they get ordered in their registration orderhandler
- the Handler
implementing the business-logic, which should become active during the AFTER phase.default void after(String[] events, String[] entities, Handler handler)
events
- the events the custom handler is registered forentities
- the entities the custom handler is registered forhandler
- the Handler
implementing the business-logic, which should become active during the AFTER phase.default void after(String event, String entity, int order, Handler handler)
event
- the event the custom handler is registered forentity
- the entity the custom handler is registered fororder
- the order of the handler. the lower the order the earlier the handler gets called. if two handlers have the same order they get ordered in their registration orderhandler
- the Handler
implementing the business-logic, which should become active during the AFTER phase.default void after(String event, String entity, Handler handler)
event
- the event the custom handler is registered forentity
- the entity the custom handler is registered forhandler
- the Handler
implementing the business-logic, which should become active during the AFTER phase.void emit(EventContext context)
EventContext
objects.
More specialized consumption APIs (for example CqnService
) are implemented as a wrapper around this method.
EventContext
will start the processing of the event and calls the registered Handler
instances.
If emit(EventContext)
is called outside of an active ChangeSetContext
, an internal ChangeSetContext
is opened and properly closed.
Handler
can therefore rely on an active ChangeSetContext
.
EventContext
passed to this method, should be propagated with the required input parameters of the event.
After the method finished, the respective output parameters can be read from the passed in EventContext
.context
- the EventContext
to be emittedCopyright © 2021. All rights reserved.