Interface TenantComponentProvider<T>
- Type Parameters:
T- the type of component provided per tenant
- All Superinterfaces:
DescribableComponent,MultiTenantAwareComponent,TenantDescriptors
T.
A provider holds one instance of T per tenant, so message handlers always receive
the resource belonging to the tenant of the message being handled (for example a per-tenant SQL datasource or
repository). Not to be confused with the TenantProvider, which provisions the tenants themselves: a
TenantComponentProvider provides an application component scoped to each of those tenants.
A single provider is generic over one component type. To expose several tenant-scoped component types,
register a separate provider per type. Each provider is matched to handler parameters by its
component type.
The default provider, obtained through withFactory(Class, TenantComponentFactory), creates instances
lazily through a TenantComponentFactory on first access for a
tenant, and releases them again when that tenant is unregistered.
As a MultiTenantAwareComponent the provider participates in tenant lifecycle management. Registering a
tenant makes it eligible for component instances and unregistering it releases them.
- Since:
- 5.3.0
- Author:
- Theo Emanuelsson, Jan Galinski, Laura Devriendt
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncomponentFor(TenantDescriptor tenant) Returns the component instance for the giventenant.Returns the type of component provided per tenant.static <T> TenantComponentProvider<T> withFactory(Class<T> componentType, TenantComponentFactory<T> factory) Creates aTenantComponentProviderfor the givencomponentType, building and destroying the per-tenant instances through the givenfactory.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeToMethods inherited from interface io.axoniq.framework.messaging.multitenancy.api.MultiTenantAwareComponent
registerAndStartTenant, registerTenantMethods inherited from interface io.axoniq.framework.messaging.multitenancy.api.TenantDescriptors
isKnown, tenants
-
Method Details
-
withFactory
static <T> TenantComponentProvider<T> withFactory(Class<T> componentType, TenantComponentFactory<T> factory) Creates aTenantComponentProviderfor the givencomponentType, building and destroying the per-tenant instances through the givenfactory.The returned provider creates each tenant's instance lazily on first access and caches it. It only serves
registeredtenants: requesting the component of an unknown tenant is rejected with aTenantNotResolvedException, so no tenant-scoped resource is ever built for a tenant the application does not know. Unregistering a tenant removes anddestroysits cached instance.Component creation runs inside the provider's cache update. The given
factory'screatemethod must therefore not register or unregister tenants on, nor request components from, the returned provider on the creating thread.- Type Parameters:
T- the type of component provided per tenant- Parameters:
componentType- the type of component provided per tenant, used to match against handler parameters, must not benullfactory- the factory building and destroying the per-tenant instances, must not benull- Returns:
- a provider serving one lazily created instance of
componentTypeper registered tenant - Throws:
NullPointerException- if the givencomponentTypeorfactoryisnull
-
componentFor
Returns the component instance for the giventenant.Implementations may reject tenants they do not serve with a
TenantNotResolvedException. The provider returned bywithFactory(Class, TenantComponentFactory)only serves registered tenants and creates each tenant's instance lazily on first access.- Parameters:
tenant- the tenant to provide the component instance for- Returns:
- the component instance belonging to the given
tenant - Throws:
TenantNotResolvedException- if the giventenantis not served by this provider
-
componentType
Returns the type of component provided per tenant.Used to match this provider against message-handler parameters during parameter resolution. Matching is based on the raw type: generic type parameters of the component type are not distinguished, so components differing only in their generics need distinct wrapper types.
- Returns:
- the component type provided per tenant
-