public interface EventRouter
processing commands.
Event routing can be done in two ways: already coded events can be routed via one of the
routeEvent(..) methods. Alternatively the event can be encoded into the
event log buffer directly as follows:
try (RoutingContext context = routingEvent()) {
int length = context.buffer().putStringAscii(0, "Hello world");
context.route(length);
}
Note that RoutingContext implements AutoCloseable and if event routing is performed inside a
try-resource block as in the example above then routing will be aborted automatically
if route(..) is not called for instance due to an exception.| Modifier and Type | Interface and Description |
|---|---|
static interface |
EventRouter.Default
Provides default methods for
EventRouter. |
static interface |
EventRouter.RoutingContext
Context object returned by
routingEvent() allowing for zero copy encoding of events directly into the
event log buffer. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isSkipped()
If true the current command was skipped without routing any events.
|
short |
nextEventIndex()
Returns the zero based index of the next event to be routed.
|
void |
routeEvent(DirectBuffer buffer,
int offset,
int length)
Routes an
APPLICATION event already encoded in the given buffer. |
void |
routeEvent(int type,
DirectBuffer buffer,
int offset,
int length)
Routes an already encoded event of the specified event
type. |
void |
routeEventWithoutPayload(int type)
Routes an event of the specified event
type that carries no payload data. |
EventRouter.RoutingContext |
routingEvent()
Starts routing of an
APPLICATION event and returns the routing context with the
buffer for event encoding. |
EventRouter.RoutingContext |
routingEvent(int type)
Starts routing of an event of the given
type returns the routing context with the buffer for event
encoding. |
boolean |
skipCommand()
Skip the current command if possible.
|
EventRouter.RoutingContext routingEvent()
APPLICATION event and returns the routing context with the
buffer for event encoding. Encoding and routing is completed with route(..)
and is recommended to be performed inside a try-resource block; see class documentation for
an example.EventRouter.RoutingContext routingEvent(int type)
type returns the routing context with the buffer for event
encoding. Encoding and routing is completed with route(..) and is recommended
to be performed inside a try-resource block; see class documentation for an example.type - the event type, typically non-negative for application events (plugins use negative event types)IllegalArgumentException - if type is COMMIT or ROLLBACKvoid routeEvent(DirectBuffer buffer, int offset, int length)
APPLICATION event already encoded in the given buffer.buffer - the buffer containing the event dataoffset - offset where the event data starts in bufferlength - the length of the event data in bytesIllegalStateException - if this command has been skippedvoid routeEvent(int type,
DirectBuffer buffer,
int offset,
int length)
type.type - the event type, typically non-negative for application events (plugins use negative event types)buffer - the buffer containing the event dataoffset - offset where the event data starts in bufferlength - the length of the event data in bytesIllegalArgumentException - if type is COMMIT or ROLLBACKIllegalStateException - if this command has been skippedvoid routeEventWithoutPayload(int type)
type that carries no payload data.type - the event type, typically non-negative for application events (plugins use negative event types)IllegalArgumentException - if type is COMMIT or ROLLBACKIllegalStateException - if this command has been skippedshort nextEventIndex()
routingEvent()
then the index refers to the event currently being encoded.boolean skipCommand()
boolean isSkipped()
The application state after processing the current command will be exactly the same as before the command. Note that the command will not be be marked as processed and is normally also not replayed. Replaying of the command may occur however if the application is restarted or leadership is passed to another node and commands are replayed from the command log. However replaying occurs only if no subsequent command from the same source has yet been marked as processed.
Copyright © 2020 tools4j.org (Marco Terzer, Anton Anufriev). All Rights Reserved.