Class EventChannelImpl
- java.lang.Object
-
- io.axoniq.axonserver.connector.impl.AbstractAxonServerChannel<Void>
-
- io.axoniq.axonserver.connector.event.impl.EventChannelImpl
-
- All Implemented Interfaces:
EventChannel
public class EventChannelImpl extends AbstractAxonServerChannel<Void> implements EventChannel
EventChannelimplementation, serving as the event connection between AxonServer and a client application.
-
-
Constructor Summary
Constructors Constructor Description EventChannelImpl(ClientIdentification clientIdentification, ScheduledExecutorService executor, AxonServerManagedChannel channel)Constructs aEventChannelImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Confirmation>appendSnapshot(Event snapshotEvent)Store the givensnapshotEvent.CompletableFuture<InstructionAck>cancelSchedule(String token)Cancels the scheduled publication of an event for which the givenscheduleTokenwas returned.voidconnect()Connect this channel with AxonServer.CompletableFuture<CreateResult>createPersistentStream(String streamId, PersistentStreamProperties creationProperties)Opens the persistent stream identified bystreamId.CompletableFuture<Void>deletePersistentStream(String streamId)Deletes a persistent stream.voiddisconnect()Disconnect this channel from AxonServer.CompletableFuture<Long>findHighestSequence(String aggregateId)Find the highest sequence number (i.e. the sequence number of the most recent event) for an aggregate with givenaggregateId.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 giveninstant.booleanisReady()Validate whether this channel has all required streams connected with AxonServer.AggregateEventStreamloadSnapshots(String aggregateIdentifier, long initialSequence, long maxSequence, int maxResults)Loads Snapshot Events for the givenaggregateIdentifierwith sequence number betweeninitialSequenceandmaxSequence(inclusive), returning at mostmaxResultsnumber of snapshots.AggregateEventStreamopenAggregateStream(String aggregateIdentifier, boolean allowSnapshots)Opens a stream for consuming Events from a single aggregate, with givenallowSnapshotsindicating whether the first Event may be a Snapshot Event.AggregateEventStreamopenAggregateStream(String aggregateIdentifier, long initialSequence, long maxSequence)Opens a stream for consuming Events from a single aggregate, starting with the giveninitialSequenceuntil the givenmaxSequence.PersistentStreamopenPersistentStream(String streamId, int bufferSize, int refillBatch, PersistentStreamCallbacks callbacks)Opens the persistent stream identified bystreamId.PersistentStreamopenPersistentStream(String streamId, int bufferSize, int refillBatch, PersistentStreamCallbacks callbacks, PersistentStreamProperties creationProperties)Opens the persistent stream identified bystreamId.EventStreamopenStream(long token, int bufferSize, int refillBatch, boolean forceReadFromLeader)Open an EventStream, for sequentially consuming events from AxonServer, starting at giventokenand keeping a local buffer ofbufferSize, which is refilled after consumingrefillBatchitems.CompletableFuture<List<StreamStatus>>persistentStreams()Returns a list of persistent streams with the last confirmed token per segment.ResultStream<EventQueryResultEntry>queryEvents(String queryExpression, boolean liveStream, String contextName)Queries the Event Store for events using givenqueryExpression.ResultStream<EventQueryResultEntry>querySnapshotEvents(String queryExpression, boolean liveStream, String contextName)Queries the Event Store for snapshot events using givenqueryExpression.voidreconnect()Reconnect this channel with AxonServer.CompletableFuture<String>reschedule(String scheduleToken, Instant scheduleTime, Event event)Convenience method to cancel the scheduled event with givenscheduleTokenand reschedule the giveneventto be published at givenscheduleTime.CompletableFuture<Void>resetPersistentStreamAtHead(String streamId)Resets the position of a persistent stream to the head (most recent) event in the event store.CompletableFuture<Void>resetPersistentStreamAtPosition(String streamId, long position)Resets the position of a persistent stream to the event at given position (global index) in the event store.CompletableFuture<Void>resetPersistentStreamAtTail(String streamId)Resets the position of a persistent stream to the first (oldest) event in the event store.CompletableFuture<Void>resetPersistentStreamAtTime(String streamId, long instant)Resets the position of a persistent stream to the event at or after the given timestamp in the event store.CompletableFuture<String>scheduleEvent(Instant scheduleTime, Event event)Schedule the giveneventto be published at givenscheduleTime.CompletableFuture<Void>setPersistentStreamSegments(String streamId, int segments)Updates the number of segments for a persistent stream.AppendEventsTransactionstartAppendEventsTransaction()Starts a new transaction to append events.CompletableFuture<Void>updatePersistentStreamName(String streamId, String streamName)Updates the name for a persistent stream.-
Methods inherited from class io.axoniq.axonserver.connector.impl.AbstractAxonServerChannel
processAck, scheduleImmediateReconnect, scheduleReconnect, sendInstruction
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.axoniq.axonserver.connector.event.EventChannel
appendEvents, loadSnapshot, loadSnapshots, openAggregateStream, openAggregateStream, openStream, openStream, queryEvents, querySnapshotEvents, reschedule, scheduleEvent
-
-
-
-
Constructor Detail
-
EventChannelImpl
public EventChannelImpl(ClientIdentification clientIdentification, ScheduledExecutorService executor, AxonServerManagedChannel channel)
Constructs aEventChannelImpl.- Parameters:
executor- aScheduledExecutorServiceused to schedule reconnects of this channelchannel- theAxonServerManagedChannelused to form the connection with AxonServer
-
-
Method Detail
-
connect
public void connect()
Description copied from class:AbstractAxonServerChannelConnect this channel with AxonServer.- Specified by:
connectin classAbstractAxonServerChannel<Void>
-
reconnect
public void reconnect()
Description copied from class:AbstractAxonServerChannelReconnect this channel with AxonServer.- Specified by:
reconnectin classAbstractAxonServerChannel<Void>
-
disconnect
public void disconnect()
Description copied from class:AbstractAxonServerChannelDisconnect this channel from AxonServer.- Specified by:
disconnectin classAbstractAxonServerChannel<Void>
-
isReady
public boolean isReady()
Description copied from class:AbstractAxonServerChannelValidate whether this channel has all required streams connected with AxonServer. If the state of the channel does not require any active streams, it is considered ready and will returntrue.- Specified by:
isReadyin classAbstractAxonServerChannel<Void>- Returns:
trueif this channel is connected with AxonServer or does not require any active connections,falseotherwise
-
startAppendEventsTransaction
public AppendEventsTransaction startAppendEventsTransaction()
Description copied from interface:EventChannelStarts a new transaction to append events.- Specified by:
startAppendEventsTransactionin interfaceEventChannel- Returns:
- The transaction reference onto which to register events to append
-
scheduleEvent
public CompletableFuture<String> scheduleEvent(Instant scheduleTime, Event event)
Description copied from interface:EventChannelSchedule the giveneventto be published at givenscheduleTime. The returned value can be used to cancel the schedule, or to reschedule the event to another time.- Specified by:
scheduleEventin interfaceEventChannel- Parameters:
scheduleTime- The scheduleTime at which to publish the eventevent- The event to publish- Returns:
- a token used to cancel the schedule
-
cancelSchedule
public CompletableFuture<InstructionAck> cancelSchedule(String token)
Description copied from interface:EventChannelCancels the scheduled publication of an event for which the givenscheduleTokenwas returned.- Specified by:
cancelSchedulein interfaceEventChannel- Parameters:
token- the token provided when scheduling the event to be cancelled- Returns:
- a future reference to the result of the instruction
-
reschedule
public CompletableFuture<String> reschedule(String scheduleToken, Instant scheduleTime, Event event)
Description copied from interface:EventChannelConvenience method to cancel the scheduled event with givenscheduleTokenand reschedule the giveneventto be published at givenscheduleTime. Is effectively the same as cancelling and scheduling in separate calls, but this call requires only a single round-trip to the server.- Specified by:
reschedulein interfaceEventChannel- Parameters:
scheduleToken- the token of the event to cancelscheduleTime- the point in time to publish the new eventevent- the event to publish- Returns:
- a future reference to the token for the new schedule
-
findHighestSequence
public CompletableFuture<Long> findHighestSequence(String aggregateId)
Description copied from interface:EventChannelFind the highest sequence number (i.e. the sequence number of the most recent event) for an aggregate with givenaggregateId.If no events for an aggregate with given identifier have been found, the returned CompletableFuture will resolve to a
nullvalue.- Specified by:
findHighestSequencein interfaceEventChannel- Parameters:
aggregateId- the identifier of the aggregate to find the sequence number for- Returns:
- a CompletableFuture providing the sequence number found, or resolving to
nullwhen no event was found.
-
openStream
public EventStream openStream(long token, int bufferSize, int refillBatch, boolean forceReadFromLeader)
Description copied from interface:EventChannelOpen an EventStream, for sequentially consuming events from AxonServer, starting at giventokenand keeping a local buffer ofbufferSize, which is refilled after consumingrefillBatchitems. TheforceReadFromLeaderparameter can be used to enforce this stream to read events from the RAFT leader.A value for
bufferSizesmaller than 64 items will result in a buffer of 64. A value forrefillBatchsmaller than 16 will result in a refill batch of 16. A value larger than thebufferSizewill be reduced to match the givenbufferSize. While this will work, it is not recommended. TherefillBatchshould 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.
- Specified by:
openStreamin interfaceEventChannel- Parameters:
token- the token representing the position to start the stream, or-1to start from beginningbufferSize- the number of events to buffer locallyrefillBatch- the number of events to be consumed prior to refilling the bufferforceReadFromLeader- abooleandefining whether Events must be read from the leader- Returns:
- the Stream for consuming the requested Events
- See Also:
to use a sensible default for refill batch value.
-
createPersistentStream
public CompletableFuture<CreateResult> createPersistentStream(String streamId, PersistentStreamProperties creationProperties)
Description copied from interface:EventChannelOpens the persistent stream identified bystreamId. If the stream does not exist it will be created with the properties specified increationProperties.- Specified by:
createPersistentStreamin interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent streamcreationProperties- properties to initialize the persistent stream if it does not exist yet- Returns:
- a result indicating if the stream has been created or it already existed
-
openPersistentStream
public PersistentStream openPersistentStream(String streamId, int bufferSize, int refillBatch, PersistentStreamCallbacks callbacks)
Description copied from interface:EventChannelOpens the persistent stream identified bystreamId. Fails if the stream does not exist.- Specified by:
openPersistentStreamin interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent streambufferSize- the number of events to buffer locallyrefillBatch- the number of events to be consumed prior to refilling the buffercallbacks- the callbacks that are invoked on persistent stream events- Returns:
- a PersistedStream streaming events per segment
-
openPersistentStream
public PersistentStream openPersistentStream(String streamId, int bufferSize, int refillBatch, PersistentStreamCallbacks callbacks, PersistentStreamProperties creationProperties)
Description copied from interface:EventChannelOpens the persistent stream identified bystreamId. If the stream does not exist it will be created with the properties specified increationProperties.- Specified by:
openPersistentStreamin interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent streambufferSize- the number of events to buffer locallyrefillBatch- the number of events to be consumed prior to refilling the buffercallbacks- the callbacks that are invoked on persistent stream eventscreationProperties- properties to initialize the persistent stream if it does not exist yet- Returns:
- a PersistentStream streaming events per segment
-
deletePersistentStream
public CompletableFuture<Void> deletePersistentStream(String streamId)
Description copied from interface:EventChannelDeletes a persistent stream. If the stream does not exist the operation completes successfully.- Specified by:
deletePersistentStreamin interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent stream- Returns:
- a CompletableFuture that completes when the persistent stream is deleted
-
updatePersistentStreamName
public CompletableFuture<Void> updatePersistentStreamName(String streamId, String streamName)
Description copied from interface:EventChannelUpdates the name for a persistent stream.- Specified by:
updatePersistentStreamNamein interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent streamstreamName- the new logical name for the stream- Returns:
- a CompletableFuture that completes when the persistent stream is updated
-
setPersistentStreamSegments
public CompletableFuture<Void> setPersistentStreamSegments(String streamId, int segments)
Description copied from interface:EventChannelUpdates the number of segments for a persistent stream.- Specified by:
setPersistentStreamSegmentsin interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent streamsegments- the requested number of segments for the persistent stream- Returns:
- a CompletableFuture that completes when the persistent stream is updated
-
persistentStreams
public CompletableFuture<List<StreamStatus>> persistentStreams()
Description copied from interface:EventChannelReturns a list of persistent streams with the last confirmed token per segment.- Specified by:
persistentStreamsin interfaceEventChannel- Returns:
- a list of persistent streams
-
resetPersistentStreamAtHead
public CompletableFuture<Void> resetPersistentStreamAtHead(String streamId)
Description copied from interface:EventChannelResets the position of a persistent stream to the head (most recent) event in the event store.- Specified by:
resetPersistentStreamAtHeadin interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent stream
-
resetPersistentStreamAtTail
public CompletableFuture<Void> resetPersistentStreamAtTail(String streamId)
Description copied from interface:EventChannelResets the position of a persistent stream to the first (oldest) event in the event store.- Specified by:
resetPersistentStreamAtTailin interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent stream
-
resetPersistentStreamAtPosition
public CompletableFuture<Void> resetPersistentStreamAtPosition(String streamId, long position)
Description copied from interface:EventChannelResets the position of a persistent stream to the event at given position (global index) in the event store.- Specified by:
resetPersistentStreamAtPositionin interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent streamposition- the global index of the first event to be returned
-
resetPersistentStreamAtTime
public CompletableFuture<Void> resetPersistentStreamAtTime(String streamId, long instant)
Description copied from interface:EventChannelResets the position of a persistent stream to the event at or after the given timestamp in the event store.- Specified by:
resetPersistentStreamAtTimein interfaceEventChannel- Parameters:
streamId- the unique identification of a persistent streaminstant- the timestamp of the first event to be included in the stream
-
openAggregateStream
public AggregateEventStream openAggregateStream(String aggregateIdentifier, boolean allowSnapshots)
Description copied from interface:EventChannelOpens a stream for consuming Events from a single aggregate, with givenallowSnapshotsindicating whether the first Event may be a Snapshot Event. When givenallowSnapshotsisfalse, 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.- Specified by:
openAggregateStreamin interfaceEventChannel- Parameters:
aggregateIdentifier- the identifier of the Aggregate to load events forallowSnapshots- abooleanwhether to allow a snapshot event as first event, or not- Returns:
- a stream of Events for the given Aggregate
-
openAggregateStream
public AggregateEventStream openAggregateStream(String aggregateIdentifier, long initialSequence, long maxSequence)
Description copied from interface:EventChannelOpens a stream for consuming Events from a single aggregate, starting with the giveninitialSequenceuntil the givenmaxSequence. This method will not return a Snapshot Event as first event.Note: a
maxSequenceof0will result in all events after the initial sequence to be returned.- Specified by:
openAggregateStreamin interfaceEventChannel- Parameters:
aggregateIdentifier- 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 return- Returns:
- a stream of Events for the given Aggregate
-
appendSnapshot
public CompletableFuture<Confirmation> appendSnapshot(Event snapshotEvent)
Description copied from interface:EventChannelStore the givensnapshotEvent.- Specified by:
appendSnapshotin interfaceEventChannel- Parameters:
snapshotEvent- the Snapshot Event to store- Returns:
- a CompletableFuture providing the confirmation upon storage of the snapshot
-
loadSnapshots
public AggregateEventStream loadSnapshots(String aggregateIdentifier, long initialSequence, long maxSequence, int maxResults)
Description copied from interface:EventChannelLoads Snapshot Events for the givenaggregateIdentifierwith sequence number betweeninitialSequenceandmaxSequence(inclusive), returning at mostmaxResultsnumber of snapshots.Note that Snapshot Events are returned in reverse order of their sequence number.
- Specified by:
loadSnapshotsin interfaceEventChannel- Parameters:
aggregateIdentifier- 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 return- Returns:
- a stream containing Snapshot Events within the requested bounds
-
getLastToken
public CompletableFuture<Long> getLastToken()
Description copied from interface:EventChannelRetrieves the Token referring to the most recent Event in the Event Store. Using this token to open a stream will only yield events that were appended after execution of this call.- Specified by:
getLastTokenin interfaceEventChannel- Returns:
- a completable future resolving the Token of the last (i.e. most recent) event
-
getFirstToken
public CompletableFuture<Long> getFirstToken()
Description copied from interface:EventChannelRetrieves the Token referring to the first Event in the Event Store. Using this token to open a stream will yield all events that available in the event store.- Specified by:
getFirstTokenin interfaceEventChannel- Returns:
- a completable future resolving the Token of the first (i.e. oldest) event
-
getTokenAt
public CompletableFuture<Long> getTokenAt(long instant)
Description copied from interface:EventChannelRetrieves the token referencing the first Event in the Event Store closest to the giveninstant.The timestamp of the referenced Event may be on or after the given
instantwhen theinstantoccurred within the Event Store's lifecycle. Will return the most recent token when theinstantis placed into the future. Will return the earliest token if theinstantis 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 theinstant.- Specified by:
getTokenAtin interfaceEventChannel- Parameters:
instant- The point in time for which to retrieve a token referencing an event within the Event Store. If the giveninstantresides outside the Event Store its existing time frame, the latest or earliest token is returned for a future or pastinstantrespectively.- Returns:
- A completable future resolving the Token of the first (i.e. oldest) event with timestamp on or after
given
instant.
-
queryEvents
public ResultStream<EventQueryResultEntry> queryEvents(String queryExpression, boolean liveStream, String contextName)
Description copied from interface:EventChannelQueries the Event Store for events using givenqueryExpression. The givenliveStreamindicates 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. When acontextNameis provided the query is executed for that context, instead of the main context for the channel.- Specified by:
queryEventsin interfaceEventChannel- Parameters:
queryExpression- a valid Event Stream Query Language expressionliveStream- whether to continue processing live eventscontextName- the name of the context of the event store to query- Returns:
- a ResultStream containing the query results
-
querySnapshotEvents
public ResultStream<EventQueryResultEntry> querySnapshotEvents(String queryExpression, boolean liveStream, String contextName)
Description copied from interface:EventChannelQueries the Event Store for snapshot events using givenqueryExpression. The givenliveStreamindicates 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. When acontextNameis provided the query is executed for that context, instead of the main context for the channel.- Specified by:
querySnapshotEventsin interfaceEventChannel- Parameters:
queryExpression- a valid Event Stream Query Language expressionliveStream- whether to continue processing live snapshot eventscontextName- the name of the context of the event store to query- Returns:
- a ResultStream containing the query results
-
-