Class ConfigDrivenServiceProviderBase<T,CB>
java.lang.Object
io.helidon.inject.runtime.AbstractServiceProvider<T>
io.helidon.inject.configdriven.runtime.ConfigDrivenServiceProviderBase<T,CB>
- Type Parameters:
T
- the type of the service this provider managesCB
- the type of config beans that this service is configured by
- All Implemented Interfaces:
Weighted
,ActivationPhaseReceiver
,Activator
,DeActivator
,InjectionPointProvider<T>
,Resettable
,ServiceProvider<T>
,ServiceProviderBindable<T>
,ServiceProviderProvider
,ConfigBeanFactory<CB>
,ConfiguredServiceProvider<T,
,CB> InjectionResolver
,Provider<T>
,Comparable<Weighted>
public abstract class ConfigDrivenServiceProviderBase<T,CB>
extends AbstractServiceProvider<T>
implements ConfiguredServiceProvider<T,CB>, ServiceProviderProvider, InjectionPointProvider<T>, InjectionResolver
Abstract base for any config-driven-service.
-
Nested Class Summary
Nested classes/interfaces inherited from class io.helidon.inject.runtime.AbstractServiceProvider
AbstractServiceProvider.LogEntryAndResult
-
Field Summary
Fields inherited from interface io.helidon.common.Weighted
DEFAULT_WEIGHT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ConfigDrivenServiceProviderBase
(String instanceId) The default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
assertIsRootProvider
(boolean isRootProvider, boolean expectSet) Maybe transition into being a root provider if we are the first to claim it.protected abstract ConfigDrivenServiceProviderBase
<T, CB> createInstance
(NamedInstance<CB> configBean) Creates a new instance of this type of configured service provider, along with the configuration bean associated with the service.protected final List
<NamedInstance<CB>> createRepeatableBeans
(Config config, boolean wantDefault, Function<Config, CB> factory) protected void
doConstructing
(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) After the gathering dependency phase, we will short circuit directly to the finish line.protected void
doDestroying
(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called after thePreDestroyMethod
process.protected void
doPreDestroying
(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called during thePreDestroyMethod
process.protected abstract boolean
Return true if this service is driven to activation during startup (and provided it has some config).first
(io.helidon.inject.api.ContextualServiceQuery query) Get (or create) an instance of this service type for the given injection point context.protected String
The identity suffix, or empty string if there is no suffix.void
injectionServices
(Optional<InjectionServices> injectionServices) Assigns the services instance this provider is bound to.protected String
Instance id associated with this instance.boolean
Returns true if this provider is the root provider.list
(io.helidon.inject.api.ContextualServiceQuery query) Get (or create) a list of instances matching the criteria for the given injection point context.protected System.Logger
logger()
The logger.managedServiceProviders
(io.helidon.inject.api.ServiceInfoCriteria criteria) This method will only apply to the managed/slave instances being provided, not to itself as in the case forServiceProviderProvider.serviceProviders(ServiceInfoCriteria, boolean, boolean)
.protected void
Called on the final leg of the shutdown sequence.void
onPhaseEvent
(Event event, Phase phase) Called when there is an event transition within the service registry.final void
registerConfigBean
(NamedInstance<CB> configBean) Called during initialization to register a loaded config bean.boolean
reset
(boolean deep) Resets the state of this object.resolve
(io.helidon.inject.api.InjectionPointInfo ipInfo, InjectionServices injectionServices, ServiceProvider<?> serviceProvider, boolean resolveIps) Attempts to resolve the injection point info for a given service provider.Gets the root/parent provider for this service.void
rootProvider
(ServiceProvider<T> root) Sets the root/parent provider for this instance.protected void
serviceInfo
(io.helidon.inject.api.ServiceInfo serviceInfo) Sets the service info that describes the managed service that is assigned.Configurable services by their very nature are not compile-time bindable during application creation.List
<ServiceProvider<?>> serviceProviders
(io.helidon.inject.api.ServiceInfoCriteria criteria, boolean wantThis, boolean thisAlreadyMatches) Here we are only looking for service providers, not service instances.Methods inherited from class io.helidon.inject.runtime.AbstractServiceProvider
activate, activationLog, activator, createLogEntryAndResult, createServiceProvider, currentActivationPhase, deactivate, deActivator, dependencies, dependencies, description, doInjectingFields, doInjectingMethods, doPostConstructing, equals, expectedQualifiedServiceError, get, get, getOrCreateInjectionPlan, hashCode, id, identityPrefix, injectionPlanBinder, injectionServices, interceptor, interceptor, isAlreadyAtTargetPhase, isCustom, isInterceptor, isProvider, maybeActivate, moduleName, name, onFailedFinish, onFinished, postConstructMethod, preDestroyMethod, serviceInfo, serviceRef, serviceTypeInjectionOrder, startTransitionCurrentActivationPhase, toAbstractServiceProvider, toString, weight
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.helidon.inject.configdriven.api.ConfigBeanFactory
configBeanType, createConfigBeans
Methods inherited from interface io.helidon.inject.configdriven.runtime.ConfiguredServiceProvider
configBean
Methods inherited from interface io.helidon.inject.api.InjectionPointProvider
get
Methods inherited from interface io.helidon.inject.api.ServiceProvider
activator, currentActivationPhase, deActivator, dependencies, description, id, isProvider, postConstructMethod, preDestroyMethod, serviceInfo, serviceType
Methods inherited from interface io.helidon.inject.api.ServiceProviderBindable
isIntercepted
-
Constructor Details
-
ConfigDrivenServiceProviderBase
The default constructor.- Parameters:
instanceId
- of this provider, root provider is hardcoded toroot
, managed instances are named based on the config bean name
-
-
Method Details
-
registerConfigBean
Called during initialization to register a loaded config bean.- Specified by:
registerConfigBean
in interfaceConfiguredServiceProvider<T,
CB> - Parameters:
configBean
- the config bean
-
reset
public boolean reset(boolean deep) Description copied from interface:Resettable
Resets the state of this object.- Specified by:
reset
in interfaceResettable
- Overrides:
reset
in classAbstractServiceProvider<T>
- Parameters:
deep
- true to iterate over any contained objects, to reflect the reset into the retained object- Returns:
- returns true if the state was changed
-
isRootProvider
public boolean isRootProvider()Description copied from interface:ServiceProviderBindable
Returns true if this provider is the root provider.- Specified by:
isRootProvider
in interfaceServiceProviderBindable<T>
- Returns:
- indicates whether this provider is a root provider - the default is true
-
rootProvider
Description copied from interface:ServiceProviderBindable
Gets the root/parent provider for this service. A root/parent provider is intended to manage it's underlying providers. Note that "root" and "parent" are interchangeable here since there is at most one level of depth that occurs whenServiceProvider
's are wrapped by other providers.- Specified by:
rootProvider
in interfaceServiceProviderBindable<T>
- Returns:
- the root/parent provider or empty if this instance is the root provider
-
rootProvider
Description copied from interface:ServiceProviderBindable
Sets the root/parent provider for this instance.- Specified by:
rootProvider
in interfaceServiceProviderBindable<T>
- Parameters:
root
- sets the root provider
-
injectionServices
Description copied from interface:ServiceProviderBindable
Assigns the services instance this provider is bound to. A service provider can be associated with 0..1 services instance. If not set, the service provider should useInjectionServices.injectionServices()
to ascertain the instance.- Specified by:
injectionServices
in interfaceServiceProviderBindable<T>
- Overrides:
injectionServices
in classAbstractServiceProvider<T>
- Parameters:
injectionServices
- the injection services instance, or empty to clear any active binding
-
onPhaseEvent
Description copied from interface:ActivationPhaseReceiver
Called when there is an event transition within the service registry.- Specified by:
onPhaseEvent
in interfaceActivationPhaseReceiver
- Overrides:
onPhaseEvent
in classAbstractServiceProvider<T>
- Parameters:
event
- the eventphase
- the phase
-
resolve
public Optional<Object> resolve(io.helidon.inject.api.InjectionPointInfo ipInfo, InjectionServices injectionServices, ServiceProvider<?> serviceProvider, boolean resolveIps) Description copied from interface:InjectionResolver
Attempts to resolve the injection point info for a given service provider.There are two modes that injection resolvers run through. Phase 1 (resolveIps=false) is during the time when the injection plan is being formulated. This is the time we need to identify which
ServiceProvider
instances qualify. Phase 2 (resolveIps=true) is during actual resolution, and typically comes during the service activation lifecycle.- Specified by:
resolve
in interfaceInjectionResolver
- Parameters:
ipInfo
- the injection point being resolvedinjectionServices
- the services registryserviceProvider
- the service provider this pertains toresolveIps
- flag indicating whether injection points should be resolved- Returns:
- the resolution for the plan or the injection point, or empty if unable to resolve the injection point context
-
serviceProviders
public List<ServiceProvider<?>> serviceProviders(io.helidon.inject.api.ServiceInfoCriteria criteria, boolean wantThis, boolean thisAlreadyMatches) Here we are only looking for service providers, not service instances. What we need to do here is to determine whether to (a) include root providers, (b) include slave providers, or (c) include both.The result depends on the type of this provider instance. Here is the heuristic:
- if this is a slave then simply use the standard matching behavior.
If, however, we are the root provider then the additional heuristic is applied:
- if the request mentions the
ConfigDriven
qualifier w/ no value specified then the caller is only interested in the root provider. - if the request mentions the
ConfigDriven
qualifier w/ a value specified then the caller is only interested in the slave providers. - if the request is completely empty then they are interested in everything - the root provider as well as the slave providers.
- if there is no slaves under management then they must be interested in the root provider.
- the fallback is to use standard matching using the criteria provided and only include the slaves.
- Specified by:
serviceProviders
in interfaceServiceProviderProvider
- Parameters:
criteria
- the injection point criteria that must matchwantThis
- if this instance matches criteria, do we want to return this instance as part of the resultthisAlreadyMatches
- an optimization that signals to the implementation that this instance has already matched using the standard service info matching checks- Returns:
- the list of matching service providers based upon the context and criteria provided
- if this is a slave then simply use the standard matching behavior.
-
managedServiceProviders
public Map<String,ConfigDrivenServiceProviderBase<?, managedServiceProvidersCB>> (io.helidon.inject.api.ServiceInfoCriteria criteria) Description copied from interface:ServiceProviderProvider
This method will only apply to the managed/slave instances being provided, not to itself as in the case forServiceProviderProvider.serviceProviders(ServiceInfoCriteria, boolean, boolean)
.- Specified by:
managedServiceProviders
in interfaceServiceProviderProvider
- Parameters:
criteria
- the injection point criteria that must match- Returns:
- the map of managed service providers matching the criteria, identified by its key/context
-
first
Description copied from interface:InjectionPointProvider
Get (or create) an instance of this service type for the given injection point context. This is logically the same as using the first element of the result from callingInjectionPointProvider.list(ContextualServiceQuery)
.- Specified by:
first
in interfaceInjectionPointProvider<T>
- Overrides:
first
in classAbstractServiceProvider<T>
- Parameters:
query
- the service query- Returns:
- the best service provider matching the criteria
-
list
Description copied from interface:InjectionPointProvider
Get (or create) a list of instances matching the criteria for the given injection point context.- Specified by:
list
in interfaceInjectionPointProvider<T>
- Overrides:
list
in classAbstractServiceProvider<T>
- Parameters:
query
- the service query- Returns:
- the resolved services matching criteria for the injection point in order of weight, or null if the context is not supported
-
serviceProviderBindable
Configurable services by their very nature are not compile-time bindable during application creation.- Specified by:
serviceProviderBindable
in interfaceServiceProvider<T>
- Overrides:
serviceProviderBindable
in classAbstractServiceProvider<T>
- Returns:
- empty, signaling that we are not bindable
- See Also:
-
createInstance
protected abstract ConfigDrivenServiceProviderBase<T,CB> createInstance(NamedInstance<CB> configBean) Creates a new instance of this type of configured service provider, along with the configuration bean associated with the service.- Parameters:
configBean
- the config bean- Returns:
- the created instance injected with the provided config bean
-
doConstructing
After the gathering dependency phase, we will short circuit directly to the finish line.- Overrides:
doConstructing
in classAbstractServiceProvider<T>
- Parameters:
logEntryAndResult
- the record that holds the results
-
identitySuffix
Description copied from class:AbstractServiceProvider
The identity suffix, or empty string if there is no suffix.- Overrides:
identitySuffix
in classAbstractServiceProvider<T>
- Returns:
- the identity suffix
-
instanceId
Instance id associated with this instance.- Returns:
- instance id
-
serviceInfo
protected void serviceInfo(io.helidon.inject.api.ServiceInfo serviceInfo) Description copied from class:AbstractServiceProvider
Sets the service info that describes the managed service that is assigned.- Overrides:
serviceInfo
in classAbstractServiceProvider<T>
- Parameters:
serviceInfo
- the service info
-
logger
Description copied from class:AbstractServiceProvider
The logger.- Overrides:
logger
in classAbstractServiceProvider<T>
- Returns:
- the logger
-
doPreDestroying
Description copied from class:AbstractServiceProvider
Called during thePreDestroyMethod
process.- Overrides:
doPreDestroying
in classAbstractServiceProvider<T>
- Parameters:
logEntryAndResult
- the entry holding the result
-
doDestroying
Description copied from class:AbstractServiceProvider
Called after thePreDestroyMethod
process.- Overrides:
doDestroying
in classAbstractServiceProvider<T>
- Parameters:
logEntryAndResult
- the entry holding the result
-
onFinalShutdown
protected void onFinalShutdown()Description copied from class:AbstractServiceProvider
Called on the final leg of the shutdown sequence.- Overrides:
onFinalShutdown
in classAbstractServiceProvider<T>
-
assertIsRootProvider
protected void assertIsRootProvider(boolean isRootProvider, boolean expectSet) Maybe transition into being a root provider if we are the first to claim it. Otherwise, we are a slave being managed.- Parameters:
isRootProvider
- true if an asserting is being made to claim root or claim managed slaveexpectSet
- true if this is a strong assertion, and if not claimed an exception will be thrown
-
drivesActivation
protected abstract boolean drivesActivation()Return true if this service is driven to activation during startup (and provided it has some config). SeeConfigDriven.activateByDefault()
.- Returns:
- true if this service is driven to activation during startup
-
createRepeatableBeans
-