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
ConstructorsModifierConstructorDescriptionprotectedConfigDrivenServiceProviderBase(String instanceId) The default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassertIsRootProvider(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 voiddoConstructing(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) After the gathering dependency phase, we will short circuit directly to the finish line.protected voiddoDestroying(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called after thePreDestroyMethodprocess.protected voiddoPreDestroying(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called during thePreDestroyMethodprocess.protected abstract booleanReturn 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 StringThe identity suffix, or empty string if there is no suffix.voidinjectionServices(Optional<InjectionServices> injectionServices) Assigns the services instance this provider is bound to.protected StringInstance id associated with this instance.booleanReturns 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.Loggerlogger()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 voidCalled on the final leg of the shutdown sequence.voidonPhaseEvent(Event event, Phase phase) Called when there is an event transition within the service registry.final voidregisterConfigBean(NamedInstance<CB> configBean) Called during initialization to register a loaded config bean.booleanreset(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.voidrootProvider(ServiceProvider<T> root) Sets the root/parent provider for this instance.protected voidserviceInfo(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, weightMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.helidon.inject.configdriven.api.ConfigBeanFactory
configBeanType, createConfigBeansMethods inherited from interface io.helidon.inject.configdriven.runtime.ConfiguredServiceProvider
configBeanMethods inherited from interface io.helidon.inject.api.InjectionPointProvider
getMethods inherited from interface io.helidon.inject.api.ServiceProvider
activator, currentActivationPhase, deActivator, dependencies, description, id, isProvider, postConstructMethod, preDestroyMethod, serviceInfo, serviceTypeMethods 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:
registerConfigBeanin interfaceConfiguredServiceProvider<T,CB> - Parameters:
configBean- the config bean
-
reset
public boolean reset(boolean deep) Description copied from interface:ResettableResets the state of this object.- Specified by:
resetin interfaceResettable- Overrides:
resetin 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:ServiceProviderBindableReturns true if this provider is the root provider.- Specified by:
isRootProviderin interfaceServiceProviderBindable<T>- Returns:
- indicates whether this provider is a root provider - the default is true
-
rootProvider
Description copied from interface:ServiceProviderBindableGets 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:
rootProviderin interfaceServiceProviderBindable<T>- Returns:
- the root/parent provider or empty if this instance is the root provider
-
rootProvider
Description copied from interface:ServiceProviderBindableSets the root/parent provider for this instance.- Specified by:
rootProviderin interfaceServiceProviderBindable<T>- Parameters:
root- sets the root provider
-
injectionServices
Description copied from interface:ServiceProviderBindableAssigns 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:
injectionServicesin interfaceServiceProviderBindable<T>- Overrides:
injectionServicesin classAbstractServiceProvider<T>- Parameters:
injectionServices- the injection services instance, or empty to clear any active binding
-
onPhaseEvent
Description copied from interface:ActivationPhaseReceiverCalled when there is an event transition within the service registry.- Specified by:
onPhaseEventin interfaceActivationPhaseReceiver- Overrides:
onPhaseEventin 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:InjectionResolverAttempts 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
ServiceProviderinstances qualify. Phase 2 (resolveIps=true) is during actual resolution, and typically comes during the service activation lifecycle.- Specified by:
resolvein 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
ConfigDrivenqualifier w/ no value specified then the caller is only interested in the root provider. - if the request mentions the
ConfigDrivenqualifier 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:
serviceProvidersin 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:ServiceProviderProviderThis 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:
managedServiceProvidersin 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:InjectionPointProviderGet (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:
firstin interfaceInjectionPointProvider<T>- Overrides:
firstin classAbstractServiceProvider<T>- Parameters:
query- the service query- Returns:
- the best service provider matching the criteria
-
list
Description copied from interface:InjectionPointProviderGet (or create) a list of instances matching the criteria for the given injection point context.- Specified by:
listin interfaceInjectionPointProvider<T>- Overrides:
listin 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:
serviceProviderBindablein interfaceServiceProvider<T>- Overrides:
serviceProviderBindablein 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:
doConstructingin classAbstractServiceProvider<T>- Parameters:
logEntryAndResult- the record that holds the results
-
identitySuffix
Description copied from class:AbstractServiceProviderThe identity suffix, or empty string if there is no suffix.- Overrides:
identitySuffixin 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:AbstractServiceProviderSets the service info that describes the managed service that is assigned.- Overrides:
serviceInfoin classAbstractServiceProvider<T>- Parameters:
serviceInfo- the service info
-
logger
Description copied from class:AbstractServiceProviderThe logger.- Overrides:
loggerin classAbstractServiceProvider<T>- Returns:
- the logger
-
doPreDestroying
Description copied from class:AbstractServiceProviderCalled during thePreDestroyMethodprocess.- Overrides:
doPreDestroyingin classAbstractServiceProvider<T>- Parameters:
logEntryAndResult- the entry holding the result
-
doDestroying
Description copied from class:AbstractServiceProviderCalled after thePreDestroyMethodprocess.- Overrides:
doDestroyingin classAbstractServiceProvider<T>- Parameters:
logEntryAndResult- the entry holding the result
-
onFinalShutdown
protected void onFinalShutdown()Description copied from class:AbstractServiceProviderCalled on the final leg of the shutdown sequence.- Overrides:
onFinalShutdownin 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
-