Class MultiTenantSnapshotStore
- All Implemented Interfaces:
DescribableComponent,SnapshotStore
SnapshotStore. Snapshot load and
store operations are routed to the store of the
one tenant resolved from the ProcessingContext, so each tenant's snapshots live in its own store.
Snapshot operations therefore require a tenant-carrying processing context. When none is available, or the tenant cannot be resolved from it, the operation completes exceptionally.
Registered as the application's SnapshotStore, so snapshots written for an entity land in the store of the
tenant the entity belongs to. Snapshot reads while sourcing do not travel through here: those stay with
MultiTenantEventStorageEngine, which routes them to the tenant's own engine.
- Since:
- 5.3.0
- Author:
- Jakob Hatzl, Laura Devriendt
-
Constructor Summary
ConstructorsConstructorDescriptionMultiTenantSnapshotStore(TenantSnapshotStoreFactory snapshotStoreFactory, TenantRouter tenantRouter) Constructs aMultiTenantSnapshotStore. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.CompletableFuture<@Nullable Snapshot> load(QualifiedName qualifiedName, Object identifier, @Nullable ProcessingContext context) Loads the latest snapshot for a given name and identifier.store(QualifiedName qualifiedName, Object identifier, Snapshot snapshot, @Nullable ProcessingContext context) Persists a snapshot under the given name and identifier.
-
Constructor Details
-
MultiTenantSnapshotStore
public MultiTenantSnapshotStore(TenantSnapshotStoreFactory snapshotStoreFactory, TenantRouter tenantRouter) Constructs aMultiTenantSnapshotStore.- Parameters:
snapshotStoreFactory- the factory providing each tenant'sSnapshotStoretenantRouter- the router deciding which tenant a snapshot operation is routed to
-
-
Method Details
-
store
public CompletableFuture<Void> store(QualifiedName qualifiedName, Object identifier, Snapshot snapshot, @Nullable ProcessingContext context) Description copied from interface:SnapshotStorePersists a snapshot under the given name and identifier. This replaces any previous snapshot(s) with the same name and identifier.This method is asynchronous and returns a
CompletableFuturethat completes when the snapshot has been durably stored.- Specified by:
storein interfaceSnapshotStore- Parameters:
qualifiedName- the name of the snapshot to persist, cannot benullidentifier- the identifier of the snapshot to persist, cannot benullsnapshot- the snapshot to persist, cannot benullcontext- theProcessingContextactive while storing, used by decorators (e.g. tracing) to correlate the operation with the surrounding unit of work; may benull- Returns:
- a
CompletableFuturethat completes when the snapshot has been stored
-
load
public CompletableFuture<@Nullable Snapshot> load(QualifiedName qualifiedName, Object identifier, @Nullable ProcessingContext context) Description copied from interface:SnapshotStoreLoads the latest snapshot for a given name and identifier.The returned snapshot may have an older or newer version relative to what is expected. The caller is responsible for handling version compatibility or ignoring unusable snapshots.
This method is asynchronous and returns a
CompletableFuturethat completes with the snapshot if one exists, ornullif no snapshot is available.- Specified by:
loadin interfaceSnapshotStore- Parameters:
qualifiedName- the name of the snapshot, cannot benullidentifier- the identifier of the snapshot, cannot benullcontext- theProcessingContextactive while loading, used by decorators (e.g. tracing) to correlate the operation with the surrounding unit of work; may benull- Returns:
- a
CompletableFuturecontaining the snapshot, or containingnullif no matching snapshot exists
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-