public class EventChannelImpl extends AbstractAxonServerChannel<Void> implements EventChannel
EventChannel implementation, serving as the event connection between AxonServer and a client application.| Constructor and Description |
|---|
EventChannelImpl(ClientIdentification clientIdentification,
ScheduledExecutorService executor,
AxonServerManagedChannel channel)
Constructs a
EventChannelImpl. |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Confirmation> |
appendSnapshot(Event snapshotEvent)
Store the given
snapshotEvent. |
CompletableFuture<InstructionAck> |
cancelSchedule(String token)
Cancels the scheduled publication of an event for which the given
scheduleToken was returned. |
void |
connect()
Connect this channel with AxonServer.
|
void |
disconnect()
Disconnect this channel from AxonServer.
|
CompletableFuture<Long> |
findHighestSequence(String aggregateId)
Find the highest sequence number (i.e.
|
CompletableFuture<Long> |
getFirstToken()
Retrieves the Token referring to the first Event in the Event Store.
|
CompletableFuture<Long> |
getLastToken()
Retrieves the Token referring to the most recent Event in the Event Store.
|
CompletableFuture<Long> |
getTokenAt(long instant)
Retrieves the token referencing the first Event in the Event Store closest to the given
instant. |
boolean |
isReady()
Validate whether this channel has all required streams connected with AxonServer.
|
AggregateEventStream |
loadSnapshots(String aggregateIdentifier,
long initialSequence,
long maxSequence,
int maxResults)
Loads Snapshot Events for the given
aggregateIdentifier with sequence number between initialSequence and maxSequence (inclusive), returning at most maxResults number of snapshots. |
AggregateEventStream |
openAggregateStream(String aggregateIdentifier,
boolean allowSnapshots)
Opens a stream for consuming Events from a single aggregate, with given
allowSnapshots indicating whether
the first Event may be a Snapshot Event. |
AggregateEventStream |
openAggregateStream(String aggregateIdentifier,
long initialSequence,
long maxSequence)
Opens a stream for consuming Events from a single aggregate, starting with the given
initialSequence
until the given maxSequence. |
EventStream |
openStream(long token,
int bufferSize,
int refillBatch,
boolean forceReadFromLeader)
Open an EventStream, for sequentially consuming events from AxonServer, starting at given
token and
keeping a local buffer of bufferSize, which is refilled after consuming refillBatch items. |
ResultStream<EventQueryResultEntry> |
queryEvents(String queryExpression,
boolean liveStream)
Queries the Event Store for events using given
queryExpression. |
ResultStream<EventQueryResultEntry> |
querySnapshotEvents(String queryExpression,
boolean liveStream)
Queries the Event Store for snapshot events using given
queryExpression. |
void |
reconnect()
Reconnect this channel with AxonServer.
|
CompletableFuture<String> |
reschedule(String scheduleToken,
Instant scheduleTime,
Event event)
Convenience method to cancel the scheduled event with given
scheduleToken and reschedule the given event to be published at given scheduleTime. |
CompletableFuture<String> |
scheduleEvent(Instant scheduleTime,
Event event)
Schedule the given
event to be published at given scheduleTime. |
AppendEventsTransaction |
startAppendEventsTransaction()
Starts a new transaction to append events.
|
processAck, scheduleImmediateReconnect, scheduleReconnect, sendInstructionclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitappendEvents, loadSnapshot, loadSnapshots, openAggregateStream, openAggregateStream, openStream, openStream, reschedule, scheduleEventpublic EventChannelImpl(ClientIdentification clientIdentification, ScheduledExecutorService executor, AxonServerManagedChannel channel)
EventChannelImpl.executor - a ScheduledExecutorService used to schedule reconnects of this channelchannel - the AxonServerManagedChannel used to form the connection with AxonServerpublic void connect()
AbstractAxonServerChannelconnect in class AbstractAxonServerChannel<Void>public void reconnect()
AbstractAxonServerChannelreconnect in class AbstractAxonServerChannel<Void>public void disconnect()
AbstractAxonServerChanneldisconnect in class AbstractAxonServerChannel<Void>public boolean isReady()
AbstractAxonServerChanneltrue.isReady in class AbstractAxonServerChannel<Void>true if this channel is connected with AxonServer or does not require any active connections,
false otherwisepublic AppendEventsTransaction startAppendEventsTransaction()
EventChannelstartAppendEventsTransaction in interface EventChannelpublic CompletableFuture<String> scheduleEvent(Instant scheduleTime, Event event)
EventChannelevent to be published at given scheduleTime. The returned value can be used to
cancel the schedule, or to reschedule the event to another time.scheduleEvent in interface EventChannelscheduleTime - The scheduleTime at which to publish the eventevent - The event to publishpublic CompletableFuture<InstructionAck> cancelSchedule(String token)
EventChannelscheduleToken was returned.cancelSchedule in interface EventChanneltoken - the token provided when scheduling the event to be cancelledpublic CompletableFuture<String> reschedule(String scheduleToken, Instant scheduleTime, Event event)
EventChannelscheduleToken and reschedule the given event to be published at given scheduleTime. Is effectively the same as cancelling and scheduling in
separate calls, but this call requires only a single round-trip to the server.reschedule in interface EventChannelscheduleToken - the token of the event to cancelscheduleTime - the point in time to publish the new eventevent - the event to publishpublic CompletableFuture<Long> findHighestSequence(String aggregateId)
EventChannelaggregateId.
If no events for an aggregate with given identifier have been found, the returned CompletableFuture will resolve
to a null value.
findHighestSequence in interface EventChannelaggregateId - the identifier of the aggregate to find the sequence number fornull when no event was
found.public EventStream openStream(long token, int bufferSize, int refillBatch, boolean forceReadFromLeader)
EventChanneltoken and
keeping a local buffer of bufferSize, which is refilled after consuming refillBatch items. The
forceReadFromLeader parameter can be used to enforce this stream to read events from the RAFT leader.
A value for bufferSize smaller than 64 items will result in a buffer of 64. A value for refillBatch smaller than 16 will result in a refill batch of 16. A value larger than the bufferSize will
be reduced to match the given bufferSize. While this will work, it is not recommended. The refillBatch should be sufficiently small to allow for a constant flow of messages to consume.
The stream of Events starts immediately upon the invocation of this method, making the first messages available for consumption as soon as they have arrived from AxonServer.
openStream in interface EventChanneltoken - the token representing the position to start the stream, or -1 to start from
beginningbufferSize - the number of events to buffer locallyrefillBatch - the number of events to be consumed prior to refilling the bufferforceReadFromLeader - a boolean defining whether Events must be read from the leaderto use a sensible default for refill batch value.public AggregateEventStream openAggregateStream(String aggregateIdentifier, boolean allowSnapshots)
EventChannelallowSnapshots indicating whether
the first Event may be a Snapshot Event. When given allowSnapshots is false, this method will
return events starting at the first available sequence number of the aggregate (typically 0).
Note that this method does not have any form of flow control. All messages are buffered locally. When expecting
large streams of events, consider using EventChannel.openAggregateStream(String, long, long) to retrieve chunks of
the event stream instead.
openAggregateStream in interface EventChannelaggregateIdentifier - the identifier of the Aggregate to load events forallowSnapshots - a boolean whether to allow a snapshot event as first event, or notpublic AggregateEventStream openAggregateStream(String aggregateIdentifier, long initialSequence, long maxSequence)
EventChannelinitialSequence
until the given maxSequence. This method will not return a Snapshot Event as first event.
Note: a maxSequence of 0 will result in all events after the initial sequence to be returned.
openAggregateStream in interface EventChannelaggregateIdentifier - the identifier of the Aggregate to load events forinitialSequence - the sequence number of the first event to returnmaxSequence - the sequence number of the last event to returnpublic CompletableFuture<Confirmation> appendSnapshot(Event snapshotEvent)
EventChannelsnapshotEvent.appendSnapshot in interface EventChannelsnapshotEvent - the Snapshot Event to storepublic AggregateEventStream loadSnapshots(String aggregateIdentifier, long initialSequence, long maxSequence, int maxResults)
EventChannelaggregateIdentifier with sequence number between initialSequence and maxSequence (inclusive), returning at most maxResults number of snapshots.
Note that Snapshot Events are returned in reverse order of their sequence number.
loadSnapshots in interface EventChannelaggregateIdentifier - the identifier of the Aggregate to retrieve snapshots forinitialSequence - the lowest sequence number of snapshots to returnmaxSequence - the highest sequence number of snapshots to returnmaxResults - the maximum allowed number of snapshots to returnpublic CompletableFuture<Long> getLastToken()
EventChannelgetLastToken in interface EventChannelpublic CompletableFuture<Long> getFirstToken()
EventChannelgetFirstToken in interface EventChannelpublic CompletableFuture<Long> getTokenAt(long instant)
EventChannelinstant.
The timestamp of the referenced Event may be on or after the given instant when the instant
occurred within the Event Store's lifecycle. Will return the most recent token when the instant is placed
into the future. Will return the earliest token if the instant is placed in the past (read: before the
existence of this Event Store).
Using this token to open a stream will yield all events with a timestamp starting at that instance but may also
yield events created before this instant, whose append transaction completed after the instant.
getTokenAt in interface EventChannelinstant - The point in time for which to retrieve a token referencing an event within the Event Store. If
the given instant resides outside the Event Store its existing time frame, the latest or
earliest token is returned for a future or past instant respectively.instant.public ResultStream<EventQueryResultEntry> queryEvents(String queryExpression, boolean liveStream)
EventChannelqueryExpression. The given liveStream indicates
whether the query should complete when the end of the Event Stream is reached, or if the query should continue
processing events as they are stored.queryEvents in interface EventChannelqueryExpression - a valid Event Stream Query Language expressionliveStream - whether to continue processing live eventspublic ResultStream<EventQueryResultEntry> querySnapshotEvents(String queryExpression, boolean liveStream)
EventChannelqueryExpression. The given liveStream
indicates whether the query should complete when the end of the Snapshot Event Stream is reached, or if the query
should continue processing snapshot events as they are stored.querySnapshotEvents in interface EventChannelqueryExpression - a valid Event Stream Query Language expressionliveStream - whether to continue processing live snapshot eventsCopyright © 2020–2022 AxonIQ BV. All rights reserved.