Class AbstractConfiguredServiceProvider<T,CB>
java.lang.Object
io.helidon.pico.runtime.AbstractServiceProvider<T>
io.helidon.pico.configdriven.runtime.AbstractConfiguredServiceProvider<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:
ConfigBeanMapper,Weighted,ActivationPhaseReceiver,Activator,DeActivator,InjectionPointProvider<T>,Resettable,ServiceProvider<T>,ServiceProviderBindable<T>,ServiceProviderProvider,ConfiguredServiceProvider<T,,CB> InjectionResolver,Provider<T>,Comparable<Weighted>
public abstract class AbstractConfiguredServiceProvider<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.pico.runtime.AbstractServiceProvider
AbstractServiceProvider.LogEntryAndResult -
Field Summary
Fields inherited from interface io.helidon.common.Weighted
DEFAULT_WEIGHT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedThe default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected CBacceptConfig(Config config) Called to accept the new config bean instance initialized from the appropriate configuration tree location.protected voidassertIsRootProvider(boolean isRootProvider, boolean expectSet) Maybe transition into being a root provider if we are the first to claim it.The config bean attributes for ourConfigBean.abstract voidconfigBeanInstanceId(CB configBean, String val) Brokers the set of the instance id for the given config bean.The map of bean instance id's to config bean instances.Class<?>TheConfigBeantype that is used to configure this provider.The map of bean instance id's to managed configured service providers that this instance managed directly.protected abstract AbstractConfiguredServiceProvider<T,CB> createInstance(Object configBean) Creates a new instance of this type of configured service provider, along with the configuration bean associated with the service.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 booleanReturn true if this service is driven to activation during startup (and provided it has some config).first(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.booleanReturns true if this provider is the root provider.list(ContextualServiceQuery query) Get (or create) a list of instances matching the criteria for the given injection point context.protected System.Loggerlogger()The logger.managedServiceProviders(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).io.helidon.builder.config.spi.MetaConfigBeanInfoThe meta config bean information associated with this service provider'sConfigBean.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.voidpicoServices(Optional<PicoServices> picoServices) Assigns the services instance this provider is bound to.The backing config of this configured service instance.voidregisterConfigBean(String instanceId, Object configBean) Called during initialization to register a loaded config bean.booleanreset(boolean deep) Resets the state of this object.resolve(InjectionPointInfo ipInfo, PicoServices picoServices, 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(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(ServiceInfoCriteria criteria, boolean wantThis, boolean thisAlreadyMatches) Here we are only looking for service providers, not service instances.toConfigBean(C config, Class<CB> configBeanType) Translate the provided configuration into the appropriate config bean for this service type.abstract StringtoConfigBeanInstanceId(CB configBean) Gets the internal config bean instance id for the provided config bean.Methods inherited from class io.helidon.pico.runtime.AbstractServiceProvider
activate, activationLog, activator, createLogEntryAndResult, createServiceProvider, currentActivationPhase, deactivate, deActivator, dependencies, dependencies, description, doInjectingFields, doInjectingMethods, doPostConstructing, equals, expectedQualifiedServiceError, get, getOrCreateInjectionPlan, hashCode, id, identityPrefix, injectionPlanBinder, interceptor, interceptor, isAlreadyAtTargetPhase, isCustom, isInterceptor, isProvider, maybeActivate, moduleName, name, onFailedFinish, onFinished, picoServices, 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.pico.configdriven.runtime.ConfiguredServiceProvider
configBean, serviceType, toConfigBean, toConfigBeanBuilder, visitAttributesMethods inherited from interface io.helidon.pico.api.InjectionPointProvider
getMethods inherited from interface io.helidon.pico.api.ServiceProvider
activator, currentActivationPhase, deActivator, dependencies, description, id, isProvider, postConstructMethod, preDestroyMethod, serviceInfoMethods inherited from interface io.helidon.pico.api.ServiceProviderBindable
isIntercepted
-
Constructor Details
-
AbstractConfiguredServiceProvider
protected AbstractConfiguredServiceProvider()The default constructor.
-
-
Method Details
-
configBeanMap
The map of bean instance id's to config bean instances.- Returns:
- map of bean instance id's to config bean instances
-
configuredServicesMap
The map of bean instance id's to managed configured service providers that this instance managed directly.- Returns:
- map of bean instance id to managed configured service providers
-
registerConfigBean
Called during initialization to register a loaded config bean.- Parameters:
instanceId- the config bean instance idconfigBean- 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
-
picoServices
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 usePicoServices.picoServices()to ascertain the instance.- Specified by:
picoServicesin interfaceServiceProviderBindable<T>- Overrides:
picoServicesin classAbstractServiceProvider<T>- Parameters:
picoServices- the pico 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
-
configBeanType
Description copied from interface:ConfiguredServiceProviderTheConfigBeantype that is used to configure this provider.- Specified by:
configBeanTypein interfaceConfiguredServiceProvider<T,CB> - Returns:
- the
ConfigBeantype that is used to configure this provider
-
metaConfigBeanInfo
public io.helidon.builder.config.spi.MetaConfigBeanInfo metaConfigBeanInfo()Description copied from interface:ConfiguredServiceProviderThe meta config bean information associated with this service provider'sConfigBean.- Specified by:
metaConfigBeanInfoin interfaceConfiguredServiceProvider<T,CB> - Returns:
- the
MetaConfigBeanInfofor this config bean
-
configBeanAttributes
Description copied from interface:ConfiguredServiceProviderThe config bean attributes for ourConfigBean. Generally this method is for internal use only. Most should useConfiguredServiceProvider.visitAttributes(CB, io.helidon.builder.AttributeVisitor<java.lang.Object>, R)instead of this method.- Specified by:
configBeanAttributesin interfaceConfiguredServiceProvider<T,CB> - Returns:
- the config bean attributes
-
resolve
public Optional<Object> resolve(InjectionPointInfo ipInfo, PicoServices picoServices, 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 resolvedpicoServices- the pico servicesserviceProvider- 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(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
ConfiguredByqualifier w/ no value specified then the caller is only interested in the root provider. - if the request mentions the
ConfiguredByqualifier 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,AbstractConfiguredServiceProvider<?, managedServiceProvidersCB>> (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:
-
toConfigBean
Description copied from interface:ConfigBeanMapperTranslate the provided configuration into the appropriate config bean for this service type.- Specified by:
toConfigBeanin interfaceConfigBeanMapper- Type Parameters:
C- the config typeCB- the config bean type- Parameters:
config- the configconfigBeanType- the config bean type- Returns:
- the config bean generated, or empty if not possible to create
-
toConfigBeanInstanceId
Description copied from interface:ConfiguredServiceProviderGets the internal config bean instance id for the provided config bean.- Specified by:
toConfigBeanInstanceIdin interfaceConfiguredServiceProvider<T,CB> - Parameters:
configBean- the config bean- Returns:
- the config bean instance id
-
configBeanInstanceId
Brokers the set of the instance id for the given config bean.- Parameters:
configBean- the config bean to setval- the instance id to associate it with
-
rawConfig
The backing config of this configured service instance.- Returns:
- the backing config of this configured service instance
-
createInstance
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
-
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 boolean drivesActivation()Return true if this service is driven to activation during startup (and provided it has some config). SeeConfiguredBy.drivesActivation()and seeConfigBean.drivesActivation()for more.- Returns:
- true if this service is driven to activation during startup
-
acceptConfig
Called to accept the new config bean instance initialized from the appropriate configuration tree location.- Parameters:
config- the configuration- Returns:
- the new config bean
-