Class ServiceLocatorImpl
- All Implemented Interfaces:
ServiceLocator
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static final class
private class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IndexedListData
private ConcurrentHashMap
<Class<? extends Annotation>, InjectionResolver<?>> private final LinkedHashSet
<ValidationService> private static final String
private static final String
private static boolean
private static final String
private static final int
private final Map
<ServiceLocatorImpl, ServiceLocatorImpl> private final Object
private final HashMap
<String, ClassAnalyzer> private final ClassReflectionHelper
private final LinkedList
<ServiceHandle<?>> private final Cache
<Class<? extends Annotation>, Context<?>> private static long
private String
private Unqualified
(package private) static final DescriptorComparator
private final HashMap
<String, IndexedListData> private final HashMap
<String, IndexedListData> private final LinkedList
<ErrorService> private static final ServiceHandleComparator
private boolean
private final long
private final Cache
<SystemInjecteeImpl, InjectionResolver<?>> private final LinkedList
<InterceptionService> private final String
private boolean
private final AtomicLong
private final ServiceLocatorImpl
private final PerLocatorUtilities
private final ReentrantReadWriteLock
private final ReentrantReadWriteLock.ReadLock
private final Context
<javax.inject.Singleton> private static final Object
private ServiceLocatorState
private final ReentrantReadWriteLock.WriteLock
-
Constructor Summary
ConstructorsConstructorDescriptionServiceLocatorImpl
(String name, ServiceLocatorImpl parent) Called by the Generator, and hence must be a public method -
Method Summary
Modifier and TypeMethodDescriptionprivate Context
<?> _resolveContext
(Class<? extends Annotation> scope) private void
addChild
(ServiceLocatorImpl child) (package private) void
private List
<SystemDescriptor<?>> assistedInject
(Object injectMe, Method method, MethodParameter... params) This will invoke the given method on the given object.assistedInject
(Object injectMe, Method method, ServiceHandle<?> root, MethodParameter... params) This will invoke the given method on the given object.private void
callAllConfigurationListeners
(List<ServiceHandle<?>> allListeners) private boolean
Must have read lock heldChecks the configuration operation before anything happens to the internal data structures.private void
(package private) void
(package private) void
<T> T
This method will analyze the given class, and create it if can.<T> T
This method will analyze the given class, and create it if can.<U> U
createAndInitialize
(Class<U> createMe) Creates, injects and postConstructs, all in one<U> U
createAndInitialize
(Class<U> createMe, String strategy) Creates, injects and postConstructs, all in oneprivate static boolean
doTrace
(ActiveDescriptor<?> desc) private void
getAllChildren
(LinkedList<ServiceLocatorImpl> allMyChildren) getAllContracts
(ActiveDescriptor<?> desc) List
<ServiceHandle<?>> getAllServiceHandles
(Annotation qualifier, Annotation... qualifiers) Gets a list ofServiceHandle
that can be used to get and destroy services associated with descriptors that match the provided criteria<T> List
<ServiceHandle<T>> getAllServiceHandles
(Class<T> contractOrImpl, Annotation... qualifiers) Gets a list ofServiceHandle
that can be used to get and destroy services associated with descriptors that match the provided criteriaList
<ServiceHandle<?>> getAllServiceHandles
(Type contractOrImpl, Annotation... qualifiers) Gets a list ofServiceHandle
that can be used to get and destroy services associated with descriptors that match the provided criteriaList
<ServiceHandle<?>> getAllServiceHandles
(Filter searchCriteria) Gets a list ofServiceHandle
whoseActiveDescriptor
s match the supplied filter.<T> List
<T> getAllServices
(Annotation qualifier, Annotation... qualifiers) Gets all services from this locator that have the provided qualifiers<T> List
<T> getAllServices
(Class<T> contractOrImpl, Annotation... qualifiers) Gets all services from this locator that implement this contract or have this implementation and have the provided qualifiers<T> List
<T> getAllServices
(Type contractOrImpl, Annotation... qualifiers) Gets all services from this locator that implement this contract or have this implementation and have the provided qualifiersList
<?> getAllServices
(Filter searchCriteria) Gets all services from this locator that match the providedFilter
(package private) List
<ServiceHandle<?>> getAllUnqualifiedServiceHandles
(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers) private LinkedHashSet
<ValidationService> (package private) ClassAnalyzer
getAnalyzer
(String name, Collector collector) private static long
getBestDescriptor
(Filter filter) Gets the descriptor that best matches this filter, taking ranking and service id into account(package private) ClassReflectionHelper
Gets the name of the default class analyzer serviceThis returns the defaultUnqualified
annotation that will be put on all injection points that do not have any qualifiers.List
<ActiveDescriptor<?>> getDescriptors
(Filter filter) Gets the list of descriptors that match the given filterprivate List
<SystemDescriptor<?>> getDescriptors
(Filter filter, Injectee onBehalfOf, boolean getParents, boolean doValidation, boolean getLocals) private Unqualified
getEffectiveUnqualified
(Unqualified givenUnqualified, boolean isIterable, Annotation[] qualifiers) (package private) LinkedList
<ErrorService> getInjecteeDescriptor
(Injectee injectee) This method will first find a descriptor for this injectee, and then reify that descriptor.(package private) InjectionResolver
<?> getInjectionResolver
(Class<? extends Annotation> annoType) (package private) InjectionResolver
<?> (package private) List
<InterceptionService> long
This returns the unique locator ID for this locator.private ServiceLocatorImpl
getMe()
Used to get the ServiceLocatorImpl in inner classesgetName()
Returns the name of this ServiceLocatorprivate static String
getName
(String name, Annotation... qualifiers) boolean
This returns the value of neutralContextClassLoader.(package private) long
(package private) int
(package private) int
Gets the parent service locator for this locator(package private) PerLocatorUtilities
(package private) int
<T> T
getService
(Class<T> contractOrImpl, Annotation... qualifiers) Gets the best service from this locator that implements this contract or has this implementation<T> T
getService
(Class<T> contractOrImpl, String name, Annotation... qualifiers) Gets the best service from this locator that implements this contract or has this implementation and has the given name<T> T
getService
(Type contractOrImpl, Annotation... qualifiers) Gets the best service from this locator that implements this contract or has this implementation<T> T
getService
(Type contractOrImpl, String name, Annotation... qualifiers) Gets the best service from this locator that implements this contract or has this implementation and has the given name<T> T
getService
(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root) Deprecated.<T> T
getService
(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root, Injectee originalRequest) This method should be called by code resolving injectee's on behalf of some root service, usually by an implementation ofInjectionResolver.resolve(Injectee, ServiceHandle)
.(package private) int
(package private) int
<T> ServiceHandle
<T> getServiceHandle
(Class<T> contractOrImpl, Annotation... qualifiers) Gets aServiceHandle
that can be used to get and destroy the service that best matches the given criteria<T> ServiceHandle
<T> getServiceHandle
(Class<T> contractOrImpl, String name, Annotation... qualifiers) Gets aServiceHandle
that can be used to get and destroy the service that best matches the given criteria<T> ServiceHandle
<T> getServiceHandle
(Type contractOrImpl, Annotation... qualifiers) Gets aServiceHandle
that can be used to get and destroy the service that best matches the given criteria<T> ServiceHandle
<T> getServiceHandle
(Type contractOrImpl, String name, Annotation... qualifiers) Gets aServiceHandle
that can be used to get and destroy the service that best matches the given criteria<T> ServiceHandle
<T> getServiceHandle
(ActiveDescriptor<T> activeDescriptor) Gets aServiceHandle
that can be used to get and destroy the service described by theActiveDescriptor
.<T> ServiceHandle
<T> getServiceHandle
(ActiveDescriptor<T> activeDescriptor, Injectee injectee) Gets aServiceHandle
that can be used to get and destroy the service described by theActiveDescriptor
.private <T> ServiceHandleImpl
<T> getServiceHandleImpl
(ActiveDescriptor<T> activeDescriptor, Injectee injectee) getState()
Returns the current state of this service locator.(package private) <T> T
getUnqualifiedService
(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers) This method is only called from the get of IterableProvider.(package private) <T> ServiceHandle
<T> getUnqualifiedServiceHandle
(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers) (package private) boolean
hasInjectAnnotation
(AnnotatedElement annotated) private ServiceLocatorImpl.IgdValue
void
This will analyze the given object and inject into its fields and methods.void
This will analyze the given object and inject into its fields and methods.private List
<?> internalGetAllServiceHandles
(Type contractOrImpl, Unqualified unqualified, boolean getHandles, boolean isIterable, Annotation... qualifiers) private <T> ActiveDescriptor
<T> internalGetDescriptor
(Injectee onBehalfOf, Type contractOrImpl, String name, Unqualified unqualified, boolean isIterable, boolean calledFromSecondChanceResolveMethod, Annotation... qualifiers) private <T> ActiveDescriptor
<T> internalGetDescriptor
(Injectee onBehalfOf, Type contractOrImpl, String name, Unqualified unqualified, boolean isIterable, Annotation... qualifiers) private ActiveDescriptor
<?> internalGetInjecteeDescriptor
(Injectee injectee, boolean calledFromSecondChanceResolveMethod) private <T> T
internalGetService
(Type contractOrImpl, String name, Unqualified unqualified, boolean calledFromSecondChanceResolveMethod, Annotation... qualifiers) private <T> T
internalGetService
(Type contractOrImpl, String name, Unqualified unqualified, Annotation... qualifiers) private <T> ServiceHandleImpl
<T> internalGetServiceHandle
(ActiveDescriptor<T> activeDescriptor, Type requestedType, Injectee originalRequest) (package private) boolean
isInjectAnnotation
(Annotation annotation) (package private) boolean
isInjectAnnotation
(Annotation annotation, boolean isConstructor) private Class
<?> loadClass
(Descriptor descriptor, Injectee injectee) private ImmediateResults
narrow
(ServiceLocator locator, List<SystemDescriptor<?>> candidates, Type requiredType, String name, Injectee injectee, boolean onlyOne, boolean doValidation, NarrowResults cachedResults, Filter filter, Annotation... qualifiers) void
postConstruct
(Object postConstructMe) This will analyze the given object and call the postConstruct method.void
postConstruct
(Object postConstructMe, String strategy) This will analyze the given object and call the postConstruct method.void
preDestroy
(Object preDestroyMe) This will analyze the given object and call the preDestroy method.void
preDestroy
(Object preDestroyMe, String strategy) This will analyze the given object and call the preDestroy method.private List
<ServiceHandle<?>> protectedGetAllServiceHandles
(Type contractOrImpl, Annotation... qualifiers) private <T> List
<T> protectedGetAllServices
(Type contractOrImpl, Annotation... qualifiers) private List
<ActiveDescriptor<?>> protectedGetDescriptors
(Filter filter) reifyDescriptor
(Descriptor descriptor) Converts a descriptor to an ActiveDescriptor.reifyDescriptor
(Descriptor descriptor, Injectee injectee) Converts a descriptor to an ActiveDescriptor.private void
removeChild
(ServiceLocatorImpl child) private void
removeConfigurationInternal
(List<SystemDescriptor<?>> unbinds) (package private) Context
<?> resolveContext
(Class<? extends Annotation> scope) private void
reup
(List<SystemDescriptor<?>> thingsAdded, boolean instanceListenersModified, boolean injectionResolversModified, boolean errorHandlersModified, boolean classAnalyzersModified, boolean dynamicConfigurationListenersModified, HashSet<String> affectedContracts, boolean interceptionServicesModified) private void
private void
private void
private void
private void
private void
reupInstanceListenersHandlers
(Collection<SystemDescriptor<?>> checkList) private void
private ActiveDescriptor
<?> secondChanceResolve
(Injectee injectee) void
setDefaultClassAnalyzerName
(String defaultClassAnalyzer) Sets the name of the default class analyzer that should be used for allDescriptor
s that return null as their class analyzer.void
setDefaultUnqualified
(Unqualified unqualified) This sets the defaultUnqualified
annotation that will be put on all injection points that do not have any qualifiers.void
setNeutralContextClassLoader
(boolean neutralContextClassLoader) This sets the value of neutralContextClassLoader.void
shutdown()
This method will shutdown every service associated with this ServiceLocator.toString()
(package private) int
unsortIndexes
(int newRank, SystemDescriptor<?> desc, Set<IndexedListData> myLists) private boolean
validate
(SystemDescriptor<?> descriptor, Injectee onBehalfOf, Filter filter) Must be called under lock
-
Field Details
-
BIND_TRACING_PATTERN_PROPERTY
- See Also:
-
BIND_TRACING_PATTERN
-
BIND_TRACING_STACKS_PROPERTY
- See Also:
-
BIND_TRACING_STACKS
private static boolean BIND_TRACING_STACKS -
CACHE_SIZE
private static final int CACHE_SIZE- See Also:
-
sLock
-
currentLocatorId
private static long currentLocatorId -
DESCRIPTOR_COMPARATOR
-
HANDLE_COMPARATOR
-
readWriteLock
-
wLock
-
rLock
-
nextServiceId
-
locatorName
-
id
private final long id -
parent
-
neutralContextClassLoader
private volatile boolean neutralContextClassLoader -
classReflectionHelper
-
perLocatorUtilities
-
allDescriptors
-
descriptorsByAdvertisedContract
-
descriptorsByName
-
singletonContext
-
perLookupContext
-
allValidators
-
errorHandlers
-
configListeners
-
hasInterceptionServices
private volatile boolean hasInterceptionServices -
interceptionServices
-
contextCache
-
children
-
classAnalyzerLock
-
classAnalyzers
-
defaultClassAnalyzer
-
defaultUnqualified
-
allResolvers
-
injecteeToResolverCache
-
state
-
igdCache
-
igashCache
-
-
Constructor Details
-
ServiceLocatorImpl
Called by the Generator, and hence must be a public method- Parameters:
name
- The name of this locatorparent
- The parent of this locator (may be null)
-
-
Method Details
-
getAndIncrementLocatorId
private static long getAndIncrementLocatorId() -
callValidate
Must have read lock held- Parameters:
vi
- The non-null validation- Returns:
-
validate
Must be called under lock- Parameters:
descriptor
- The descriptor to validateonBehalfOf
- The fella who is being validated (or null)- Returns:
- true if every validator returned true
-
getDescriptors
private List<SystemDescriptor<?>> getDescriptors(Filter filter, Injectee onBehalfOf, boolean getParents, boolean doValidation, boolean getLocals) -
protectedGetDescriptors
-
getDescriptors
Description copied from interface:ServiceLocator
Gets the list of descriptors that match the given filter- Specified by:
getDescriptors
in interfaceServiceLocator
- Parameters:
filter
- A filter to use when determining which services should apply- Returns:
- A non-null but possibly empty list of descriptors in ranked order that match the given filter
-
getBestDescriptor
Description copied from interface:ServiceLocator
Gets the descriptor that best matches this filter, taking ranking and service id into account- Specified by:
getBestDescriptor
in interfaceServiceLocator
- Parameters:
filter
- The non-null filter to use to retrieve the best descriptor- Returns:
- The best descriptor matching the filter, or null if there is no descriptor that matches the filter
-
reifyDescriptor
public ActiveDescriptor<?> reifyDescriptor(Descriptor descriptor, Injectee injectee) throws MultiException Description copied from interface:ServiceLocator
Converts a descriptor to an ActiveDescriptor. Will use the registered HK2Loaders to perform this action. If no HK2Loader is available for the descriptor, will use the injectee to discover a classloader- Specified by:
reifyDescriptor
in interfaceServiceLocator
- Parameters:
descriptor
- The descriptor to convert, may not be nullinjectee
- The injectee on behalf of whom this descriptor is being injected. May be null if the injectee is unknown- Returns:
- The active descriptor as loaded with the first valid
HK2Loader
- Throws:
MultiException
- if there were errors when loading or analyzing the class
-
reifyDescriptor
Description copied from interface:ServiceLocator
Converts a descriptor to an ActiveDescriptor. Will use the registered HK2Loaders to perform this action- Specified by:
reifyDescriptor
in interfaceServiceLocator
- Parameters:
descriptor
- The descriptor to convert, may not be null- Returns:
- The active descriptor as loaded with the first valid
HK2Loader
- Throws:
MultiException
- if there were errors when loading or analyzing the class
-
secondChanceResolve
-
internalGetInjecteeDescriptor
private ActiveDescriptor<?> internalGetInjecteeDescriptor(Injectee injectee, boolean calledFromSecondChanceResolveMethod) -
getInjecteeDescriptor
Description copied from interface:ServiceLocator
This method will first find a descriptor for this injectee, and then reify that descriptor. If multiple descriptors are found, they will be reified in ranking order until an ActiveDescriptor matching the Injectee is found.This method is responsible for using the available
JustInTimeInjectionResolver
to add in new descriptors should the descriptor for the given injectee not be found initially- Specified by:
getInjecteeDescriptor
in interfaceServiceLocator
- Parameters:
injectee
- the injection point for whom to find the ActiveDescriptor- Returns:
- The active descriptor for this injection point
- Throws:
MultiException
- if there were errors when loading or analyzing the class
-
getServiceHandle
public <T> ServiceHandle<T> getServiceHandle(ActiveDescriptor<T> activeDescriptor, Injectee injectee) throws MultiException Description copied from interface:ServiceLocator
Gets aServiceHandle
that can be used to get and destroy the service described by theActiveDescriptor
. The injectee may be used to discover the proper classloader to use when attempting to reify theActiveDescriptor
- Specified by:
getServiceHandle
in interfaceServiceLocator
- Parameters:
activeDescriptor
- The descriptor for which to create aServiceHandle
. May not be nullinjectee
- The injectee on behalf of whom this service is being injected. May be null if the injectee is unknown- Returns:
- A
ServiceHandle
that may be used to create or destroy the service associated with thisActiveDescriptor
- Throws:
MultiException
- if there was an error during service handle creation
-
getServiceHandleImpl
private <T> ServiceHandleImpl<T> getServiceHandleImpl(ActiveDescriptor<T> activeDescriptor, Injectee injectee) throws MultiException - Throws:
MultiException
-
getServiceHandle
public <T> ServiceHandle<T> getServiceHandle(ActiveDescriptor<T> activeDescriptor) throws MultiException Description copied from interface:ServiceLocator
Gets aServiceHandle
that can be used to get and destroy the service described by theActiveDescriptor
.- Specified by:
getServiceHandle
in interfaceServiceLocator
- Parameters:
activeDescriptor
- The descriptor for which to create aServiceHandle
. May not be null- Returns:
- A
ServiceHandle
that may be used to create or destroy the service associated with thisActiveDescriptor
- Throws:
MultiException
- if there was an error during service handle creation
-
internalGetServiceHandle
private <T> ServiceHandleImpl<T> internalGetServiceHandle(ActiveDescriptor<T> activeDescriptor, Type requestedType, Injectee originalRequest) -
getService
@Deprecated public <T> T getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root) throws MultiException Deprecated.Description copied from interface:ServiceLocator
This method should be called by code resolving injectee's on behalf of some root service, usually by an implementation ofInjectionResolver.resolve(Injectee, ServiceHandle)
. In this way the objects associated with the root object can be destroyed in the proper sequence- Specified by:
getService
in interfaceServiceLocator
- Parameters:
activeDescriptor
- The descriptor whose service to createroot
- The ultimate parent of this service creation. May be null- Returns:
- The service matching this descriptor
- Throws:
MultiException
- if there was an error during service creation
-
getService
public <T> T getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root, Injectee originalRequest) throws MultiException Description copied from interface:ServiceLocator
This method should be called by code resolving injectee's on behalf of some root service, usually by an implementation ofInjectionResolver.resolve(Injectee, ServiceHandle)
. In this way the objects associated with the root object can be destroyed in the proper sequence- Specified by:
getService
in interfaceServiceLocator
- Parameters:
activeDescriptor
- The descriptor whose service to createroot
- The ultimate parent of this service creation. May be nulloriginalRequest
- The injectee passed into theInjectionResolver.resolve(Injectee, ServiceHandle)
if known, null otherwise- Returns:
- The service matching this descriptor
- Throws:
MultiException
- if there was an error during service creation
-
getService
Description copied from interface:ServiceLocator
Gets the best service from this locator that implements this contract or has this implementationUse this method only if destroying the service is not important, otherwise use
ServiceLocator.getServiceHandle(Class, Annotation...)
- Specified by:
getService
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service definition- Returns:
- An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract
- Throws:
MultiException
- if there was an error during service creation
-
getService
Description copied from interface:ServiceLocator
Gets the best service from this locator that implements this contract or has this implementationUse this method only if destroying the service is not important, otherwise use
ServiceLocator.getServiceHandle(Type, Annotation...)
- Specified by:
getService
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service definition- Returns:
- An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract
- Throws:
MultiException
- if there was an error during service creation
-
getService
public <T> T getService(Class<T> contractOrImpl, String name, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets the best service from this locator that implements this contract or has this implementation and has the given nameUse this method only if destroying the service is not important, otherwise use
ServiceLocator.getServiceHandle(Class, String, Annotation...)
- Specified by:
getService
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofname
- May be null (to indicate any name is ok), and is the name of the implementation to be returnedqualifiers
- The set of qualifiers that must match this service definition- Returns:
- An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract
- Throws:
MultiException
- if there was an error during service creation
-
getService
public <T> T getService(Type contractOrImpl, String name, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets the best service from this locator that implements this contract or has this implementation and has the given nameUse this method only if destroying the service is not important, otherwise use
ServiceLocator.getServiceHandle(Type, String, Annotation...)
- Specified by:
getService
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofname
- May be null (to indicate any name is ok), and is the name of the implementation to be returnedqualifiers
- The set of qualifiers that must match this service definition- Returns:
- An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract
- Throws:
MultiException
- if there was an error during service creation
-
internalGetService
private <T> T internalGetService(Type contractOrImpl, String name, Unqualified unqualified, Annotation... qualifiers) -
internalGetService
private <T> T internalGetService(Type contractOrImpl, String name, Unqualified unqualified, boolean calledFromSecondChanceResolveMethod, Annotation... qualifiers) -
getUnqualifiedService
<T> T getUnqualifiedService(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers) throws MultiException This method is only called from the get of IterableProvider. IterableProvider has already called the JIT resolvers and so should not do so again, since it is too much work and doesn't have the information about the original injectee- Throws:
MultiException
-
protectedGetAllServices
-
getAllServices
public <T> List<T> getAllServices(Class<T> contractOrImpl, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets all services from this locator that implement this contract or have this implementation and have the provided qualifiersUse this method only if destroying the service is not important, otherwise use
ServiceLocator.getAllServiceHandles(Class, Annotation...)
- Specified by:
getAllServices
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service definition- Returns:
- A list of services implementing this contract or concrete implementation. May not return null, but may return an empty list
- Throws:
MultiException
- if there was an error during service creation
-
getAllServices
public <T> List<T> getAllServices(Type contractOrImpl, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets all services from this locator that implement this contract or have this implementation and have the provided qualifiersUse this method only if destroying the service is not important, otherwise use
ServiceLocator.getAllServiceHandles(Type, Annotation...)
- Specified by:
getAllServices
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service definition- Returns:
- A list of services implementing this contract or concrete implementation. May not return null, but may return an empty list
- Throws:
MultiException
- if there was an error during service creation
-
getAllServices
public <T> List<T> getAllServices(Annotation qualifier, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets all services from this locator that have the provided qualifiersUse this method only if destroying the services is not important, otherwise use
ServiceLocator.getAllServiceHandles(Annotation, Annotation...)
- Specified by:
getAllServices
in interfaceServiceLocator
- Parameters:
qualifier
- May not be null, and is a qualifier that must match the service definitionqualifiers
- The set of qualifiers that must match this service definition- Returns:
- A list of services implementing this contract or concrete implementation. May not return null, but may return an empty list
- Throws:
MultiException
- if there was an error during service creation
-
getAllServices
Description copied from interface:ServiceLocator
Gets all services from this locator that match the providedFilter
Use this method only if destroying the service is not important, otherwise use
ServiceLocator.getAllServiceHandles(Filter)
This method should also be used with care to avoid classloading a large number of services
- Specified by:
getAllServices
in interfaceServiceLocator
- Parameters:
searchCriteria
- The returned service will match the Filter (in other words, searchCriteria.matches returns true). May not be null- Returns:
- A list of services matching this filter. May not return null, but may return an empty list
- Throws:
MultiException
- if there was an error during service creation
-
getName
Description copied from interface:ServiceLocator
Returns the name of this ServiceLocator- Specified by:
getName
in interfaceServiceLocator
- Returns:
- The name of this ServiceLocator, will not return null
-
getState
Description copied from interface:ServiceLocator
Returns the current state of this service locator. This method will work in all service locator states- Specified by:
getState
in interfaceServiceLocator
- Returns:
- The current state of the service locator
-
shutdown
public void shutdown()Description copied from interface:ServiceLocator
This method will shutdown every service associated with this ServiceLocator. Those services that have a preDestroy shall have their preDestroy called- Specified by:
shutdown
in interfaceServiceLocator
-
create
Description copied from interface:ServiceLocator
This method will analyze the given class, and create it if can. The object created in this way will not be managed by HK2. It is the responsibility of the caller to ensure that any lifecycle this object has is honored- Specified by:
create
in interfaceServiceLocator
- Parameters:
createMe
- The class to create, may not be null- Returns:
- An instance of the object
-
create
Description copied from interface:ServiceLocator
This method will analyze the given class, and create it if can. The object created in this way will not be managed by HK2. It is the responsibility of the caller to ensure that any lifecycle this object has is honored- Specified by:
create
in interfaceServiceLocator
- Parameters:
createMe
- The class to create, may not be nullstrategy
- The name of theClassAnalyzer
that should be used. If null the default analyzer will be used- Returns:
- An instance of the object
-
inject
Description copied from interface:ServiceLocator
This will analyze the given object and inject into its fields and methods. The object injected in this way will not be managed by HK2- Specified by:
inject
in interfaceServiceLocator
- Parameters:
injectMe
- The object to be analyzed and injected into
-
assistedInject
Description copied from interface:ServiceLocator
This will invoke the given method on the given object. The values for the method will either be taken from the params list or will be gotten from this ServiceLocator taking into account all injection resolvers- Specified by:
assistedInject
in interfaceServiceLocator
- Parameters:
injectMe
- The non-null object to inject intomethod
- The non-null method to inject intoparams
- A list of parameter values known by the caller. The indexes in params may not repeat and must be in the valid range of parameters for the passed in method- Returns:
- The return value of the method (null if the method is void type)
-
assistedInject
public Object assistedInject(Object injectMe, Method method, ServiceHandle<?> root, MethodParameter... params) Description copied from interface:ServiceLocator
This will invoke the given method on the given object. The values for the method will either be taken from the params list or will be gotten from this ServiceLocator taking into account all injection resolvers- Specified by:
assistedInject
in interfaceServiceLocator
- Parameters:
injectMe
- The non-null object to inject intomethod
- The non-null method to inject intoroot
- A possibly null ServiceHandle that can be used after this call to destroy any hanging PerLookup instances createdparams
- A list of parameter values known by the caller. The indexes in params may not repeat and must be in the valid range of parameters for the passed in method- Returns:
- The return value of the method (null if the method is void type)
-
inject
Description copied from interface:ServiceLocator
This will analyze the given object and inject into its fields and methods. The object injected in this way will not be managed by HK2- Specified by:
inject
in interfaceServiceLocator
- Parameters:
injectMe
- The object to be analyzed and injected intostrategy
- The name of theClassAnalyzer
that should be used. If null the default analyzer will be used
-
postConstruct
Description copied from interface:ServiceLocator
This will analyze the given object and call the postConstruct method. The object given will not be managed by HK2- Specified by:
postConstruct
in interfaceServiceLocator
- Parameters:
postConstructMe
- The object to postConstruct
-
postConstruct
Description copied from interface:ServiceLocator
This will analyze the given object and call the postConstruct method. The object given will not be managed by HK2- Specified by:
postConstruct
in interfaceServiceLocator
- Parameters:
postConstructMe
- The object to postConstructstrategy
- The name of theClassAnalyzer
that should be used. If null the default analyzer will be used
-
preDestroy
Description copied from interface:ServiceLocator
This will analyze the given object and call the preDestroy method. The object given will not be managed by HK2- Specified by:
preDestroy
in interfaceServiceLocator
- Parameters:
preDestroyMe
- The object to preDestroy
-
preDestroy
Description copied from interface:ServiceLocator
This will analyze the given object and call the preDestroy method. The object given will not be managed by HK2- Specified by:
preDestroy
in interfaceServiceLocator
- Parameters:
preDestroyMe
- The object to preDestroystrategy
- The name of theClassAnalyzer
that should be used. If null the default analyzer will be used
-
createAndInitialize
Creates, injects and postConstructs, all in one- Specified by:
createAndInitialize
in interfaceServiceLocator
- Parameters:
createMe
- The non-null class to create this object from- Returns:
- An instance of the object that has been created, injected and post constructed
-
createAndInitialize
Creates, injects and postConstructs, all in one- Specified by:
createAndInitialize
in interfaceServiceLocator
- Parameters:
createMe
- The non-null class to create this object fromstrategy
- The name of theClassAnalyzer
that should be used. If null the default analyzer will be used- Returns:
- An instance of the object that has been created, injected and post constructed
-
getName
-
igdCacheCompute
-
getEffectiveUnqualified
private Unqualified getEffectiveUnqualified(Unqualified givenUnqualified, boolean isIterable, Annotation[] qualifiers) -
internalGetDescriptor
private <T> ActiveDescriptor<T> internalGetDescriptor(Injectee onBehalfOf, Type contractOrImpl, String name, Unqualified unqualified, boolean isIterable, Annotation... qualifiers) throws MultiException - Throws:
MultiException
-
internalGetDescriptor
private <T> ActiveDescriptor<T> internalGetDescriptor(Injectee onBehalfOf, Type contractOrImpl, String name, Unqualified unqualified, boolean isIterable, boolean calledFromSecondChanceResolveMethod, Annotation... qualifiers) throws MultiException - Throws:
MultiException
-
getServiceHandle
public <T> ServiceHandle<T> getServiceHandle(Class<T> contractOrImpl, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets aServiceHandle
that can be used to get and destroy the service that best matches the given criteria- Specified by:
getServiceHandle
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service definition- Returns:
- Will return the service handle corresponding to the service or null if none were found
- Throws:
MultiException
- if there was an issue during lookup
-
getServiceHandle
public <T> ServiceHandle<T> getServiceHandle(Type contractOrImpl, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets aServiceHandle
that can be used to get and destroy the service that best matches the given criteria- Specified by:
getServiceHandle
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service definition- Returns:
- Will return the service handle corresponding to the service or null if none were found
- Throws:
MultiException
- if there was an issue during lookup
-
getUnqualifiedServiceHandle
<T> ServiceHandle<T> getUnqualifiedServiceHandle(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers) throws MultiException - Throws:
MultiException
-
protectedGetAllServiceHandles
private List<ServiceHandle<?>> protectedGetAllServiceHandles(Type contractOrImpl, Annotation... qualifiers) -
getAllServiceHandles
public <T> List<ServiceHandle<T>> getAllServiceHandles(Class<T> contractOrImpl, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets a list ofServiceHandle
that can be used to get and destroy services associated with descriptors that match the provided criteria- Specified by:
getAllServiceHandles
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service definition- Returns:
- A non-null but possibly empty list of service handles matching the given criteria
- Throws:
MultiException
- if there was an error during service lookup
-
getAllServiceHandles
public List<ServiceHandle<?>> getAllServiceHandles(Type contractOrImpl, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets a list ofServiceHandle
that can be used to get and destroy services associated with descriptors that match the provided criteria- Specified by:
getAllServiceHandles
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service definition- Returns:
- A non-null but possibly empty list of service handles matching the given criteria
- Throws:
MultiException
- if there was an error during service lookup
-
getAllUnqualifiedServiceHandles
List<ServiceHandle<?>> getAllUnqualifiedServiceHandles(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers) throws MultiException - Throws:
MultiException
-
internalGetAllServiceHandles
private List<?> internalGetAllServiceHandles(Type contractOrImpl, Unqualified unqualified, boolean getHandles, boolean isIterable, Annotation... qualifiers) throws MultiException - Throws:
MultiException
-
getServiceHandle
public <T> ServiceHandle<T> getServiceHandle(Class<T> contractOrImpl, String name, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets aServiceHandle
that can be used to get and destroy the service that best matches the given criteria- Specified by:
getServiceHandle
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofname
- The name to use to further qualify the search (may be null, indicating that any name will match)qualifiers
- The set of qualifiers that must match this service definition- Returns:
- Will the service handle for the best service matching the given criteria, or null if no matching service could be found
- Throws:
MultiException
- if there was an error during lookup
-
getServiceHandle
public <T> ServiceHandle<T> getServiceHandle(Type contractOrImpl, String name, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets aServiceHandle
that can be used to get and destroy the service that best matches the given criteria- Specified by:
getServiceHandle
in interfaceServiceLocator
- Parameters:
contractOrImpl
- May not be null, and is the contract or concrete implementation to get the best instance ofname
- The name to use to further qualify the search (may be null, indicating that any name will match)qualifiers
- The set of qualifiers that must match this service definition- Returns:
- Will the service handle for the best service matching the given criteria, or null if no matching service could be found
- Throws:
MultiException
- if there was an error during service lookup
-
getAllServiceHandles
Description copied from interface:ServiceLocator
Gets a list ofServiceHandle
whoseActiveDescriptor
s match the supplied filter. The returnedServiceHandle
s may be used to get or destroy the services associated with the matching descriptors- Specified by:
getAllServiceHandles
in interfaceServiceLocator
- Parameters:
searchCriteria
- A filter to use when determining which descriptors should apply- Returns:
- A non-null but possibly empty list of service handles that match the given filter
- Throws:
MultiException
- if there was an error during service handle creation
-
getAllServiceHandles
public List<ServiceHandle<?>> getAllServiceHandles(Annotation qualifier, Annotation... qualifiers) throws MultiException Description copied from interface:ServiceLocator
Gets a list ofServiceHandle
that can be used to get and destroy services associated with descriptors that match the provided criteria- Specified by:
getAllServiceHandles
in interfaceServiceLocator
- Parameters:
qualifier
- May not be null, and is a qualifier that must match the service definitionqualifiers
- The set of qualifiers that must match this service definition- Returns:
- A non-null but possibly empty list of service handles matching the given criteria
- Throws:
MultiException
- if there was an error during service lookup
-
getInterceptionServices
List<InterceptionService> getInterceptionServices() -
checkConfiguration
Checks the configuration operation before anything happens to the internal data structures.- Parameters:
dci
- The configuration that contains the proposed modifications- Returns:
- A set of descriptors that is being removed fromthe configuration
-
getAllContracts
-
removeConfigurationInternal
-
doTrace
-
addConfigurationInternal
-
reupInjectionResolvers
private void reupInjectionResolvers() -
reupInterceptionServices
private void reupInterceptionServices() -
reupErrorHandlers
private void reupErrorHandlers() -
reupConfigListeners
private void reupConfigListeners() -
reupInstanceListenersHandlers
-
reupClassAnalyzers
private void reupClassAnalyzers() -
reupCache
-
reup
private void reup(List<SystemDescriptor<?>> thingsAdded, boolean instanceListenersModified, boolean injectionResolversModified, boolean errorHandlersModified, boolean classAnalyzersModified, boolean dynamicConfigurationListenersModified, HashSet<String> affectedContracts, boolean interceptionServicesModified) -
getAllChildren
-
callAllConfigurationListeners
-
addConfiguration
-
isInjectAnnotation
-
isInjectAnnotation
-
getInjectionResolver
-
_resolveContext
- Throws:
IllegalStateException
-
resolveContext
- Throws:
IllegalStateException
-
loadClass
-
narrow
private ImmediateResults narrow(ServiceLocator locator, List<SystemDescriptor<?>> candidates, Type requiredType, String name, Injectee injectee, boolean onlyOne, boolean doValidation, NarrowResults cachedResults, Filter filter, Annotation... qualifiers) -
getLocatorId
public long getLocatorId()Description copied from interface:ServiceLocator
This returns the unique locator ID for this locator. The locator ID will be assigned at the time of creation and must be a monotonacally increasing number (starting at zero)- Specified by:
getLocatorId
in interfaceServiceLocator
- Returns:
- The identifier for this service locator
-
getNextServiceId
long getNextServiceId() -
addChild
-
removeChild
-
checkState
private void checkState() -
getAllValidators
-
getDefaultClassAnalyzerName
Description copied from interface:ServiceLocator
Gets the name of the default class analyzer service- Specified by:
getDefaultClassAnalyzerName
in interfaceServiceLocator
- Returns:
- The name of the default class analyzer. Will not return null
-
setDefaultClassAnalyzerName
Description copied from interface:ServiceLocator
Sets the name of the default class analyzer that should be used for allDescriptor
s that return null as their class analyzer. If null is given then the default class analyzer name ofClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME
will be used- Specified by:
setDefaultClassAnalyzerName
in interfaceServiceLocator
- Parameters:
defaultClassAnalyzer
- The possibly null name of the default class analyzer (the class analyzer that will be used if a descriptor has not explicitly set the name of its class analyzer)
-
getDefaultUnqualified
Description copied from interface:ServiceLocator
This returns the defaultUnqualified
annotation that will be put on all injection points that do not have any qualifiers. ThisUnqualified
will not be returned by theInjectee.getUnqualified()
method as it is considered to be the systems defaultUnqualified
annotation. If an injection point has its ownUnqualified
annotation returned fromInjectee.getUnqualified()
then that one takes precedence over this one. Further any injection point that is aIterableProvider
will not have the default unqualified applied to it- Specified by:
getDefaultUnqualified
in interfaceServiceLocator
- Returns:
- The
Unqualified
annotation that will be (virtually) put on injection points that have no qualifiers and no otherUnqualified
annotation. If null then this ServiceLocator has no defaultUnqualified
annotation to be applied
-
setDefaultUnqualified
Description copied from interface:ServiceLocator
This sets the defaultUnqualified
annotation that will be put on all injection points that do not have any qualifiers. ThisUnqualified
will not be returned by theInjectee.getUnqualified()
method as it is considered to be the systems defaultUnqualified
annotation. If an injection point has its ownUnqualified
annotation returned fromInjectee.getUnqualified()
then that one takes precedence over this one. Further any injection point that is aIterableProvider
will not have the default unqualified applied to itThis method may be called at any time, but will only affect lookups and injections that have not yet occurred
- Specified by:
setDefaultUnqualified
in interfaceServiceLocator
- Parameters:
unqualified
- TheUnqualified
annotation that will be (virtually) put on injection points that have no qualifiers and no otherUnqualified
annotation. If null then this ServiceLocator has no defaultUnqualified
annotation to be applied- See Also:
-
getAnalyzer
-
getParent
Description copied from interface:ServiceLocator
Gets the parent service locator for this locator- Specified by:
getParent
in interfaceServiceLocator
- Returns:
- The parent service locator for this locator, or null if this service locator does not have a parent
-
getNeutralContextClassLoader
public boolean getNeutralContextClassLoader()Description copied from interface:ServiceLocator
This returns the value of neutralContextClassLoader. If this value is true then HK2 will ensure that the context class loader on the thread is maintained whenever hk2 calls into user code. If this value is false then the value of the context class loader on the thread may be changed by the code hk2 is calling.When set to false this value is used to increase performance since getting and setting the context class loader can be expensive. However, if the user code being called by hk2 may change the context class loader of the thread, this value should be true to ensure that tricky and hard to find bugs don't arise when this thread is used for other purposes later on
All new ServiceLocator implementation have this value initially set to true
- Specified by:
getNeutralContextClassLoader
in interfaceServiceLocator
- Returns:
- If true hk2 will ensure that the context class loader cannot be changed by user code. If false hk2 will not modify the context class loader of the thread when user code has finished
-
setNeutralContextClassLoader
public void setNeutralContextClassLoader(boolean neutralContextClassLoader) Description copied from interface:ServiceLocator
This sets the value of neutralContextClassLoader. If this value is true then HK2 will ensure that the context class loader on the thread is maintained whenever hk2 calls into user code. If this value is false then the value of the context class loader on the thread may be changed by the code hk2 is calling.When set to false this value is used to increase performance since getting and setting the context class loader can be expensive. However, if the user code being called by hk2 may change the context class loader of the thread, this value should be true to ensure that tricky and hard to find bugs don't arise when this thread is used for other purposes later on
All new ServiceLocator implementation have this value initially set to true
- Specified by:
setNeutralContextClassLoader
in interfaceServiceLocator
- Parameters:
neutralContextClassLoader
- true if hk2 should ensure context class loader neutrality, false if hk2 should not change the context class loader on the thread around user code calls
-
getMe
Used to get the ServiceLocatorImpl in inner classes- Returns:
- This current object
-
hasInjectAnnotation
-
getInjectionResolverForInjectee
-
getClassReflectionHelper
ClassReflectionHelper getClassReflectionHelper() -
getErrorHandlers
LinkedList<ErrorService> getErrorHandlers() -
getPerLocatorUtilities
PerLocatorUtilities getPerLocatorUtilities() -
getNumberOfDescriptors
int getNumberOfDescriptors() -
getNumberOfChildren
int getNumberOfChildren() -
getServiceCacheSize
int getServiceCacheSize() -
getServiceCacheMaximumSize
int getServiceCacheMaximumSize() -
clearServiceCache
void clearServiceCache() -
getReflectionCacheSize
int getReflectionCacheSize() -
clearReflectionCache
void clearReflectionCache() -
unsortIndexes
-
toString
-