java.lang.Object
io.helidon.inject.runtime.AbstractServiceProvider<T>
- Type Parameters:
T- the type of the service this provider manages
- All Implemented Interfaces:
Weighted,ActivationPhaseReceiver,Activator,DeActivator,InjectionPointProvider<T>,Resettable,ServiceProvider<T>,ServiceProviderBindable<T>,Provider<T>,Comparable<Weighted>
- Direct Known Subclasses:
ConfigDrivenServiceProviderBase,ReflectionBasedSingletonServiceProvider
public abstract class AbstractServiceProvider<T>
extends Object
implements ServiceProviderBindable<T>, Activator, DeActivator, ActivationPhaseReceiver, Resettable
Abstract base implementation for
ServiceProviderBindable, which represents the basics for regular
Singleton, ApplicationScoped, Provider, and ServiceProvider based managed services. All code-generated services will
extend from this abstract base class.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classRepresents a result of a phase transition. -
Field Summary
Fields inherited from interface io.helidon.common.Weighted
DEFAULT_WEIGHT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedThe default constructor.protectedAbstractServiceProvider(T instance, Phase phase, io.helidon.inject.api.ServiceInfo serviceInfo, InjectionServices injectionServices) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionio.helidon.inject.api.ActivationResultactivate(io.helidon.inject.api.ActivationRequest req) Activate a managed service/provider.protected Optional<ActivationLog> Returns the activation log.The agent responsible for activation - this will be non-null for build-time activators.createLogEntryAndResult(Phase targetPhase) Creates a log entry result based upon the target phase provided.protected TcreateServiceProvider(Map<String, Object> resolvedDeps) Creates the service with the supplied resolved dependencies, key'ed by each injection point id.The current activation phase for this service provider.io.helidon.inject.api.ActivationResultdeactivate(io.helidon.inject.api.DeActivationRequest req) Deactivate a managed service.The agent responsible for deactivation - this will be non-null for build-time activators.io.helidon.inject.api.DependenciesInfoProvides the dependencies for this service provider if known, or null if not known or not available.protected voiddependencies(io.helidon.inject.api.DependenciesInfo dependencies) Used to set the dependencies from this service provider.Describe the service provider.protected voiddoConstructing(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called during construction phase.protected voiddoDestroying(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called after thePreDestroyMethodprocess.protected voiddoInjectingFields(Object target, Map<String, Object> deps, Set<String> injections, TypeName forServiceType) Called during the injection of fields.protected voiddoInjectingMethods(Object target, Map<String, Object> deps, Set<String> injections, TypeName forServiceType) Called during the injection of methods.protected voiddoPostConstructing(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called during thePostConstructMethodprocess.protected voiddoPreDestroying(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called during thePreDestroyMethodprocess.booleanprotected ServiceProviderInjectionExceptionexpectedQualifiedServiceError(io.helidon.inject.api.ContextualServiceQuery ctx) Creates an injection exception appropriate when there are no matching qualified services for the context provided.first(io.helidon.inject.api.ContextualServiceQuery ctx) Get (or create) an instance of this service type for the given injection point context.get()Get (or create) an instance of this service type using default/empty criteria and context.protected <T> TCalled by the generated code when it is attempting to resolve a specific injection point dependency by id.getOrCreateInjectionPlan(boolean resolveIps) Get or Create the injection plan.inthashCode()id()Identifies the service provider physically and uniquely.protected StringThe identity prefix, or empty string if there is no prefix.protected StringThe identity suffix, or empty string if there is no suffix.Called at startup to establish the injection plan as an alternative to gathering it dynamically.Returns the previously assignedInjectionServicesinstance.voidinjectionServices(Optional<InjectionServices> injectionServices) Assigns the services instance this provider is bound to.Returns the service provider that intercepts this provider.voidinterceptor(ServiceProvider<?> interceptor) Sets the interceptor for this service provider.protected booleanisAlreadyAtTargetPhase(Phase targetPhase) Returns true if the current activation phase has reached the given target phase.booleanisCustom()Identifies whether the implementation was custom written and not code generated.booleanReturns true if this service provider instance is anInterceptor.booleanDoes the service provide singletons, does it always produce the same result for every call toInjectionPointProvider.get().list(io.helidon.inject.api.ContextualServiceQuery ctx) Get (or create) a list of instances matching the criteria for the given injection point context.protected System.Loggerlogger()The logger.maybeActivate(io.helidon.inject.api.ContextualServiceQuery ctx) Will trigger an activation if the managed service is not yet active.voidmoduleName(String moduleName) Called to inform a service provider the module name it is bound to.name(boolean simple) The name assigned to this provider.protected voidonFailedFinish(AbstractServiceProvider.LogEntryAndResult logEntryAndResult, Throwable t, boolean throwOnError) Called on a failed finish of activation.protected voidCalled on the final leg of the shutdown sequence.protected voidonFinished(AbstractServiceProvider.LogEntryAndResult logEntryAndResult) Called on a successful finish of activation.voidonPhaseEvent(Event event, Phase phase) Called when there is an event transition within the service registry.The optional method handling PreDestroy.The optional method handling PostConstruct.booleanreset(boolean deep) Resets the state of this object.io.helidon.inject.api.ServiceInfoThe meta information that describes the service.protected voidserviceInfo(io.helidon.inject.api.ServiceInfo serviceInfo) Sets the service info that describes the managed service that is assigned.The agent/instance to be used for binding this service provider to the injectable application that was code generated.Returns the managed service this provider has (or is in the process of) activating.Used to control the order of injection.protected voidstartTransitionCurrentActivationPhase(AbstractServiceProvider.LogEntryAndResult logEntryAndResult, Phase newPhase) Starts transitioning to a new phase.static <T> Optional<AbstractServiceProvider<T>> toAbstractServiceProvider(ServiceProvider<?> sp, boolean expected) Will test and downcast the passed service provider to an instance ofAbstractServiceProvider.toString()doubleweight()Weight of this class (maybe because it is defined dynamically, so it cannot be defined by an annotation).Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.helidon.inject.api.ServiceProvider
serviceTypeMethods inherited from interface io.helidon.inject.api.ServiceProviderBindable
isIntercepted, isRootProvider, rootProvider, rootProvider
-
Constructor Details
-
AbstractServiceProvider
protected AbstractServiceProvider()The default constructor. -
AbstractServiceProvider
protected AbstractServiceProvider(T instance, Phase phase, io.helidon.inject.api.ServiceInfo serviceInfo, InjectionServices injectionServices) Constructor.- Parameters:
instance- the managed service instancephase- the current phaseserviceInfo- the service infoinjectionServices- the services instance
-
-
Method Details
-
toAbstractServiceProvider
public static <T> Optional<AbstractServiceProvider<T>> toAbstractServiceProvider(ServiceProvider<?> sp, boolean expected) Will test and downcast the passed service provider to an instance ofAbstractServiceProvider.- Type Parameters:
T- the managed service type- Parameters:
sp- the service providerexpected- is the result expected to be present- Returns:
- the abstract service provider
-
activator
Description copied from interface:ServiceProviderThe agent responsible for activation - this will be non-null for build-time activators. If not present then anInjectormust be used to reflectively activate.- Specified by:
activatorin interfaceServiceProvider<T>- Returns:
- the activator
-
deActivator
Description copied from interface:ServiceProviderThe agent responsible for deactivation - this will be non-null for build-time activators. If not present then anInjectormust be used to reflectively deactivate.- Specified by:
deActivatorin interfaceServiceProvider<T>- Returns:
- the deactivator to use or null if the service is not interested in deactivation
-
serviceProviderBindable
Description copied from interface:ServiceProviderThe agent/instance to be used for binding this service provider to the injectable application that was code generated.- Specified by:
serviceProviderBindablein interfaceServiceProvider<T>- Returns:
- the service provider that should be used for binding, or empty if this provider does not support binding
- See Also:
-
isProvider
public boolean isProvider()Description copied from interface:ServiceProviderDoes the service provide singletons, does it always produce the same result for every call toInjectionPointProvider.get(). I.e., if the managed service implements Provider orInjectionPointProviderthen this typically is considered not a singleton provider. I.e., If the managed services is NOTSingleton, then it will be treated as per request / dependent scope. Note that this is similar in nature to RequestScope, except the "official" request scope is bound to the web request. Here, we are speaking about contextually any caller asking for a new instance of the service in question. The requester in question will ideally be able to identify itself to this provider viaInjectionPointProvider.first(ContextualServiceQuery)so that this provider can properly service the "provide" request.- Specified by:
isProviderin interfaceServiceProvider<T>- Returns:
- true if the service provider provides per-request instances for each caller
-
isCustom
public boolean isCustom()Identifies whether the implementation was custom written and not code generated. We assume by default this is part of code-generation, and the default is to return false.- Returns:
- true if a custom, user-supplied implementation (rare)
-
serviceInfo
public io.helidon.inject.api.ServiceInfo serviceInfo()Description copied from interface:ServiceProviderThe meta information that describes the service. Must remain immutable for the lifetime of the JVM post binding - ie., afterServiceBinder.bind(ServiceProvider)is called.- Specified by:
serviceInfoin interfaceServiceProvider<T>- Returns:
- the meta information describing the service
-
dependencies
public io.helidon.inject.api.DependenciesInfo dependencies()Description copied from interface:ServiceProviderProvides the dependencies for this service provider if known, or null if not known or not available.- Specified by:
dependenciesin interfaceServiceProvider<T>- Returns:
- the dependencies this service provider has or null if unknown or unavailable
-
weight
public double weight()Description copied from interface:WeightedWeight of this class (maybe because it is defined dynamically, so it cannot be defined by an annotation). If not dynamic, you can use theWeightannotation rather than implementing this interface as long as it is supported by the library using thisWeighted. -
currentActivationPhase
Description copied from interface:ServiceProviderThe current activation phase for this service provider.- Specified by:
currentActivationPhasein interfaceServiceProvider<T>- Returns:
- the activation phase
-
injectionServices
Description copied from interface:ServiceProviderBindableReturns the previously assignedInjectionServicesinstance.- Specified by:
injectionServicesin interfaceServiceProviderBindable<T>- Returns:
- the previously assigned injection services instance, or empty if never assigned
- See Also:
-
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>- Parameters:
injectionServices- the injection services instance, or empty to clear any active binding
-
moduleName
Description copied from interface:ServiceProviderBindableCalled to inform a service provider the module name it is bound to. Will only be called when there is a non-null module name associated for the givenModuleComponent. A service provider can be associated with 0..1 modules.- Specified by:
moduleNamein interfaceServiceProviderBindable<T>- Parameters:
moduleName- the non-null module name
-
isInterceptor
public boolean isInterceptor()Description copied from interface:ServiceProviderBindableReturns true if this service provider instance is anInterceptor.- Specified by:
isInterceptorin interfaceServiceProviderBindable<T>- Returns:
- true if this service provider is an interceptor
-
interceptor
Description copied from interface:ServiceProviderBindableReturns the service provider that intercepts this provider.- Specified by:
interceptorin interfaceServiceProviderBindable<T>- Returns:
- the service provider that intercepts this provider
-
interceptor
Description copied from interface:ServiceProviderBindableSets the interceptor for this service provider.- Specified by:
interceptorin interfaceServiceProviderBindable<T>- Parameters:
interceptor- the interceptor for this provider
-
hashCode
public int hashCode() -
equals
-
toString
-
description
Description copied from interface:ServiceProviderDescribe the service provider. This will change based upon activation state.- Specified by:
descriptionin interfaceServiceProvider<T>- Returns:
- the logical and immutable description
-
id
Description copied from interface:ServiceProviderIdentifies the service provider physically and uniquely.- Specified by:
idin interfaceServiceProvider<T>- Returns:
- the unique identity of the service provider
-
name
The name assigned to this provider. Simple names are not unique.- Parameters:
simple- flag to indicate simple name usage- Returns:
- this name assigned to this provider
-
get
Description copied from interface:InjectionPointProviderGet (or create) an instance of this service type using default/empty criteria and 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>- Parameters:
ctx- 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>- Parameters:
ctx- 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
-
activate
public io.helidon.inject.api.ActivationResult activate(io.helidon.inject.api.ActivationRequest req) Description copied from interface:ActivatorActivate a managed service/provider. -
onPhaseEvent
Description copied from interface:ActivationPhaseReceiverCalled when there is an event transition within the service registry.- Specified by:
onPhaseEventin interfaceActivationPhaseReceiver- Parameters:
event- the eventphase- the phase
-
injectionPlanBinder
Called at startup to establish the injection plan as an alternative to gathering it dynamically.- Specified by:
injectionPlanBinderin interfaceServiceProviderBindable<T>- Returns:
- binder used for this service provider, or empty if not capable or ineligible of being bound
-
getOrCreateInjectionPlan
public Map<String,io.helidon.inject.runtime.HelidonInjectionPlan> getOrCreateInjectionPlan(boolean resolveIps) Get or Create the injection plan.- Parameters:
resolveIps- true if the injection points should also be activated/resolved.- Returns:
- the injection plan
-
reset
public boolean reset(boolean deep) Description copied from interface:ResettableResets the state of this object.- Specified by:
resetin interfaceResettable- 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
-
postConstructMethod
Description copied from interface:ServiceProviderThe optional method handling PreDestroy.- Specified by:
postConstructMethodin interfaceServiceProvider<T>- Returns:
- the post-construct method or empty if there is none
-
preDestroyMethod
Description copied from interface:ServiceProviderThe optional method handling PostConstruct.- Specified by:
preDestroyMethodin interfaceServiceProvider<T>- Returns:
- the pre-destroy method or empty if there is none
-
deactivate
public io.helidon.inject.api.ActivationResult deactivate(io.helidon.inject.api.DeActivationRequest req) Description copied from interface:DeActivatorDeactivate a managed service. This will trigger anyPreDestroymethod on the underlying service type instance.- Specified by:
deactivatein interfaceDeActivator- Parameters:
req- deactivation request- Returns:
- the result
-
onFinalShutdown
protected void onFinalShutdown()Called on the final leg of the shutdown sequence. -
onFailedFinish
protected void onFailedFinish(AbstractServiceProvider.LogEntryAndResult logEntryAndResult, Throwable t, boolean throwOnError) Called on a failed finish of activation.- Parameters:
logEntryAndResult- the log entry holding the resultt- the error that was observedthrowOnError- the flag indicating whether we should throw on error- See Also:
-
logger
The logger.- Returns:
- the logger
-
serviceInfo
protected void serviceInfo(io.helidon.inject.api.ServiceInfo serviceInfo) Sets the service info that describes the managed service that is assigned.- Parameters:
serviceInfo- the service info
-
dependencies
protected void dependencies(io.helidon.inject.api.DependenciesInfo dependencies) Used to set the dependencies from this service provider.- Parameters:
dependencies- the dependencies from this service provider
-
isAlreadyAtTargetPhase
Returns true if the current activation phase has reached the given target phase.- Parameters:
targetPhase- the target phase- Returns:
- true if the targetPhase has been reached
-
identityPrefix
The identity prefix, or empty string if there is no prefix.- Returns:
- the identity prefix
-
identitySuffix
The identity suffix, or empty string if there is no suffix.- Returns:
- the identity suffix
-
serviceRef
Returns the managed service this provider has (or is in the process of) activating.- Returns:
- the service we are managing lifecycle for
-
activationLog
Returns the activation log.- Returns:
- the activation log
-
get
Called by the generated code when it is attempting to resolve a specific injection point dependency by id.- Type Parameters:
T- the type of the dependency- Parameters:
deps- the entire map of resolved dependenciesid- the id of the dependency to lookup- Returns:
- the resolved object
-
maybeActivate
Will trigger an activation if the managed service is not yet active.- Parameters:
ctx- the context that triggered the activation- Returns:
- the result of the activation
-
onFinished
Called on a successful finish of activation.- Parameters:
logEntryAndResult- the record holding the result- See Also:
-
doConstructing
Called during construction phase.- Parameters:
logEntryAndResult- the record that holds the results
-
createServiceProvider
Creates the service with the supplied resolved dependencies, key'ed by each injection point id.- Parameters:
resolvedDeps- the resolved dependencies- Returns:
- the newly created managed service
- Throws:
ServiceProviderInjectionException- since this is a base method for what is expected to be a code-generated derivedActivatorthen this method will throw an exception if the derived class does not implement this method as it normally should
-
serviceTypeInjectionOrder
Used to control the order of injection. Jsr-330 is particular about this.- Returns:
- the order of injection
-
doInjectingFields
protected void doInjectingFields(Object target, Map<String, Object> deps, Set<String> injections, TypeName forServiceType) Called during the injection of fields.- Parameters:
target- the targetdeps- the dependenciesinjections- the injectionsforServiceType- the service type
-
doInjectingMethods
protected void doInjectingMethods(Object target, Map<String, Object> deps, Set<String> injections, TypeName forServiceType) Called during the injection of methods.- Parameters:
target- the targetdeps- the dependenciesinjections- the injectionsforServiceType- the service type
-
doPostConstructing
Called during thePostConstructMethodprocess.- Parameters:
logEntryAndResult- the entry holding the result
-
doPreDestroying
Called during thePreDestroyMethodprocess.- Parameters:
logEntryAndResult- the entry holding the result
-
doDestroying
Called after thePreDestroyMethodprocess.- Parameters:
logEntryAndResult- the entry holding the result
-
expectedQualifiedServiceError
protected ServiceProviderInjectionException expectedQualifiedServiceError(io.helidon.inject.api.ContextualServiceQuery ctx) Creates an injection exception appropriate when there are no matching qualified services for the context provided.- Parameters:
ctx- the context- Returns:
- the injection exception
-
createLogEntryAndResult
Creates a log entry result based upon the target phase provided.- Parameters:
targetPhase- the target phase- Returns:
- a new log entry and result record
-
startTransitionCurrentActivationPhase
protected void startTransitionCurrentActivationPhase(AbstractServiceProvider.LogEntryAndResult logEntryAndResult, Phase newPhase) Starts transitioning to a new phase.- Parameters:
logEntryAndResult- the record that will hold the state of the transitionnewPhase- the target new phase
-