Interface Fluxzero
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultFluxzero
This interface exposes static convenience methods to publish and track messages, interact with aggregates, schedule tasks, index/search documents, and more. It is designed to reduce boilerplate and promote location transparency in message-driven systems.
Usage Patterns
- To send or publish messages, use static methods such as
sendCommand(Object)orpublishEvent(Object). - To track incoming messages, register handlers using
registerHandlers(Object...). - To interact with independent models, use
loadModel(Id)ormodelRepository(). - To interact with legacy aggregates, use
loadAggregate(Id)oraggregateRepository().
Most applications will never need to hold or inject a Fluxzero instance directly. Instead, the Java SDK
automatically binds the relevant instance to a thread-local scope, allowing access via static methods.
A concrete instance is typically constructed using DefaultFluxzero.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classstatic final record -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AtomicReference<Fluxzero> Fluxzero instance set by the current application.static final ThreadLocal<Fluxzero> Thread-local binding of the currentFluxzeroinstance. -
Method Summary
Modifier and TypeMethodDescriptionReturns a client to assist with event sourcing.default <R> RApplies the given function with this Fluxzero set as current threadlocal instance.static <T> Entity<T> asEntity(T value) Returns an Entity containing given value.static <T> Graph<T> assertAndApply(Graph<T> target, Object update) Runs and commits an update against the explicitly selected model graph, independently of any model ID carried by the update payload.static <T> Graph<T> assertAndApply(Graph<T> target, Object update, io.fluxzero.common.api.Metadata metadata) Runs and commits an update with additional metadata against the explicitly selected model graph.static voidassertAndApply(Object update) Runs the model assertions, apply interceptors, and applies declared for the given update and waits until the resulting model commit has been committed.static voidassertAndApply(Object update, io.fluxzero.common.api.Metadata metadata) Runs and commits a model commit with the supplied metadata.static CompletableFuture<Void> assertAndApplyAllAsync(Collection<?> updates) Runs and commits multiple independent model updates asynchronously.static CompletableFuture<Void> assertAndApplyAsync(Object update) Runs the model assertions, apply interceptors, and applies declared for the given update without blocking the caller, and completes after the resulting model commit has been durably stored.static CompletableFuture<Void> assertAndApplyAsync(Object update, io.fluxzero.common.api.Metadata metadata) Runs and commits a model commit asynchronously with the supplied metadata.static voidassertLegal(Object update) Runs apply interceptors and immediate model assertions declared for the given update without invoking applies or committing model changes.static voidassertLegal(Object update, io.fluxzero.common.api.Metadata metadata) Runs apply interceptors and immediate model assertions with the supplied metadata, without invoking applies or committing model changes.io.fluxzero.common.RegistrationbeforeShutdown(Runnable task) Register a task to run before this Fluxzero instance is closed.static BulkUpdateBuilderbulkUpdate(Object collection) Prepare a fluent bulk update for the given document collection.io.fluxzero.common.caching.Cachecache()Returns the cache used by the client to cache aggregates etc.static voidcancelSchedule(Object scheduleId) Cancels the schedule with givenscheduleId.client()Returns the low level client used by this Fluxzero instance to interface with the Fluxzero Runtime.clock()Returns the clock used by Fluxzero to generate timestamps.default voidclose()Closes this Fluxzero instance gracefully.voidclose(boolean silently) Closes this Fluxzero instance gracefully.Returns the gateway for command messages.static CompletableFuture<Void> commit()Commits Model changes already produced in the current handling context without waiting for its normal automatic commit boundary.default CompletableFuture<Void> Flushes Model changes already attached to the current handling context.Returns theFluxzeroConfigurationof this Fluxzero instance.Returns the provider of correlation data for published messages.static ClockGets the clock of the current Fluxzero instance (obtained viagetOptionally()).Gets the current correlation data, which by default depends on the currentClient,TrackerandDeserializingMessagestatic IdentityProviderFetches the configured identity provider used for both functional and technical IDs.static InstantGets the time according to the current Fluxzero clock (obtained viacurrentClock()).customGateway(String topic) Returns the gateway for given custom message topic.static CompletableFuture<Void> deleteCollection(Object collection) Deletes a search collection if it exists.static CompletableFuture<Void> deleteDocument(Object id, Object collection) Deletes the document with given id in given collection if it exists.Returns a client for the document search service offered by Fluxzero.static Objectdowncast(io.fluxzero.common.api.Data<?> data, int desiredRevision) Downcasts aDataobject to the specified revision level.static ObjectDowncasts the given object to a previous revision.Returns the gateway for any error messages published while handling a command or query.Returns the message gateway for application events.Returns the store for aggregate events.default voidExecutes the given task with this Fluxzero set as current threadlocal instance.default CompletableFuture<Void> executeModelAssertions(Message update) Executes model apply interceptors and immediate assertions without applying or committing the update.default CompletableFuture<Void> executeModelCommit(Message update) Executes one model commit without routing it through command handlers.default CompletableFuture<Void> executeModelCommit(Message update, String modelId, Class<?> modelType) Executes one model commit against an explicitly selected persisted model identity.default CompletableFuture<Void> executeModelCommits(List<Message> updates) Executes multiple independent model commits without routing them through command handlers.default CompletableFuture<Void> executeStoredModelEvent(Message event) Applies an event that was already accepted by its original command flow to independent models.static <T> TfilterContent(T value, User user) Modify given value before it's passed to the given viewer.static StringGenerates a functional ID using the currentIdentityProvider.static <T extends Id<?>>
TgenerateId(Class<T> idClass) Generates a strongly typed ID of givenidClassusing the currentIdentityProvider.static Fluxzeroget()Returns the Fluxzero instance bound to the current thread or else set by the current application.static <T> Optional<T> getDocument(Id<T> id) Fetches a document by id using the associated type to determine the collection.static <T> Optional<T> getDocument(Object id, Class<T> collection) Gets the document with given id in given collection type, returning the value.static <T> Optional<T> getDocument(Object id, Object collection) Gets the document with given id in given collection, returning the value in the type that it was stored.static <T> Optional<T> getDocument(Object id, Object collection, Class<T> type) Gets the document with given id in given collection, converting the matching document to a value with given type.static <T> Collection<T> getDocuments(Collection<?> ids, Class<T> collection) Gets a collection of documents by their IDs from the given collection type.static <T> Collection<T> getDocuments(Collection<?> ids, Object collection) Gets a collection of documents by their IDs from the given collection and deserializes them into the stored type.static <T> Collection<T> getDocuments(Collection<?> ids, Object collection, Class<T> type) Gets a collection of documents by their IDs, converting the matching documents to value with the given type.static <K,V> V getGloballyMemoized(K key) Returns the memoized value for the given key in the global scope of the current Fluxzero instance.static <K,V> V getMemoized(K key) Returns the memoized value for the given key in the scope of the current calling class.Returns the Fluxzero client bound to the current thread or else set by the current application as Optional.static booleanhasDocument(Id<?> id) Checks whether a document exists for the given identifier and its associated type.static booleanhasDocument(Object id, Object collection) Checks if a document exists in the specified collection.Returns the factory used by Fluxzero to generate identifiers.static StringGenerates an ID derived from the givennameusing the currentIdentityProvider.static CompletableFuture<Void> Index given object for search.static CompletableFuture<Void> Index given object for search.static CompletableFuture<Void> Index given object for search.static CompletableFuture<Void> Index given object for search.static CompletableFuture<Void> Index given object for search.static <T> CompletableFuture<Void> index(Collection<? extends T> objects, Object collection, Function<? super T, String> idFunction, Function<? super T, Instant> timestampFunction, Function<? super T, Instant> endFunction) Index given objects for search.Returns a client for the key value service offered by Fluxzero.static <T> Entity<T> loadAggregate(Id<T> aggregateId) Loads the aggregate root of type<T>with given aggregateId.static <T> Entity<T> loadAggregate(Object aggregateId) Loads the aggregate root with the given aggregateId.static <T> Entity<T> loadAggregate(Object aggregateId, Class<T> aggregateType) Loads the aggregate root of type<T>with given aggregateId.static <T> Entity<T> loadAggregateFor(Object entityId) Loads the aggregate root that currently contains the entity with given entityId.static <T> Entity<T> loadAggregateFor(Object entityId, Class<?> defaultType) Loads the aggregate root of type<T>that currently contains the entity with given entityId.static <T> Graph<T> loadCurrentGraph(Id<T> modelId) Loads the latest state of the independently stored model identified by the typed ID as a relationship graph.static <T> Graph<T> loadCurrentGraph(Object modelId, Class<T> modelType) Loads the latest state of an independently stored model as a relationship graph, without inheriting an event or notification handler's historical read boundary.static <T> ModelState<T> loadCurrentModelState(Id<T> modelId) Reads a current document-backed Model using its typed identity.static <T> ModelState<T> loadCurrentModelState(String modelId, Class<T> modelType) Reads a verified current Model document without replaying historical events.static <T> Entity<T> loadEntity(Id<T> entityId) Loads the entity with given id.static <T> Entity<T> loadEntity(Object entityId) Loads the entity with given id.static <T> Entity<T> loadEntity(Object entityId, Class<T> entityType) Loads an entity by functional ID and expected type.static <T> TloadEntityValue(Id<T> entityId) Loads the current entity value for given entity id.static <T> TloadEntityValue(Object entityId) Loads the current entity value for given entity id.static <T> TloadEntityValue(Object entityId, Class<T> entityType) Loads an entity value by functional ID and expected type.static <T> Graph<T> Lazily loads the independently stored model identified by the typed ID as a relationship graph.static Graph<?> Loads a model whose concrete type is resolved from storage as a lazy relationship graph.static <T> Graph<T> Lazily loads a parent-scoped model by functional child ID and explicit parent type as a relationship graph.static <T> Graph<T> Lazily loads an independently stored model by ID and expected type as a relationship graph.static <T> Graph<T> loadGraphAt(Id<T> modelId, long stateIndex) Reconstructs a complete historical graph at the requested durable model-state boundary.static <T> Entity<T> Loads the independently stored model identified by the given typed ID.static <T> Entity<T> Loads an independently stored model by ID.static <T> Entity<T> Loads a parent-scoped model by functional child ID and explicit parent type.static <T> Entity<T> Loads an independently stored model by ID and expected type.loadModels(List<?> modelIds, Class<T> modelType) Loads several independently stored models at one coherent state boundary.Returns the memoization store of this Fluxzero instance.static voidStores the given value in a memoization store that is scoped to the current Fluxzero instance and the calling class.static voidStores the given value in a memoization store that is scoped to the current Fluxzero instance and the calling class, evicting it after the given lifespan.static <K,V> V memoize(K key, BiFunction<K, V, V> supplier) Computes and stores a memoized value in a scope bound to the current Fluxzero instance and the calling class.static <K,V> V memoize(K key, BiFunction<K, V, V> supplier, Duration lifespan) Computes and stores a memoized value in a scope bound to the current Fluxzero instance and the calling class, evicting it after the given lifespan.static voidmemoizeGlobally(Object key, Object value) Stores the given value in a memoization store that is scoped only to the current Fluxzero instance.static voidmemoizeGlobally(Object key, Object value, Duration lifespan) Stores the given value in a memoization store that is scoped only to the current Fluxzero instance, evicting it after the given lifespan.static <K,V> V memoizeGlobally(K key, BiFunction<K, V, V> supplier) Computes and stores a memoized value in a scope bound only to the current Fluxzero instance.static <K,V> V memoizeGlobally(K key, BiFunction<K, V, V> supplier, Duration lifespan) Computes and stores a memoized value in a scope bound only to the current Fluxzero instance, evicting it after the given lifespan.static <K,V> V memoizeGloballyIfAbsent(K key, Function<K, V> supplier) Returns the memoized value for the given key in the global scope of the current Fluxzero instance, computing it only when absent or expired.static <K,V> V memoizeGloballyIfAbsent(K key, Function<K, V> supplier, Duration lifespan) Returns the memoized value for the given key in the global scope of the current Fluxzero instance, computing it only when absent or expired and evicting it after the given lifespan.static <K,V> V memoizeIfAbsent(K key, Function<K, V> supplier) Returns the memoized value for the given key in the scope of the current calling class, computing it only when absent or expired.static <K,V> V memoizeIfAbsent(K key, Function<K, V> supplier, Duration lifespan) Returns the memoized value for the given key in the scope of the current calling class, computing it only when absent or expired and evicting it after the given lifespan.Returns the gateway to schedule messages.Returns the gateway for metrics events.default ModelRepositoryReturns the repository for independently stored models.static IndexOperationprepareIndex(@NonNull Object object) Prepare given object for indexing for search.io.fluxzero.common.application.PropertySourceReturns thePropertySourceconfigured for this Fluxzero instance.static voidpublishEvent(Object event) Publishes the given application event.static voidpublishEvent(Object payload, io.fluxzero.common.api.Metadata metadata) Publishes an event with given payload and metadata.static voidpublishEvents(Object... events) Publishes given application events.static voidpublishMetrics(Object metrics) Publishes a metrics event.static voidpublishMetrics(Object payload, io.fluxzero.common.api.Metadata metadata) Publishes a metrics event with given payload and metadata.static <R> CompletableFuture<R> Sends the given query and returns a future that will be completed with the query's result.static <R> CompletableFuture<R> Sends a query with given payload and metadata and returns a future that will be completed with the query's result.static <R> CompletableFuture<R> Sends the given query and returns a future that will be completed with the query's result.static <R> CompletableFuture<R> Sends a query with given payload and metadata and returns a future that will be completed with the query's result.static <R> RqueryAndWait(Request<R> query) Sends the given query and returns the query's result.static <R> RqueryAndWait(Request<R> payload, io.fluxzero.common.api.Metadata metadata) Sends a query with given payload and metadata and returns the query's result.static <R> RqueryAndWait(Object query) Sends the given query and returns the query's result.static <R> RqueryAndWait(Object payload, io.fluxzero.common.api.Metadata metadata) Sends a query with given payload and metadata and returns the query's result.Returns the gateway for query messages.default io.fluxzero.common.RegistrationregisterHandlers(Object... handlers) Registers given handlers and initiates message tracking (i.e. listening for messages).default io.fluxzero.common.RegistrationregisterHandlers(List<?> handlers) Registers given handlers and initiates message tracking.Returns the gateway for result messages sent by handlers of commands and queries.static voidSchedule a message object (of typeSchedule) for execution, using theGuarantee.SENTguarantee.static voidSchedule a message object (of typeSchedule) for execution, using theGuarantee.SENTguarantee.static voidSchedules a message with givenscheduleIdafter given delay.static voidSchedules a message with givenscheduleIdfor the given timestamp.static StringSchedules a message after the given delay, returning the schedule's id.static StringSchedules a message for the given timestamp, returning the schedule's id.static voidscheduleCommand(Schedule message) Schedule a command using the given scheduling settings, using theGuarantee.SENTguarantee.static voidscheduleCommand(Schedule message, boolean ifAbsent) Schedule a command using the given scheduling settings if no other with same ID exists, using theGuarantee.SENTguarantee.static voidscheduleCommand(Object command, Object scheduleId, Duration delay) Schedules a command with givenscheduleIdafter given delay.static voidscheduleCommand(Object command, Object scheduleId, Instant deadline) Schedules a command with givenscheduleIdfor the given timestamp.static StringscheduleCommand(Object command, Duration delay) Schedules a command after given delay, returning the command schedule's id.static StringscheduleCommand(Object command, Instant deadline) Schedules a command for the given timestamp, returning the command schedule's id.static StringschedulePeriodic(Object schedule) Starts a new periodic schedule, returning the schedule's id.static voidschedulePeriodic(Object schedule, Object scheduleId) Starts a new periodic schedule using given schedule id.static <T> Search<T> search(io.fluxzero.common.api.search.SearchQuery.Builder queryBuilder) Search documents using given reusable query builder.static <T> Search<T> Search the collection represented by the given document class and retain that class as the default result type.static <T> Search<T> Search the collections represented by the given document class and additional collection identifiers while retaining the document class as the default result type.static <T> Search<T> Search the given collection for documents.static <T> Search<T> Search the given collections for documents.searchGraph(Class<T> rootModelType) Searches complete graph views for an independent model root.searchGraph(Class<T> rootModelType, boolean forceAdHoc) Searches complete graph views for an independent model root.static voidsendAndForgetCommand(Object command) Sends the given command and doesn't wait for a result.static voidsendAndForgetCommand(Object payload, io.fluxzero.common.api.Metadata metadata) Sends a command with given payload and metadata and don't wait for a result.static voidsendAndForgetCommand(Object payload, io.fluxzero.common.api.Metadata metadata, io.fluxzero.common.Guarantee guarantee) Sends a command with given payload and metadata and don't wait for a result.static voidsendAndForgetCommands(Object... commands) Sends the given commands and doesn't wait for results.static <R> CompletableFuture<R> sendCommand(Request<R> command) Sends the given command and returns a future that will be completed with the command's result.static <R> CompletableFuture<R> sendCommand(Request<R> payload, io.fluxzero.common.api.Metadata metadata) Sends a command with given payload and metadata and returns a future that will be completed with the command's result.static <R> CompletableFuture<R> sendCommand(Object command) Sends the given command and returns a future that will be completed with the command's result.static <R> CompletableFuture<R> sendCommand(Object payload, io.fluxzero.common.api.Metadata metadata) Sends a command with given payload and metadata and returns a future that will be completed with the command's result.static <R> RsendCommandAndWait(Request<R> command) Sends the given command and returns the command's result.static <R> RsendCommandAndWait(Request<R> payload, io.fluxzero.common.api.Metadata metadata) Sends a command with given payload and metadata and returns a future that will be completed with the command's result.static <R> RsendCommandAndWait(Object command) Sends the given command and returns the command's result.static <R> RsendCommandAndWait(Object payload, io.fluxzero.common.api.Metadata metadata) Sends a command with given payload and metadata and returns a future that will be completed with the command's result.static <R> List<CompletableFuture<R>> sendCommands(Object... commands) Sends the given commands and returns a list of futures that will be completed with the commands' results.static CompletableFuture<WebResponse> sendWebRequest(WebRequest request) Sends the given web request using default request settings and returns a future that completes with the response.static CompletableFuture<WebResponse> sendWebRequest(WebRequest request, WebRequestSettings settings) Sends the given web request using the given request settings and returns a future that completes with the response.static WebResponsesendWebRequestAndWait(WebRequest request) Sends the given web request using default request settings and waits for the response synchronously.static WebResponsesendWebRequestAndWait(WebRequest request, WebRequestSettings settings) Sends the given web request using given request settings and waits for the response synchronously.Returns the default serializerReturns the store for aggregate snapshots.io.fluxzero.common.TaskSchedulerReturns theTaskSchedulerof this Fluxzero instance.tracking(io.fluxzero.common.MessageType messageType) Returns a client to assist with the tracking of a given message type.Returns the UserProvider used by Fluxzero to authenticate users.Returns the gateway for sending web requests.voidHave Fluxzero use the given Clock when generating timestamps, e.g. when creating aMessage.
-
Field Details
-
applicationInstance
Fluxzero instance set by the current application. Used as a fallback when no threadlocal instance was set. This is added as a convenience for applications that never have more than one than Fluxzero instance which will be the case for nearly all applications. On application startup simply fill this application instance. -
instance
Thread-local binding of the currentFluxzeroinstance.This is automatically set during message processing to ensure that handlers can invoke commands, queries, or schedule events without explicitly injecting dependencies.
Example: Inside a
@HandleCommandmethod, you can callFluxzero.sendCommand(...)and it will automatically use the correct instance, without needing manual wiring.
-
-
Method Details
-
get
Returns the Fluxzero instance bound to the current thread or else set by the current application. Throws an exception if no instance was registered. -
getOptionally
-
currentClock
Gets the clock of the current Fluxzero instance (obtained viagetOptionally()). If there is no current instance the system's UTC clock is returned. -
currentTime
Gets the time according to the current Fluxzero clock (obtained viacurrentClock()). If there is no current Fluxzero instance the system's UTC time is returned. -
memoize
-
memoize
-
memoizeGlobally
-
memoizeGlobally
-
memoize
Computes and stores a memoized value in a scope bound to the current Fluxzero instance and the calling class. -
memoize
Computes and stores a memoized value in a scope bound to the current Fluxzero instance and the calling class, evicting it after the given lifespan. -
memoizeGlobally
Computes and stores a memoized value in a scope bound only to the current Fluxzero instance. -
memoizeGlobally
Computes and stores a memoized value in a scope bound only to the current Fluxzero instance, evicting it after the given lifespan. -
memoizeIfAbsent
Returns the memoized value for the given key in the scope of the current calling class, computing it only when absent or expired. -
memoizeIfAbsent
-
memoizeGloballyIfAbsent
Returns the memoized value for the given key in the global scope of the current Fluxzero instance, computing it only when absent or expired. -
memoizeGloballyIfAbsent
-
getMemoized
static <K,V> V getMemoized(K key) Returns the memoized value for the given key in the scope of the current calling class. -
getGloballyMemoized
static <K,V> V getGloballyMemoized(K key) Returns the memoized value for the given key in the global scope of the current Fluxzero instance. -
generateId
Generates a functional ID using the currentIdentityProvider. This is typically used for application-level entities such as aggregates or user-defined messages.- Returns:
- a unique, traceable identifier string
-
generateId
Generates a strongly typed ID of givenidClassusing the currentIdentityProvider.- Returns:
- a unique, traceable typed identifier
-
idForName
Generates an ID derived from the givennameusing the currentIdentityProvider.For a given name, this method always returns the same identifier.
- Parameters:
name- the name to derive the identifier from- Returns:
- a unique, traceable identifier string
-
currentIdentityProvider
Fetches the configured identity provider used for both functional and technical IDs. The default is aUuidFactorythat generates UUIDs.If there is no current Fluxzero instance, a new UUID factory is generated.
-
currentCorrelationData
-
publishEvent
Publishes the given application event. The event may be an instance of aMessagein which case it will be published as is. Otherwise the event is published using the passed value as payload without additional metadata.Note: These events are not persisted for event sourcing. To publish domain events as part of an aggregate lifecycle, apply the events using
Entity.apply(Object...)after loading an entity.- See Also:
-
publishEvent
Publishes an event with given payload and metadata.Note: These events are not persisted for event sourcing. To publish domain events as part of an aggregate lifecycle, apply the events using
Entity.apply(Object...)after loading an entity.- See Also:
-
publishEvents
Publishes given application events. The events may be instances ofMessagein which case they will be published as is. Otherwise, the events are published using the passed value as payload without additional metadata.Note: These events are not persisted for event sourcing. To publish domain events as part of an aggregate lifecycle, apply the events using
Entity.apply(Object...)after loading an entity.- See Also:
-
sendAndForgetCommand
-
sendAndForgetCommands
-
sendAndForgetCommand
Sends a command with given payload and metadata and don't wait for a result.- See Also:
-
sendAndForgetCommand
static void sendAndForgetCommand(Object payload, io.fluxzero.common.api.Metadata metadata, io.fluxzero.common.Guarantee guarantee) Sends a command with given payload and metadata and don't wait for a result. With a guarantee the method will wait for the command itself to be sent or stored.- See Also:
-
sendCommand
Sends the given command and returns a future that will be completed with the command's result. The command may be an instance of aMessagein which case it will be sent as is. Otherwise the command is published using the passed value as payload without additional metadata. -
sendCommand
Sends the given command and returns a future that will be completed with the command's result. The command may be an instance of aMessagein which case it will be sent as is. Otherwise the command is published using the passed value as payload without additional metadata.The return type is determined by the given command.
-
sendCommands
Sends the given commands and returns a list of futures that will be completed with the commands' results. The commands may be instances of aMessagein which case they will be sent as is. Otherwise, the commands are published using the passed values as payload without additional metadata. -
sendCommand
static <R> CompletableFuture<R> sendCommand(Object payload, io.fluxzero.common.api.Metadata metadata) Sends a command with given payload and metadata and returns a future that will be completed with the command's result. -
sendCommand
static <R> CompletableFuture<R> sendCommand(Request<R> payload, io.fluxzero.common.api.Metadata metadata) Sends a command with given payload and metadata and returns a future that will be completed with the command's result.The return type is determined by the given command.
-
sendCommandAndWait
-
sendCommandAndWait
Sends the given command and returns the command's result. The command may be an instance of aMessagein which case it will be sent as is. Otherwise, the command is published using the passed value as payload without additional metadata.The return type is determined by the given command.
-
sendCommandAndWait
Sends a command with given payload and metadata and returns a future that will be completed with the command's result. -
sendCommandAndWait
Sends a command with given payload and metadata and returns a future that will be completed with the command's result.The return type is determined by the given command.
-
assertLegal
Runs apply interceptors and immediate model assertions declared for the given update without invoking applies or committing model changes.Assertions marked with
AssertLegal.afterHandler()are not invoked because this validation-only operation does not produce a post-apply model state. This enters the model pipeline directly and does not dispatch the update as a command.- Parameters:
update- the update payload or message to validate
-
assertLegal
Runs apply interceptors and immediate model assertions with the supplied metadata, without invoking applies or committing model changes.- Parameters:
update- the update payload to validatemetadata- metadata available to interceptors and assertions
-
assertAndApply
Runs the model assertions, apply interceptors, and applies declared for the given update and waits until the resulting model commit has been committed. If this application has no locally reachable model apply, immediate assertions and apply interceptors still run, after which the call logs a warning and returns without committing.This enters the model-commit pipeline directly. It does not dispatch the update as a command and therefore can safely be called from an explicit
HandleCommandhandler for the same payload type.- Parameters:
update- the update payload or message to assert and apply
-
assertAndApply
Runs and commits a model commit with the supplied metadata.- Parameters:
update- the update payload to assert and applymetadata- metadata to attach to the model event
-
commit
Commits Model changes already produced in the current handling context without waiting for its normal automatic commit boundary.This is an optional early flush of the existing Model commit, not a separate mutation or commit path. The returned future is the existing durable commit completion and therefore carries the same success or failure. Required predecessor commits are also released and flushed, so their ordinary batch boundary cannot prevent the current commit from completing. Independent deferred commits keep their normal commit boundary. When the current context has no pending Model changes, the method returns an already completed future and sends nothing to the Runtime. Automatic committing remains active and observes the same completion.
- Returns:
- completion of the current durable Model commit, or completed completion when no changes are pending
-
assertAndApply
Runs and commits an update against the explicitly selected model graph, independently of any model ID carried by the update payload. Interceptors, assertions, applies, event publication, conflict handling and commit guarantees are otherwise identical toassertAndApply(Object).Prefer
Graph.assertAndApply(Object)in application code. This overload owns the direct model-pipeline bridge used by that convenience.- Parameters:
target- explicitly selected model graphupdate- update payload or message to assert and apply- Returns:
- the freshly loaded graph after the durable commit
-
assertAndApply
-
assertAndApplyAsync
Runs the model assertions, apply interceptors, and applies declared for the given update without blocking the caller, and completes after the resulting model commit has been durably stored.The update is converted to a message before this method returns, so metadata and context inherited from the current handler remain available to the asynchronous commit pipeline.
- Parameters:
update- the update payload or message to assert and apply- Returns:
- completion of the durable model commit
-
assertAndApplyAsync
static CompletableFuture<Void> assertAndApplyAsync(Object update, io.fluxzero.common.api.Metadata metadata) Runs and commits a model commit asynchronously with the supplied metadata.- Parameters:
update- the update payload to assert and applymetadata- metadata to attach to the model event- Returns:
- completion of the durable model commit
-
assertAndApplyAllAsync
Runs and commits multiple independent model updates asynchronously. Every update remains a separate model commit with its own conflict handling and durability boundary. Implementations may batch commits that become ready together for transport, without making the updates atomic or delaying already-full transport batches.All updates are converted to messages before this method returns, so metadata and context inherited from the current handler remain available to every asynchronous commit pipeline.
- Parameters:
updates- independent update payloads or messages to assert and apply- Returns:
- completion after every resulting model commit has been durably stored
-
query
Sends the given query and returns a future that will be completed with the query's result. The query may be an instance of aMessagein which case it will be sent as is. Otherwise, the query is published using the passed value as payload without additional metadata. -
query
Sends the given query and returns a future that will be completed with the query's result. The query may be an instance of aMessagein which case it will be sent as is. Otherwise, the query is published using the passed value as payload without additional metadata.The return type is determined by the given query.
-
query
Sends a query with given payload and metadata and returns a future that will be completed with the query's result. -
query
Sends a query with given payload and metadata and returns a future that will be completed with the query's result.The return type is determined by the given query.
-
queryAndWait
-
queryAndWait
Sends the given query and returns the query's result. The query may be an instance of aMessagein which case it will be sent as is. Otherwise, the query is published using the passed value as payload without additional metadata.The return type is determined by the given query.
-
queryAndWait
Sends a query with given payload and metadata and returns the query's result. -
queryAndWait
Sends a query with given payload and metadata and returns the query's result.The return type is determined by the given query.
-
schedulePeriodic
Starts a new periodic schedule, returning the schedule's id. Thescheduleparameter may be an instance of aMessageor the schedule payload. If the payload is not annotated withPeriodicanIllegalArgumentExceptionis thrown.- See Also:
-
schedulePeriodic
Starts a new periodic schedule using given schedule id. Thescheduleparameter may be an instance of aMessageor the schedule payload. If the payload is not annotated withPeriodicanIllegalArgumentExceptionis thrown.- See Also:
-
schedule
Schedules a message for the given timestamp, returning the schedule's id. Thescheduleparameter may be an instance of aMessagein which case it will be scheduled as is. Otherwise, the schedule is published using the passed value as payload without additional metadata. -
schedule
Schedules a message with givenscheduleIdfor the given timestamp. Thescheduleparameter may be an instance of aMessagein which case it will be scheduled as is. Otherwise, the schedule is published using the passed value as payload without additional metadata. -
schedule
Schedules a message after the given delay, returning the schedule's id. Thescheduleparameter may be an instance of aMessagein which case it will be scheduled as is. Otherwise, the schedule is published using the passed value as payload without additional metadata. -
schedule
Schedules a message with givenscheduleIdafter given delay. Thescheduleparameter may be an instance of aMessagein which case it will be scheduled as is. Otherwise, the schedule is published using the passed value as payload without additional metadata. -
schedule
-
schedule
-
scheduleCommand
Schedules a command for the given timestamp, returning the command schedule's id. Thecommandparameter may be an instance of aMessagein which case it will be scheduled as is. Otherwise, the command is scheduled using the passed value as payload without additional metadata. -
scheduleCommand
Schedules a command with givenscheduleIdfor the given timestamp. Thecommandparameter may be an instance of aMessagein which case it will be scheduled as is. Otherwise, the command is published using the passed value as payload without additional metadata. -
scheduleCommand
Schedules a command after given delay, returning the command schedule's id. Thecommandparameter may be an instance of aMessagein which case it will be scheduled as is. Otherwise, the command is scheduled using the passed value as payload without additional metadata. -
scheduleCommand
Schedules a command with givenscheduleIdafter given delay. Thecommandparameter may be an instance of aMessagein which case it will be scheduled as is. Otherwise, the command is published using the passed value as payload without additional metadata. -
scheduleCommand
Schedule a command using the given scheduling settings, using theGuarantee.SENTguarantee. -
scheduleCommand
Schedule a command using the given scheduling settings if no other with same ID exists, using theGuarantee.SENTguarantee. -
cancelSchedule
Cancels the schedule with givenscheduleId. -
sendWebRequest
Sends the given web request using default request settings and returns a future that completes with the response.Proxy and native HTTP execution require an absolute URL; relative URLs may be handled by a local web handler.
-
sendWebRequest
static CompletableFuture<WebResponse> sendWebRequest(WebRequest request, WebRequestSettings settings) Sends the given web request using the given request settings and returns a future that completes with the response.Proxy and native HTTP execution require an absolute URL; relative URLs may be handled by a local web handler.
-
sendWebRequestAndWait
Sends the given web request using default request settings and waits for the response synchronously.This method blocks the calling thread until the request is completed or times out.
Proxy and native HTTP execution require an absolute URL; relative URLs may be handled by a local web handler.
-
sendWebRequestAndWait
Sends the given web request using given request settings and waits for the response synchronously.This method blocks the calling thread until the request is completed or times out.
Proxy and native HTTP execution require an absolute URL; relative URLs may be handled by a local web handler.
-
publishMetrics
Publishes a metrics event. The parameter may be an instance of aMessagein which case it will be sent as is. Otherwise the metrics event is published using the passed value as payload without additional metadata.Metrics events can be published in any form to log custom performance metrics about an application.
-
publishMetrics
Publishes a metrics event with given payload and metadata. Metrics events can be published in any form to log custom performance metrics about an application. -
loadAggregate
Loads the aggregate root of type<T>with given aggregateId.If the aggregate is loaded while handling an event of the aggregate, the returned Aggregate will automatically be played back to the event currently being handled. Otherwise, the most recent state of the aggregate is loaded. Typed identifiers whose declared type is an independent
Modelare delegated to the model repository. This preserves source-compatible typed loads while migrating an aggregate root to an independent model.- See Also:
-
loadAggregate
Loads the aggregate root with the given aggregateId. If the aggregate exists, it will be loaded and returned with its respective type, if not, an emptyEntityof typeObjectwill be returned.If the aggregate is loaded while handling an event of the aggregate, the returned Aggregate will automatically be played back to the event currently being handled. Otherwise, the most recent state of the aggregate is loaded.
- See Also:
-
loadAggregate
Loads the aggregate root of type<T>with given aggregateId.If the aggregate is loaded while handling an event of the aggregate, the returned Aggregate will automatically be played back to the event currently being handled. Otherwise, the most recent state of the aggregate is loaded.
- See Also:
-
loadModel
-
loadModel
-
loadModel
-
loadModel
-
loadCurrentModelState
Reads a verified current Model document without replaying historical events. The exact persisted identity is required. The read-only result does not inherit a handler boundary or become a transaction read dependency. Missing/deleted state is distinct from an unavailable/stale document, which fails explicitly.- See Also:
-
loadCurrentModelState
Reads a current document-backed Model using its typed identity. -
loadGraph
Lazily loads the independently stored model identified by the typed ID as a relationship graph.The source model is loaded only when its value, history or relationship contents are requested. A typed ancestor lookup can normally resolve directly from stored relationship identities.
-
loadGraph
Loads a model whose concrete type is resolved from storage as a lazy relationship graph. The default repository discovers its type from the head and pins the boundary during this call, without replaying the root value. The root Model contract must be locally known. Custom repositories may retain value-based discovery. -
loadGraph
-
loadCurrentGraph
Loads the latest state of an independently stored model as a relationship graph, without inheriting an event or notification handler's historical read boundary. The default repository pins the current head during this call and defers authoritative value reconstruction until needed. This is not the document-onlyloadCurrentModelState(String, Class)read contract.Use this after a synchronous nested command when the remainder of the handler deliberately needs that command's updated Model state. Ordinary
loadGraph(Object, Class)reads remain coherent with the message being handled and are therefore preferred everywhere else. -
loadCurrentGraph
-
loadGraph
-
loadGraphAt
-
loadModels
-
loadAggregateFor
Loads the aggregate root of type<T>that currently contains the entity with given entityId. If no such aggregate exists an empty aggregate root is returned with givendefaultTypeas its type.This method can also be used if the entity is the aggregate root (aggregateId is equal to entityId). If the entity is associated with more than one aggregate the behavior of this method is unpredictable, though the default behavior is that any one of the associated aggregates is returned.
If the aggregate is loaded while handling an event of the aggregate, the returned Aggregate will automatically be played back to the event currently being handled. Otherwise, the most recent state of the aggregate is loaded.
- See Also:
-
loadAggregateFor
Loads the aggregate root that currently contains the entity with given entityId. If no such aggregate exists an empty aggregate root is returned of typeObject. In that case be aware that applying events to create the aggregate may yield an undesired result; to prevent this useloadAggregateFor(Object, Class).This method can also be used if the entity is the aggregate root (aggregateId is equal to entityId). If the entity is associated with more than one aggregate the behavior of this method is unpredictable, though the default behavior is that any one of the associated aggregates is returned.
If the aggregate is loaded while handling an event of the aggregate, the returned Aggregate will automatically be played back to the event currently being handled. Otherwise, the most recent state of the aggregate is loaded.
- See Also:
-
loadEntity
Loads the entity with given id. If the entity is not associated with any aggregate yet, a new aggregate root is loaded with the entityId as aggregate identifier. In case multiple entities are associated with the given entityId the most recent entity is returned.If the entity is loaded while handling an event its aggregate, the returned entity will automatically be played back to the event currently being handled. Otherwise, the most recent state of the entity is loaded.
-
loadEntity
Loads the entity with given id. If the entity is not associated with any aggregate yet, a new aggregate root is loaded with the entityId as aggregate identifier. In case multiple entities are associated with the given entityId the most recent entity is returned.If the entity is loaded while handling an event its aggregate, the returned entity will automatically be played back to the event currently being handled. Otherwise, the most recent state of the entity is loaded.
-
loadEntity
-
loadEntityValue
Loads the current entity value for given entity id. Entity may be the aggregate root or any ancestral entity. If no such entity exists or its value is not setnullis returned.If the entity is loaded while handling an event its aggregate, the returned entity will automatically be played back to the event currently being handled. Otherwise, the most recent state of the entity is loaded.
-
loadEntityValue
Loads the current entity value for given entity id. Entity may be the aggregate root or any ancestral entity. If no such entity exists or its value is not setnullis returned.If the entity is loaded while handling an event its aggregate, the returned entity will automatically be played back to the event currently being handled. Otherwise, the most recent state of the entity is loaded.
-
loadEntityValue
-
asEntity
Returns an Entity containing given value. The returned entity won't exhibit any side effects when they are updated, i.e. they won't be synced to any repository or give rise to any events. Other than, that they are fully functional. -
prepareIndex
Prepare given object for indexing for search. This returns a mutable builder that allows defining an id, collection, etc.If the object is annotated with
@Searchablethe collection name and any timestamp or end path defined there will be used.If the object has a property annotated with
EntityId, it will be used as the id of the document. Otherwise, a random id will be assigned to the document.This method returns once the object is stored.
- See Also:
-
index
Index given object for search.If the object is annotated with
@Searchablethe collection name and any timestamp or end path defined there will be used.If the object has a property annotated with
EntityId, it will be used as the id of the document. Otherwise, a random id will be assigned to the document.This method returns once the object is stored.
- See Also:
-
index
Index given object for search.If the object has a property annotated with
EntityId, it will be used as the id of the document. Otherwise, a random id will be assigned to the document.This method returns once the object is stored.
- See Also:
-
index
Index given object for search. This method returns once the object is stored.- See Also:
-
index
-
index
-
index
static <T> CompletableFuture<Void> index(Collection<? extends T> objects, Object collection, Function<? super T, String> idFunction, Function<? super T, Instant> timestampFunction, Function<? super T, Instant> endFunction) Index given objects for search. UseidFunctionto provide the document's required id. UsetimestampFunctionandendFunctionto provide the object's timestamp. If none are supplied the document will not be timestamped.This method returns once all objects are stored.
- See Also:
-
bulkUpdate
Prepare a fluent bulk update for the given document collection.Example usage:
Fluxzero.bulkUpdate("my_collection").index(doc1).delete(doc2Id).execute();- See Also:
-
search
Search the given collection for documents. Usually collection is the String name of the collection. However, it is also possible to call it with aCollectioncontaining one or multiple collection names.If collection is of type
Classit is expected that the class is annotated withSearchable. It will then use the collection configured there.For all other inputs, the collection name will be obtained by calling
Object.toString()on the input.Example usage:
Fluxzero.<MyDocument>search("myCollection").query("foo !bar").fetch(100). -
search
-
search
-
search
Search the given collections for documents.If collection is of type
Classit is expected that the class is annotated withSearchable. It will then use the collection configured there. For all other inputs, the collection name will be obtained by callingObject.toString()on the input.Example usage: Fluxzero.search("myCollection", "myOtherCollection).query("foo !bar").fetch(100);
-
search
Search documents using given reusable query builder.Example usage: Fluxzero.search(SearchQuery.builder().search("myCollection").query("foo !bar")).fetch(100);
-
searchGraph
-
searchGraph
-
hasDocument
Checks whether a document exists for the given identifier and its associated type. The type is used to determine the document collection. -
hasDocument
-
getDocument
-
getDocument
-
getDocument
-
getDocument
-
getDocuments
Gets a collection of documents by their IDs from the given collection and deserializes them into the stored type. -
getDocuments
Gets a collection of documents by their IDs from the given collection type. -
getDocuments
Gets a collection of documents by their IDs, converting the matching documents to value with the given type. -
deleteDocument
Deletes the document with given id in given collection if it exists. -
deleteCollection
Deletes a search collection if it exists. -
filterContent
Modify given value before it's passed to the given viewer. SeeFilterContentfor info on how to filter the value. -
downcast
-
downcast
Downcasts aDataobject to the specified revision level.- Parameters:
data- the serialized datadesiredRevision- the target revision number- Returns:
- a serialized form of the object downcasted to the given revision
-
registerHandlers
Registers given handlers and initiates message tracking (i.e. listening for messages).The given handlers will be inspected for annotated handler methods (e.g. methods annotated with
HandleCommand). Depending on this inspection message tracking will commence for any handled message types. To stop listening at any time invokeRegistration.cancel()on the returned object.Note that an exception may be thrown if tracking for a given message type is already in progress.
If any of the handlers is a local handler or contains local handler methods, i.e. if type or method is annotated with
LocalHandler, the target object will (also) be registered as local handler. Local handlers will handle messages in the publishing thread. If a published message can be handled locally it will not be published to the Fluxzero Runtime. Local handling of messages may come in handy in several situations: e.g. when the message is expressly meant to be handled only by the current application or if the message needs to be handled as quickly as possible. However, in most cases it will not be necessary to register local handlers.Note that it will generally not be necessary to invoke this method manually if you use Spring to configure your application.
- See Also:
-
registerHandlers
Registers given handlers and initiates message tracking.- See Also:
-
withClock
-
aggregateRepository
AggregateRepository aggregateRepository()Returns a client to assist with event sourcing. -
modelRepository
Returns the repository for independently stored models.The default keeps existing custom
Fluxzeroimplementations binary/source compatible while the model action transport is introduced. Standard runtime-backed configurations override this when that transport is available. -
eventStore
EventStore eventStore()Returns the store for aggregate events. -
snapshotStore
SnapshotStore snapshotStore()Returns the store for aggregate snapshots. -
messageScheduler
-
commandGateway
CommandGateway commandGateway()Returns the gateway for command messages. -
queryGateway
QueryGateway queryGateway()Returns the gateway for query messages. -
eventGateway
EventGateway eventGateway()Returns the message gateway for application events. UseaggregateRepository()to publish events belonging to an aggregate. -
resultGateway
ResultGateway resultGateway()Returns the gateway for result messages sent by handlers of commands and queries. -
errorGateway
ErrorGateway errorGateway()Returns the gateway for any error messages published while handling a command or query. -
metricsGateway
MetricsGateway metricsGateway()Returns the gateway for metrics events. Metrics events can be published in any form to log custom performance metrics about an application. -
webRequestGateway
WebRequestGateway webRequestGateway()Returns the gateway for sending web requests. -
customGateway
Returns the gateway for given custom message topic. -
tracking
Returns a client to assist with the tracking of a given message type. -
keyValueStore
KeyValueStore keyValueStore()Returns a client for the key value service offered by Fluxzero. -
documentStore
DocumentStore documentStore()Returns a client for the document search service offered by Fluxzero. -
userProvider
UserProvider userProvider()Returns the UserProvider used by Fluxzero to authenticate users. May benullif user authentication is disabled. -
cache
io.fluxzero.common.caching.Cache cache()Returns the cache used by the client to cache aggregates etc. -
correlationDataProvider
CorrelationDataProvider correlationDataProvider()Returns the provider of correlation data for published messages. -
serializer
Serializer serializer()Returns the default serializer -
clock
Clock clock()Returns the clock used by Fluxzero to generate timestamps. -
identityProvider
IdentityProvider identityProvider()Returns the factory used by Fluxzero to generate identifiers. -
propertySource
io.fluxzero.common.application.PropertySource propertySource()Returns thePropertySourceconfigured for this Fluxzero instance. -
taskScheduler
io.fluxzero.common.TaskScheduler taskScheduler()Returns theTaskSchedulerof this Fluxzero instance. -
memoization
Memoization memoization()Returns the memoization store of this Fluxzero instance. -
configuration
FluxzeroConfiguration configuration()Returns theFluxzeroConfigurationof this Fluxzero instance. -
executeModelCommit
Executes one model commit without routing it through command handlers.This is an infrastructure extension point used by
assertAndApply(Object). Custom Fluxzero implementations that support independent models should override it.- Parameters:
update- message containing the model update- Returns:
- completion of the durable model commit
-
commitModelChanges
Flushes Model changes already attached to the current handling context. This extension point backscommit()and may be overridden by custom Fluxzero implementations with a different Model pipeline. -
executeModelCommit
default CompletableFuture<Void> executeModelCommit(Message update, String modelId, Class<?> modelType) Executes one model commit against an explicitly selected persisted model identity. This is the infrastructure extension used byGraph.assertAndApply(Object); custom implementations supporting independent models may override it alongsideexecuteModelCommit(Message). -
executeModelCommits
Executes multiple independent model commits without routing them through command handlers. The default implementation preserves compatibility for custom implementations by invokingexecuteModelCommit(Message)for every update. Implementations may override this to batch transport while retaining separate commit semantics.- Parameters:
updates- messages containing independent model updates- Returns:
- completion after every durable model commit
-
executeStoredModelEvent
Applies an event that was already accepted by its original command flow to independent models. Assertions and apply interceptors are skipped, while regular@Applymethods and durable Model-event storage are preserved. The accepted event is not published again. This infrastructure hook is primarily used by replay and test fixtures.- Parameters:
event- previously accepted event to apply- Returns:
- completion of the durable model commit
-
executeModelAssertions
Executes model apply interceptors and immediate assertions without applying or committing the update.This is an infrastructure extension point used by
assertLegal(Object). Custom Fluxzero implementations that support independent models should override it.- Parameters:
update- message containing the model update to validate- Returns:
- completion of the validation-only model evaluation
-
client
Client client()Returns the low level client used by this Fluxzero instance to interface with the Fluxzero Runtime. Of course the returned client may also be a stand-in for the actual service. -
apply
Applies the given function with this Fluxzero set as current threadlocal instance. -
execute
Executes the given task with this Fluxzero set as current threadlocal instance. -
beforeShutdown
Register a task to run before this Fluxzero instance is closed. -
close
default void close()Closes this Fluxzero instance gracefully.- Specified by:
closein interfaceAutoCloseable
-
close
void close(boolean silently) Closes this Fluxzero instance gracefully. If silently is true, shutdown is done without logging.
-