Interface FluxCapacitor
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultFluxCapacitor
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 aggregates, use
loadAggregate(Id)
oraggregateRepository()
.
Most applications will never need to hold or inject a FluxCapacitor
instance directly.
Instead, the platform automatically binds the relevant instance to a thread-local scope, allowing access via static methods.
A concrete instance is typically constructed using DefaultFluxCapacitor
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AtomicReference
<FluxCapacitor> Flux Capacitor instance set by the current application.static final ThreadLocal
<FluxCapacitor> Thread-local binding of the currentFluxCapacitor
instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns a client to assist with event sourcing.default <R> R
apply
(ThrowingFunction<FluxCapacitor, R> function) Applies the given function with this Flux Capacitor set as current threadlocal instance.static <T> Entity
<T> asEntity
(T value) Returns an Entity containing given value.beforeShutdown
(Runnable task) Register a task to run before this Flux Capacitor instance is closed.cache()
Returns the cache used by the client to cache aggregates etc.static void
cancelSchedule
(String scheduleId) Cancels the schedule with givenscheduleId
.client()
Returns the low level client used by this FluxCapacitor instance to interface with the Flux Capacitor service.clock()
Returns the clock used by Flux Capacitor to generate timestamps.default void
close()
Closes this Flux Capacitor instance gracefully.void
close
(boolean silently) Closes this Flux Capacitor instance gracefully.Returns the gateway for command messages.Returns theFluxCapacitorConfiguration
of this FluxCapacitor instance.Returns the provider of correlation data for published messages.static Clock
Gets the clock of the current FluxCapacitor instance (obtained viagetOptionally()
).Gets the current correlation data, which by default depends on the currentClient
,Tracker
andDeserializingMessage
static IdentityProvider
Fetches the configured identity provider used for both functional and technical IDs.static Instant
Gets the time according to the current FluxCapacitor 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 Flux Capacitor.static Object
Downcasts aData
object to the specified revision level.static Object
Downcasts 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 void
execute
(ThrowingConsumer<FluxCapacitor> task) Executes the given task with this Flux Capacitor set as current threadlocal instance.static <T> T
filterContent
(T value, User user) Modify given value before it's passed to the given viewer.static String
Generates a functional ID using the currentIdentityProvider
.static <T extends Id<?>>
TgenerateId
(Class<T> idClass) Generates a strongly typed ID of givenidClass
using the currentIdentityProvider
.static FluxCapacitor
get()
Returns the Flux Capacitor instance bound to the current thread or else set by the current application.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 Optional
<FluxCapacitor> Returns the FluxCapacitor client bound to the current thread or else set by the current application as Optional.Returns the factory used by Flux Capacitor to generate identifiers.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 Flux Capacitor.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> 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> T
loadEntityValue
(Id<T> entityId) Loads the current entity value for given entity id.static <T> T
loadEntityValue
(Object entityId) Loads the current entity value for given entity id.Returns the gateway to schedule messages.Returns the gateway for metrics events.static IndexOperation
prepareIndex
(@NonNull Object object) Prepare given object for indexing for search.Returns thePropertySource
configured for this FluxCapacitor instance.static void
publishEvent
(Object event) Publishes the given application event.static void
publishEvent
(Object payload, Metadata metadata) Publishes an event with given payload and metadata.static void
publishEvents
(Object... events) Publishes given application events.static void
publishMetrics
(Object metrics) Publishes a metrics event.static void
publishMetrics
(Object payload, 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> R
queryAndWait
(Request<R> query) Sends the given query and returns the query's result.static <R> R
queryAndWait
(Request<R> payload, Metadata metadata) Sends a query with given payload and metadata and returns the query's result.static <R> R
queryAndWait
(Object query) Sends the given query and returns the query's result.static <R> R
queryAndWait
(Object payload, Metadata metadata) Sends a query with given payload and metadata and returns the query's result.Returns the gateway for query messages.default Registration
registerHandlers
(Object... handlers) Registers given handlers and initiates message tracking (i.e. listening for messages).default Registration
registerHandlers
(List<?> handlers) Registers given handlers and initiates message tracking.Returns the gateway for result messages sent by handlers of commands and queries.static void
Schedule a message object (of typeSchedule
) for execution, using theGuarantee.SENT
guarantee.static void
Schedule a message object (of typeSchedule
) for execution, using theGuarantee.SENT
guarantee.static void
Schedules a message with givenscheduleId
after given delay.static void
Schedules a message with givenscheduleId
for the given timestamp.static String
Schedules a message after the given delay, returning the schedule's id.static String
Schedules a message for the given timestamp, returning the schedule's id.static void
scheduleCommand
(Schedule message) Schedule a command using the given scheduling settings, using theGuarantee.SENT
guarantee.static void
scheduleCommand
(Schedule message, boolean ifAbsent) Schedule a command using the given scheduling settings if no other with same ID exists, using theGuarantee.SENT
guarantee.static void
scheduleCommand
(Object command, String scheduleId, Duration delay) Schedules a command with givenscheduleId
after given delay.static void
scheduleCommand
(Object command, String scheduleId, Instant deadline) Schedules a command with givenscheduleId
for the given timestamp.static String
scheduleCommand
(Object command, Duration delay) Schedules a command after given delay, returning the command schedule's id.static String
scheduleCommand
(Object command, Instant deadline) Schedules a command for the given timestamp, returning the command schedule's id.static String
schedulePeriodic
(Object schedule) Starts a new periodic schedule, returning the schedule's id.static void
schedulePeriodic
(Object schedule, String scheduleId) Starts a new periodic schedule using given schedule id.static Search
search
(SearchQuery.Builder queryBuilder) Search documents using given reusable query builder.static Search
Search the given collection for documents.static Search
Search the given collections for documents.static void
sendAndForgetCommand
(Object command) Sends the given command and doesn't wait for a result.static void
sendAndForgetCommand
(Object payload, Metadata metadata) Sends a command with given payload and metadata and don't wait for a result.static void
sendAndForgetCommand
(Object payload, Metadata metadata, Guarantee guarantee) Sends a command with given payload and metadata and don't wait for a result.static void
sendAndForgetCommands
(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, 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, 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> R
sendCommandAndWait
(Request<R> command) Sends the given command and returns the command's result.static <R> R
sendCommandAndWait
(Request<R> payload, 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> R
sendCommandAndWait
(Object command) Sends the given command and returns the command's result.static <R> R
sendCommandAndWait
(Object payload, 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.Returns the default serializerReturns the store for aggregate snapshots.Returns theTaskScheduler
of this FluxCapacitor instance.tracking
(MessageType messageType) Returns a client to assist with the tracking of a given message type.Returns the UserProvider used by Flux Capacitor to authenticate users.Returns the gateway for sending web requests.void
Have Flux Capacitor use the given Clock when generating timestamps, e.g. when creating aMessage
.
-
Field Details
-
applicationInstance
Flux Capacitor 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 FluxCapacitor instance which will be the case for nearly all applications. On application startup simply fill this application instance. -
instance
Thread-local binding of the currentFluxCapacitor
instance.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
@HandleCommand
method, you can callFluxCapacitor.sendCommand(...)
and it will automatically use the correct instance, without needing manual wiring.
-
-
Method Details
-
get
Returns the Flux Capacitor instance bound to the current thread or else set by the current application. Throws an exception if no instance was registered. -
getOptionally
Returns the FluxCapacitor client bound to the current thread or else set by the current application as Optional. Returns an empty Optional if no instance was registered. -
currentClock
Gets the clock of the current FluxCapacitor instance (obtained viagetOptionally()
). If there is no current instance the system's UTC clock is returned. -
currentTime
Gets the time according to the current FluxCapacitor clock (obtained viacurrentClock()
). If there is no current FluxCapacitor instance the system's UTC time is returned. -
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 givenidClass
using the currentIdentityProvider
.- Returns:
- a unique, traceable typed identifier
-
currentIdentityProvider
Fetches the configured identity provider used for both functional and technical IDs. The default is aUuidFactory
that generates UUIDs.If there is no current FluxCapacitor instance, a new UUID factory is generated.
-
currentCorrelationData
Gets the current correlation data, which by default depends on the currentClient
,Tracker
andDeserializingMessage
-
publishEvent
Publishes the given application event. The event may be an instance of aMessage
in 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(java.lang.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(java.lang.Object...)
after loading an entity.- See Also:
-
publishEvents
Publishes given application events. The events may be instances ofMessage
in 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(java.lang.Object...)
after loading an entity.- See Also:
-
sendAndForgetCommand
Sends the given command and doesn't wait for a result. The command may be an instance of aMessage
in which case it will be sent as is. Otherwise the command is published using the passed value as payload without additional metadata.- See Also:
-
sendAndForgetCommands
Sends the given commands and doesn't wait for results. Commands may be an instance of aMessage
in which case it will be sent as is. Otherwise, the commands are published using the passed value as payload without additional metadata.- See Also:
-
sendAndForgetCommand
Sends a command with given payload and metadata and don't wait for a result.- See Also:
-
sendAndForgetCommand
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 aMessage
in 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 aMessage
in 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 aMessage
in which case they will be sent as is. Otherwise, the commands are published using the passed values as payload without additional metadata. -
sendCommand
Sends a command with given payload and metadata and returns a future that will be completed with the command's result. -
sendCommand
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
Sends the given command and returns the command's result. The command may be an instance of aMessage
in which case it will be sent as is. Otherwise, the command is published using the passed value as payload without additional metadata. -
sendCommandAndWait
Sends the given command and returns the command's result. The command may be an instance of aMessage
in 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.
-
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 aMessage
in 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 aMessage
in 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
Sends the given query and returns the query's result. The query may be an instance of aMessage
in which case it will be sent as is. Otherwise, the query is published using the passed value as payload without additional metadata. -
queryAndWait
Sends the given query and returns the query's result. The query may be an instance of aMessage
in 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. Theschedule
parameter may be an instance of aMessage
or the schedule payload. If the payload is not annotated withPeriodic
anIllegalArgumentException
is thrown.- See Also:
-
schedulePeriodic
Starts a new periodic schedule using given schedule id. Theschedule
parameter may be an instance of aMessage
or the schedule payload. If the payload is not annotated withPeriodic
anIllegalArgumentException
is thrown.- See Also:
-
schedule
Schedules a message for the given timestamp, returning the schedule's id. Theschedule
parameter may be an instance of aMessage
in 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 givenscheduleId
for the given timestamp. Theschedule
parameter may be an instance of aMessage
in 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. Theschedule
parameter may be an instance of aMessage
in 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 givenscheduleId
after given delay. Theschedule
parameter may be an instance of aMessage
in which case it will be scheduled as is. Otherwise, the schedule is published using the passed value as payload without additional metadata. -
schedule
Schedule a message object (of typeSchedule
) for execution, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the message to schedule
-
schedule
Schedule a message object (of typeSchedule
) for execution, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the message to schedule
-
scheduleCommand
Schedules a command for the given timestamp, returning the command schedule's id. Thecommand
parameter may be an instance of aMessage
in 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 givenscheduleId
for the given timestamp. Thecommand
parameter may be an instance of aMessage
in 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. Thecommand
parameter may be an instance of aMessage
in 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 givenscheduleId
after given delay. Thecommand
parameter may be an instance of aMessage
in 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.SENT
guarantee. -
scheduleCommand
Schedule a command using the given scheduling settings if no other with same ID exists, using theGuarantee.SENT
guarantee. -
cancelSchedule
Cancels the schedule with givenscheduleId
. -
publishMetrics
Publishes a metrics event. The parameter may be an instance of aMessage
in 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.
- 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 emptyEntity
of typeObject
will 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:
-
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 givendefaultType
as 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.
-
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 setnull
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.
-
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 setnull
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.
-
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
@Searchable
the 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
@Searchable
the 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
static CompletableFuture<Void> index(Object object, Object id, Object collection, Instant timestamp) Index given object for search. This method returns once the object is stored.- See Also:
-
index
static CompletableFuture<Void> index(Object object, Object id, Object collection, Instant begin, Instant end) Index given object for search. This method returns once the object is stored.- See Also:
-
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. UseidFunction
to provide the document's required id. UsetimestampFunction
andendFunction
to 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:
-
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 aCollection
containing one or multiple collection names.If collection is of type
Class
it 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: FluxCapacitor.search("myCollection").query("foo !bar").fetch(100);
-
search
Search the given collections for documents.If collection is of type
Class
it is expected that the class is annotated with *Searchable
. 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: FluxCapacitor.search("myCollection", "myOtherCollection).query("foo !bar").fetch(100);
-
search
Search documents using given reusable query builder.Example usage: FluxCapacitor.search(SearchQuery.builder().search("myCollection").query("foo !bar")).fetch(100);
-
getDocument
Gets the document with given id in given collection, returning the value in the type that it was stored. -
getDocument
Gets the document with given id in given collection type, returning the value. -
getDocument
Gets the document with given id in given collection, converting the matching document to a value with 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. SeeFilterContent
for info on how to filter the value. -
downcast
Downcasts the given object to a previous revision.- Parameters:
object
- the object to downcastdesiredRevision
- the target revision- Returns:
- a serialized form of the object downcasted to the given revision
-
downcast
Downcasts aData
object 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 Flux Capacitor service. 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
Have Flux Capacitor use the given Clock when generating timestamps, e.g. when creating aMessage
. -
aggregateRepository
AggregateRepository aggregateRepository()Returns a client to assist with event sourcing. -
eventStore
EventStore eventStore()Returns the store for aggregate events. -
snapshotStore
SnapshotStore snapshotStore()Returns the store for aggregate snapshots. -
messageScheduler
MessageScheduler messageScheduler()Returns the gateway to schedule messages.- See Also:
-
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 Flux Capacitor. -
documentStore
DocumentStore documentStore()Returns a client for the document search service offered by Flux Capacitor. -
userProvider
UserProvider userProvider()Returns the UserProvider used by Flux Capacitor to authenticate users. May benull
if user authentication is disabled. -
cache
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 Flux Capacitor to generate timestamps. -
identityProvider
IdentityProvider identityProvider()Returns the factory used by Flux Capacitor to generate identifiers. -
propertySource
PropertySource propertySource()Returns thePropertySource
configured for this FluxCapacitor instance. -
taskScheduler
TaskScheduler taskScheduler()Returns theTaskScheduler
of this FluxCapacitor instance. -
configuration
FluxCapacitorConfiguration configuration()Returns theFluxCapacitorConfiguration
of this FluxCapacitor instance. -
client
Client client()Returns the low level client used by this FluxCapacitor instance to interface with the Flux Capacitor service. Of course the returned client may also be a stand-in for the actual service. -
apply
Applies the given function with this Flux Capacitor set as current threadlocal instance. -
execute
Executes the given task with this Flux Capacitor set as current threadlocal instance. -
beforeShutdown
Register a task to run before this Flux Capacitor instance is closed. -
close
default void close()Closes this Flux Capacitor instance gracefully.- Specified by:
close
in interfaceAutoCloseable
-
close
void close(boolean silently) Closes this Flux Capacitor instance gracefully. If silently is true, shutdown is done without logging.
-