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 manages
CB - 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.
  • Constructor Details

    • ConfigDrivenServiceProviderBase

      protected ConfigDrivenServiceProviderBase(String instanceId)
      The default constructor.
      Parameters:
      instanceId - of this provider, root provider is hardcoded to root, managed instances are named based on the config bean name
  • Method Details

    • registerConfigBean

      public final void registerConfigBean(NamedInstance<CB> configBean)
      Called during initialization to register a loaded config bean.
      Specified by:
      registerConfigBean in interface ConfiguredServiceProvider<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 interface Resettable
      Overrides:
      reset in class AbstractServiceProvider<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 interface ServiceProviderBindable<T>
      Returns:
      indicates whether this provider is a root provider - the default is true
    • rootProvider

      public Optional<ServiceProvider<?>> 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 when ServiceProvider's are wrapped by other providers.
      Specified by:
      rootProvider in interface ServiceProviderBindable<T>
      Returns:
      the root/parent provider or empty if this instance is the root provider
    • rootProvider

      public void rootProvider(ServiceProvider<T> root)
      Description copied from interface: ServiceProviderBindable
      Sets the root/parent provider for this instance.
      Specified by:
      rootProvider in interface ServiceProviderBindable<T>
      Parameters:
      root - sets the root provider
    • injectionServices

      public void injectionServices(Optional<InjectionServices> 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 use InjectionServices.injectionServices() to ascertain the instance.
      Specified by:
      injectionServices in interface ServiceProviderBindable<T>
      Overrides:
      injectionServices in class AbstractServiceProvider<T>
      Parameters:
      injectionServices - the injection services instance, or empty to clear any active binding
    • onPhaseEvent

      public void onPhaseEvent(Event event, Phase phase)
      Description copied from interface: ActivationPhaseReceiver
      Called when there is an event transition within the service registry.
      Specified by:
      onPhaseEvent in interface ActivationPhaseReceiver
      Overrides:
      onPhaseEvent in class AbstractServiceProvider<T>
      Parameters:
      event - the event
      phase - 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 interface InjectionResolver
      Parameters:
      ipInfo - the injection point being resolved
      injectionServices - the services registry
      serviceProvider - the service provider this pertains to
      resolveIps - 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 interface ServiceProviderProvider
      Parameters:
      criteria - the injection point criteria that must match
      wantThis - if this instance matches criteria, do we want to return this instance as part of the result
      thisAlreadyMatches - 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
    • managedServiceProviders

      public Map<String,ConfigDrivenServiceProviderBase<?,CB>> managedServiceProviders(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 for ServiceProviderProvider.serviceProviders(ServiceInfoCriteria, boolean, boolean).
      Specified by:
      managedServiceProviders in interface ServiceProviderProvider
      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

      public Optional<T> first(io.helidon.inject.api.ContextualServiceQuery query)
      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 calling InjectionPointProvider.list(ContextualServiceQuery).
      Specified by:
      first in interface InjectionPointProvider<T>
      Overrides:
      first in class AbstractServiceProvider<T>
      Parameters:
      query - the service query
      Returns:
      the best service provider matching the criteria
    • list

      public List<T> list(io.helidon.inject.api.ContextualServiceQuery query)
      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 interface InjectionPointProvider<T>
      Overrides:
      list in class AbstractServiceProvider<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

      public Optional<ServiceProviderBindable<T>> serviceProviderBindable()
      Configurable services by their very nature are not compile-time bindable during application creation.
      Specified by:
      serviceProviderBindable in interface ServiceProvider<T>
      Overrides:
      serviceProviderBindable in class AbstractServiceProvider<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

      protected void doConstructing(AbstractServiceProvider.LogEntryAndResult logEntryAndResult)
      After the gathering dependency phase, we will short circuit directly to the finish line.
      Overrides:
      doConstructing in class AbstractServiceProvider<T>
      Parameters:
      logEntryAndResult - the record that holds the results
    • identitySuffix

      protected String identitySuffix()
      Description copied from class: AbstractServiceProvider
      The identity suffix, or empty string if there is no suffix.
      Overrides:
      identitySuffix in class AbstractServiceProvider<T>
      Returns:
      the identity suffix
    • instanceId

      protected String 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 class AbstractServiceProvider<T>
      Parameters:
      serviceInfo - the service info
    • logger

      protected System.Logger logger()
      Description copied from class: AbstractServiceProvider
      The logger.
      Overrides:
      logger in class AbstractServiceProvider<T>
      Returns:
      the logger
    • doPreDestroying

      protected void doPreDestroying(AbstractServiceProvider.LogEntryAndResult logEntryAndResult)
      Description copied from class: AbstractServiceProvider
      Called during the PreDestroyMethod process.
      Overrides:
      doPreDestroying in class AbstractServiceProvider<T>
      Parameters:
      logEntryAndResult - the entry holding the result
    • doDestroying

      protected void doDestroying(AbstractServiceProvider.LogEntryAndResult logEntryAndResult)
      Description copied from class: AbstractServiceProvider
      Called after the PreDestroyMethod process.
      Overrides:
      doDestroying in class AbstractServiceProvider<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 class AbstractServiceProvider<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 slave
      expectSet - 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). See ConfigDriven.activateByDefault().
      Returns:
      true if this service is driven to activation during startup
    • createRepeatableBeans

      protected final List<NamedInstance<CB>> createRepeatableBeans(Config config, boolean wantDefault, Function<Config,CB> factory)