Class WebSocketEventStoreClient
java.lang.Object
io.fluxzero.sdk.common.websocket.AbstractWebsocketClient
io.fluxzero.sdk.persisting.eventsourcing.client.WebSocketEventStoreClient
- All Implemented Interfaces:
WebsocketEndpoint, EventStoreClient, ModelCommitBatchingClient, AutoCloseable
public class WebSocketEventStoreClient
extends AbstractWebsocketClient
implements EventStoreClient, ModelCommitBatchingClient
WebSocket-based implementation of the
EventStoreClient, enabling interaction with the Fluxzero Runtime's event
store via a persistent WebSocket connection.
This implementation supports:
- Storing events for event-sourced aggregates
- Efficient, paginated retrieval of aggregate event streams
- Deleting aggregate event streams
- Maintaining aggregate/entity relationships
The fetchBatchSize setting controls how many events are fetched per paginated request when loading
an aggregate's event history. This ensures efficient memory usage while still supporting large aggregates.
End users rarely interact with this client directly. Instead, they typically use higher-level abstractions
such as EventStore or
AggregateRepository.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractWebsocketClient
AbstractWebsocketClient.ClientHandshakeConfigurator, AbstractWebsocketClient.ConnectionSetup, AbstractWebsocketClient.PingRegistration, AbstractWebsocketClient.PreparedRequest<R>, AbstractWebsocketClient.WebSocketRequestNested classes/interfaces inherited from interface ModelCommitBatchingClient
ModelCommitBatchingClient.ModelCommitBatch, ModelCommitBatchingClient.ModelCommitCompletion, ModelCommitBatchingClient.ModelCommitResultProcessorNested classes/interfaces inherited from interface WebsocketEndpoint
WebsocketEndpoint.ReceiveTiming -
Field Summary
Fields inherited from class AbstractWebsocketClient
CLIENT_HANDSHAKE_CONFIGURATOR_USER_PROPERTY, CLIENT_SESSION_ID_USER_PROPERTY, CONNECTION_RETRY_LOG_INTERVAL, CONNECTION_TIMEOUT_FAILSAFE_GRACE, defaultObjectMapper, defaultWebsocketConnector, NEGOTIATED_SESSION_ID_USER_PROPERTY, RUNTIME_SESSION_ID_USER_PROPERTY, RUNTIME_VERSION_USER_PROPERTY, SELECTED_COMPRESSION_ALGORITHM_USER_PROPERTY, SELECTED_TRANSPORT_FORMAT_USER_PROPERTY -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketEventStoreClient(String endPointUrl, WebSocketClient client) Creates a newWebSocketEventStoreClientwith a default batch size of 8192.WebSocketEventStoreClient(URI endPointUri, int fetchBatchSize, WebSocketClient client) Creates a newWebSocketEventStoreClientwith a specified batch size.WebSocketEventStoreClient(URI endPointUri, int fetchBatchSize, WebSocketClient client, boolean sendMetrics) Constructs the WebSocket client with full customization. -
Method Summary
Modifier and TypeMethodDescriptionCompletableFuture<io.fluxzero.common.api.modeling.ModelGraphProjectionStatus> awaitModelGraphProjection(io.fluxzero.common.api.modeling.AwaitModelGraphProjection request) Completes after every affected root in a graph projection has crossed the requested committed state boundary.beginModelCommitBatch(int capacity) Begins a transport batch for commits that become ready independently during handler execution.CompletableFuture<io.fluxzero.common.api.modeling.CommitModelsResult> commitModels(io.fluxzero.common.api.modeling.CommitModels commit) Commits an independent-model commit and retains the positions returned by the runtime.deleteEvents(String aggregateId, io.fluxzero.common.Guarantee guarantee) Sends a delete command for the event stream of the specified aggregate.CompletableFuture<io.fluxzero.common.api.modeling.ModelDeletionResult> deleteModel(io.fluxzero.common.api.modeling.DeleteModel request) Executes or resumes an idempotent independent-model hard deletion.getAggregateIds(io.fluxzero.common.api.modeling.GetAggregateIds request) Retrieves a map of aggregate IDs associated with a given entity, using aGetAggregateIdsrequest.AggregateEventStream<io.fluxzero.common.api.SerializedMessage> Retrieves events for a specific aggregate starting after a given sequence number, optionally limiting the result size.io.fluxzero.common.api.modeling.GetModelChangeResultgetModelChange(io.fluxzero.common.api.modeling.GetModelChange request) Resolves the durable targets of one model-commit substep.io.fluxzero.common.api.modeling.GetModelEventsResultgetModelEvents(io.fluxzero.common.api.modeling.GetModelEvents request) Batch-loads independent model heads and event memberships at one pinned state boundary.io.fluxzero.common.api.modeling.GetModelGraphResultgetModelGraph(io.fluxzero.common.api.modeling.GetModelGraph request) Loads one bounded temporal model graph and an optional first page of its grouped model streams.io.fluxzero.common.api.modeling.ModelGraphProjectionStatusgetModelGraphProjectionStatus(io.fluxzero.common.api.modeling.GetModelGraphProjectionStatus request) Returns the current high-watermark and backlog for one materialized graph projection.List<io.fluxzero.common.api.modeling.Relationship> getRelationships(io.fluxzero.common.api.modeling.GetRelationships request) Retrieves all relationships for a given entity, using aGetRelationshipsrequest.protected StringjfrResultType(List<io.fluxzero.common.api.RequestResult> results) Classifies decoded results for optional protocol-specific JFR diagnostics.protected intmaxRequestBatchSize(List<io.fluxzero.common.api.Request> requests) Returns the maximum transport chunk for the supplied requests.protected List<? extends io.fluxzero.common.websocket.WebSocketPayloadCodec> Returns compact payload codecs owned by this concrete protocol client.io.fluxzero.common.api.modeling.ModelDeletionPlanplanModelDeletion(io.fluxzero.common.api.modeling.PlanModelDeletion request) Creates a bounded, non-mutating plan for an explicit independent-model hard deletion.protected CompletableFuture<Void> prepareResults(List<io.fluxzero.common.api.RequestResult> results, List<Object> requestContexts) Allows a specialized client to complete request-owned work for a decoded result group before individual request futures are released.CompletableFuture<io.fluxzero.common.api.modeling.ModelGraphProjectionStatus> registerModelGraphProjection(io.fluxzero.common.api.modeling.RegisterModelGraphProjection request) Idempotently registers an asynchronous materialized model-graph projection.repairRelationships(io.fluxzero.common.api.modeling.RepairRelationships request) Sends a request to repair relationships for a specific entity.protected List<io.fluxzero.common.api.RequestResult> restoreResultContext(List<io.fluxzero.common.api.RequestResult> results) Restores request-owned context that a specialized compact response deliberately omits from the wire.protected io.fluxzero.common.jfr.FluxzeroJfr.BatchstartRequestBatchEvent(List<io.fluxzero.common.api.Request> requests) Starts an optional request-batch event owned by the concrete protocol client.storeEvents(String aggregateId, List<io.fluxzero.common.api.SerializedMessage> events, boolean storeOnly, io.fluxzero.common.Guarantee guarantee) Stores events for a specific aggregate, with control over store-only mode and delivery guarantee.CompletableFuture<io.fluxzero.common.api.modeling.TrackModelUpdatesResult> trackModelUpdates(io.fluxzero.common.api.modeling.TrackModelUpdates request) Long-polls committed independent-model commit substeps after a client-controlled state cursor.updateRelationships(io.fluxzero.common.api.modeling.UpdateRelationships request) Sends a request to update the relationships of an entity or aggregate.Methods inherited from class AbstractWebsocketClient
abort, captureReceiveTiming, close, close, connectToServer, connectToServer, createConnectionRetryConfiguration, createConnectionSetup, createConnectionSetup, getCloseHandshakeTimeout, getCompressionAlgorithm, getConnectionTimeoutFailsafeGrace, getNegotiatedSessionId, getRuntimeVersion, getTransportFormat, handleClose, handleError, handleMessage, handlePong, handleResult, handleResult, logConnectionRetryStatus, logSuccessfulReconnect, metricsMetadata, onClose, onError, onMessage, onMessage, onOpen, onPong, outstandingRequest, prepareRequest, prepareRequest, restoreResultContext, retryOutstandingRequests, retryOutstandingRequestsAsync, retryOutstandingRequestsDelay, schedulePing, send, send, sendAndWait, sendCommand, sendPing, sendPreparedRequests, toString, transportCodec, tryPublishMetricsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface EventStoreClient
close, deleteEvents, getAggregatesFor, getEvents, getEvents, getRelationships, storeEvents
-
Constructor Details
-
WebSocketEventStoreClient
Creates a newWebSocketEventStoreClientwith a default batch size of 8192.- Parameters:
endPointUrl- The URL to the Fluxzero Runtime event sourcing endpoint.client- The WebSocket client instance.
-
WebSocketEventStoreClient
Creates a newWebSocketEventStoreClientwith a specified batch size.- Parameters:
endPointUri- The URI to the event store endpoint.fetchBatchSize- Maximum number of events to retrieve per page.client- The WebSocket client.
-
WebSocketEventStoreClient
public WebSocketEventStoreClient(URI endPointUri, int fetchBatchSize, WebSocketClient client, boolean sendMetrics) Constructs the WebSocket client with full customization.- Parameters:
endPointUri- URI of the event sourcing endpoint.fetchBatchSize- The size of event batches fetched from the server.client- The WebSocket client.sendMetrics- Whether to send metrics to the Fluxzero Runtime.
-
-
Method Details
-
payloadCodecs
Description copied from class:AbstractWebsocketClientReturns compact payload codecs owned by this concrete protocol client.- Overrides:
payloadCodecsin classAbstractWebsocketClient
-
maxRequestBatchSize
Description copied from class:AbstractWebsocketClientReturns the maximum transport chunk for the supplied requests.- Overrides:
maxRequestBatchSizein classAbstractWebsocketClient
-
startRequestBatchEvent
protected io.fluxzero.common.jfr.FluxzeroJfr.Batch startRequestBatchEvent(List<io.fluxzero.common.api.Request> requests) Description copied from class:AbstractWebsocketClientStarts an optional request-batch event owned by the concrete protocol client.- Overrides:
startRequestBatchEventin classAbstractWebsocketClient
-
jfrResultType
Description copied from class:AbstractWebsocketClientClassifies decoded results for optional protocol-specific JFR diagnostics.- Overrides:
jfrResultTypein classAbstractWebsocketClient
-
storeEvents
public CompletableFuture<Void> storeEvents(String aggregateId, List<io.fluxzero.common.api.SerializedMessage> events, boolean storeOnly, io.fluxzero.common.Guarantee guarantee) Stores events for a specific aggregate, with control over store-only mode and delivery guarantee.- Specified by:
storeEventsin interfaceEventStoreClient- Parameters:
aggregateId- The aggregate ID.events- Events to store.storeOnly- Iftrue, events will not be published.guarantee- The guarantee level for this operation.- Returns:
- A future representing completion of the store operation.
-
commitModels
public CompletableFuture<io.fluxzero.common.api.modeling.CommitModelsResult> commitModels(io.fluxzero.common.api.modeling.CommitModels commit) Commits an independent-model commit and retains the positions returned by the runtime.- Specified by:
commitModelsin interfaceEventStoreClient- Parameters:
commit- complete model commit with its durable idempotency key- Returns:
- durable result containing the positions assigned by the event store
-
beginModelCommitBatch
- Specified by:
beginModelCommitBatchin interfaceModelCommitBatchingClient
-
beginReadyModelCommitBatch
Description copied from interface:ModelCommitBatchingClientBegins a transport batch for commits that become ready independently during handler execution.Unlike
ModelCommitBatchingClient.beginModelCommitBatch(int), this batch does not imply that commit execution waits for the batch boundary. Implementations may release bounded full chunks immediately and useModelCommitBatchingClient.ModelCommitBatch.flush()only to release the remaining tail. Returningnullretains individual commit transport.- Specified by:
beginReadyModelCommitBatchin interfaceModelCommitBatchingClient
-
prepareResults
protected CompletableFuture<Void> prepareResults(List<io.fluxzero.common.api.RequestResult> results, List<Object> requestContexts) Description copied from class:AbstractWebsocketClientAllows a specialized client to complete request-owned work for a decoded result group before individual request futures are released.- Overrides:
prepareResultsin classAbstractWebsocketClient
-
restoreResultContext
protected List<io.fluxzero.common.api.RequestResult> restoreResultContext(List<io.fluxzero.common.api.RequestResult> results) Description copied from class:AbstractWebsocketClientRestores request-owned context that a specialized compact response deliberately omits from the wire.- Overrides:
restoreResultContextin classAbstractWebsocketClient
-
getModelEvents
public io.fluxzero.common.api.modeling.GetModelEventsResult getModelEvents(io.fluxzero.common.api.modeling.GetModelEvents request) Description copied from interface:EventStoreClientBatch-loads independent model heads and event memberships at one pinned state boundary.- Specified by:
getModelEventsin interfaceEventStoreClient
-
trackModelUpdates
public CompletableFuture<io.fluxzero.common.api.modeling.TrackModelUpdatesResult> trackModelUpdates(io.fluxzero.common.api.modeling.TrackModelUpdates request) Description copied from interface:EventStoreClientLong-polls committed independent-model commit substeps after a client-controlled state cursor.- Specified by:
trackModelUpdatesin interfaceEventStoreClient
-
getModelGraph
public io.fluxzero.common.api.modeling.GetModelGraphResult getModelGraph(io.fluxzero.common.api.modeling.GetModelGraph request) Description copied from interface:EventStoreClientLoads one bounded temporal model graph and an optional first page of its grouped model streams.- Specified by:
getModelGraphin interfaceEventStoreClient
-
getModelChange
public io.fluxzero.common.api.modeling.GetModelChangeResult getModelChange(io.fluxzero.common.api.modeling.GetModelChange request) Description copied from interface:EventStoreClientResolves the durable targets of one model-commit substep.- Specified by:
getModelChangein interfaceEventStoreClient
-
registerModelGraphProjection
public CompletableFuture<io.fluxzero.common.api.modeling.ModelGraphProjectionStatus> registerModelGraphProjection(io.fluxzero.common.api.modeling.RegisterModelGraphProjection request) Description copied from interface:EventStoreClientIdempotently registers an asynchronous materialized model-graph projection.- Specified by:
registerModelGraphProjectionin interfaceEventStoreClient
-
getModelGraphProjectionStatus
public io.fluxzero.common.api.modeling.ModelGraphProjectionStatus getModelGraphProjectionStatus(io.fluxzero.common.api.modeling.GetModelGraphProjectionStatus request) Description copied from interface:EventStoreClientReturns the current high-watermark and backlog for one materialized graph projection.- Specified by:
getModelGraphProjectionStatusin interfaceEventStoreClient
-
awaitModelGraphProjection
public CompletableFuture<io.fluxzero.common.api.modeling.ModelGraphProjectionStatus> awaitModelGraphProjection(io.fluxzero.common.api.modeling.AwaitModelGraphProjection request) Description copied from interface:EventStoreClientCompletes after every affected root in a graph projection has crossed the requested committed state boundary.- Specified by:
awaitModelGraphProjectionin interfaceEventStoreClient
-
planModelDeletion
public io.fluxzero.common.api.modeling.ModelDeletionPlan planModelDeletion(io.fluxzero.common.api.modeling.PlanModelDeletion request) Description copied from interface:EventStoreClientCreates a bounded, non-mutating plan for an explicit independent-model hard deletion.- Specified by:
planModelDeletionin interfaceEventStoreClient
-
deleteModel
public CompletableFuture<io.fluxzero.common.api.modeling.ModelDeletionResult> deleteModel(io.fluxzero.common.api.modeling.DeleteModel request) Description copied from interface:EventStoreClientExecutes or resumes an idempotent independent-model hard deletion.- Specified by:
deleteModelin interfaceEventStoreClient
-
getEvents
public AggregateEventStream<io.fluxzero.common.api.SerializedMessage> getEvents(String aggregateId, long lastSequenceNumber, int maxSize) Retrieves events for a specific aggregate starting after a given sequence number, optionally limiting the result size.- Specified by:
getEventsin interfaceEventStoreClient- Parameters:
aggregateId- The aggregate ID.lastSequenceNumber- Sequence number to resume after.maxSize- Maximum number of events to return (or -1 for unlimited).- Returns:
- A stream of serialized events.
-
updateRelationships
public CompletableFuture<Void> updateRelationships(io.fluxzero.common.api.modeling.UpdateRelationships request) Sends a request to update the relationships of an entity or aggregate.- Specified by:
updateRelationshipsin interfaceEventStoreClient- Parameters:
request- The update request.- Returns:
- A future that completes when the operation is acknowledged.
-
repairRelationships
public CompletableFuture<Void> repairRelationships(io.fluxzero.common.api.modeling.RepairRelationships request) Sends a request to repair relationships for a specific entity.- Specified by:
repairRelationshipsin interfaceEventStoreClient- Parameters:
request- The repair request.- Returns:
- A future that completes when the repair is done.
-
getAggregateIds
Retrieves a map of aggregate IDs associated with a given entity, using aGetAggregateIdsrequest.- Specified by:
getAggregateIdsin interfaceEventStoreClient- Parameters:
request- The request containing filtering options.- Returns:
- A map of aggregate IDs referencing the target entity.
-
getRelationships
public List<io.fluxzero.common.api.modeling.Relationship> getRelationships(io.fluxzero.common.api.modeling.GetRelationships request) Retrieves all relationships for a given entity, using aGetRelationshipsrequest.- Specified by:
getRelationshipsin interfaceEventStoreClient- Parameters:
request- The request containing filter parameters.- Returns:
- A list of matching relationships.
-
deleteEvents
public CompletableFuture<Void> deleteEvents(String aggregateId, io.fluxzero.common.Guarantee guarantee) Sends a delete command for the event stream of the specified aggregate.- Specified by:
deleteEventsin interfaceEventStoreClient- Parameters:
aggregateId- The aggregate ID.guarantee- The guarantee to apply.- Returns:
- A future that completes when deletion is acknowledged.
-