Top Inners Fields Constructors Methods
org.jvnet.hk2.internal

public Class ServiceLocatorImpl

extends Object
implements ServiceLocator
Class Inheritance
All Implemented Interfaces
org.glassfish.hk2.api.ServiceLocator
Imports
java.lang.annotation.Annotation, java.lang.reflect.AnnotatedElement, .Method, .ParameterizedType, .Type, java.security.AccessController, .PrivilegedAction, java.util.Arrays, .Collection, .Collections, .HashMap, .HashSet, .Iterator, .LinkedHashSet, .LinkedList, .List, .Map, .Set, .SortedSet, .StringTokenizer, .TreeSet, .WeakHashMap, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicInteger, .AtomicLong, java.util.concurrent.locks.ReentrantLock, .ReentrantReadWriteLock, .ReentrantReadWriteLock.ReadLock, .ReentrantReadWriteLock.WriteLock, org.glassfish.hk2.api.ActiveDescriptor, .ClassAnalyzer, .Context, .Descriptor, .DescriptorVisibility, .DuplicateServiceException, .DynamicConfigurationListener, .ErrorService, .ErrorType, .Filter, .HK2Loader, .IndexedFilter, .Injectee, .InjectionResolver, .InstanceLifecycleListener, .InterceptionService, .IterableProvider, .JustInTimeInjectionResolver, .MethodParameter, .MultiException, .Operation, .PerLookup, .PostConstruct, .PreDestroy, .ServiceHandle, .ServiceLocator, .ServiceLocatorFactory, .ServiceLocatorState, .TwoPhaseResource, .TwoPhaseTransactionData, .Unqualified, .ValidationInformation, .ValidationService, .Validator, org.glassfish.hk2.api.messaging.Topic, org.glassfish.hk2.utilities.BuilderHelper, .InjecteeImpl, .RethrowErrorService, org.glassfish.hk2.utilities.cache.Cache, .CacheKeyFilter, .CacheUtilities, .Computable, .ComputationErrorException, .WeakCARCache, org.glassfish.hk2.utilities.reflection.ClassReflectionHelper, .Logger, .ParameterizedTypeImpl, .ReflectionHelper, org.glassfish.hk2.utilities.reflection.internal.ClassReflectionHelperImpl, jakarta.inject.Named, .Provider, .Singleton

Author
jwells

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private class
private static class

Field Summary

Modifier and TypeField and Description
private final IndexedListData
private ConcurrentHashMap<Class<? extends Annotation>, InjectionResolver<?>>
private final ReentrantLock
private final LinkedHashSet<ValidationService>
private static final String
private static final String
private static final boolean
private static final String
private static final int
private final Map<ServiceLocatorImpl, ServiceLocatorImpl>
private final ReentrantLock
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 volatile Unqualified
pack-priv static final DescriptorComparator
private final HashMap<String, IndexedListData>
private final HashMap<String, IndexedListData>
private final LinkedList<ErrorService>
private static final ServiceHandleComparator
private volatile boolean
private final long
private final WeakCARCache<ServiceLocatorImpl.IgdCacheKey, ServiceLocatorImpl.IgdValue>
private final WeakCARCache<ServiceLocatorImpl.IgdCacheKey, ServiceLocatorImpl.IgdValue>
private final Cache<SystemInjecteeImpl, InjectionResolver<?>>
private final LinkedList<InterceptionService>
private final String
private volatile boolean
private final AtomicLong
private final ServiceLocatorImpl
private final PerLocatorUtilities
private final Context<PerLookup>
private final ReentrantReadWriteLock
private final ReentrantReadWriteLock.ReadLock
private final Context<Singleton>
private static final ReentrantLock
private ServiceLocatorState
private final ReentrantReadWriteLock.WriteLock

Constructor Summary

AccessConstructor and Description
public
ServiceLocatorImpl(String
The name of this locator
name
,
ServiceLocatorImpl
The parent of this locator (may be null)
parent
)

Called by the Generator, and hence must be a public method

Method Summary

Modifier and TypeMethod and Description
private Context<?>
_resolveContext(final Class<? extends Annotation> scope)

private void
pack-priv void
private List<SystemDescriptor<?>>
public Object
assistedInject(Object injectMe, Method method, MethodParameter... params)

Implements org.glassfish.hk2.api.ServiceLocator.assistedInject.

This will invoke the given method on the given object.

public Object
assistedInject(Object injectMe, Method method, ServiceHandle<?> root, MethodParameter... params)

Implements org.glassfish.hk2.api.ServiceLocator.assistedInject.

This will invoke the given method on the given object.

private void
private boolean
callValidate(ValidationService vs, ValidationInformation
The non-null validation
vi
)

Must have read lock held

private ServiceLocatorImpl.CheckConfigurationData

Returns:

A set of descriptors that is being removed fromthe configuration
checkConfiguration
(DynamicConfigurationImpl
The configuration that contains the proposed modifications
dci
)

Checks the configuration operation before anything happens to the internal data structures.

private void
pack-priv void
pack-priv void
public <T> T
create(Class<T> createMe)

Implements org.glassfish.hk2.api.ServiceLocator.create.

This method will analyze the given class, and create it if can.

public <T> T
create(Class<T> createMe, String strategy)

Implements org.glassfish.hk2.api.ServiceLocator.create.

This method will analyze the given class, and create it if can.

public <U> U
createAndInitialize(Class<U> createMe)

Implements org.glassfish.hk2.api.ServiceLocator.createAndInitialize.

Creates, injects and postConstructs, all in one

public <U> U
createAndInitialize(Class<U> createMe, String strategy)

Implements org.glassfish.hk2.api.ServiceLocator.createAndInitialize.

Creates, injects and postConstructs, all in one

private static boolean
private void
private static List<String>
public <T> List<ServiceHandle<T>>
getAllServiceHandles(Class<T> contractOrImpl, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getAllServiceHandles.

Gets a list of ServiceHandle that can be used to get and destroy services associated with descriptors that match the provided criteria

public List<ServiceHandle<?>>
getAllServiceHandles(Type contractOrImpl, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getAllServiceHandles.

Gets a list of ServiceHandle that can be used to get and destroy services associated with descriptors that match the provided criteria

public List<ServiceHandle<?>>
getAllServiceHandles(Filter searchCriteria)

Implements org.glassfish.hk2.api.ServiceLocator.getAllServiceHandles.

Gets a list of ServiceHandle whose ActiveDescriptors match the supplied filter.

public List<ServiceHandle<?>>
getAllServiceHandles(Annotation qualifier, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getAllServiceHandles.

Gets a list of ServiceHandle that can be used to get and destroy services associated with descriptors that match the provided criteria

public <T> List<T>
getAllServices(Class<T> contractOrImpl, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getAllServices.

Gets all services from this locator that implement this contract or have this implementation and have the provided qualifiers

Use this method only if destroying the service is not important, otherwise use ServiceLocator#getAllServiceHandles(Class, Annotation...)

public <T> List<T>
getAllServices(Type contractOrImpl, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getAllServices.

Gets all services from this locator that implement this contract or have this implementation and have the provided qualifiers

Use this method only if destroying the service is not important, otherwise use ServiceLocator#getAllServiceHandles(Type, Annotation...)

public <T> List<T>
getAllServices(Annotation qualifier, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getAllServices.

Gets all services from this locator that have the provided qualifiers

Use this method only if destroying the services is not important, otherwise use ServiceLocator#getAllServiceHandles(Annotation, Annotation...)

public List<?>
getAllServices(Filter searchCriteria)

Implements org.glassfish.hk2.api.ServiceLocator.getAllServices.

Gets all services from this locator that match the provided Filter

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

pack-priv List<ServiceHandle<?>>
getAllUnqualifiedServiceHandles(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers)

private LinkedHashSet<ValidationService>
pack-priv ClassAnalyzer
getAnalyzer(String name, Collector collector)

private static long
public ActiveDescriptor<?>
getBestDescriptor(Filter filter)

Implements org.glassfish.hk2.api.ServiceLocator.getBestDescriptor.

Gets the descriptor that best matches this filter, taking ranking and service id into account

pack-priv ClassReflectionHelper
public String
getDefaultClassAnalyzerName()

Implements org.glassfish.hk2.api.ServiceLocator.getDefaultClassAnalyzerName.

Gets the name of the default class analyzer service

public Unqualified
getDefaultUnqualified()

Implements org.glassfish.hk2.api.ServiceLocator.getDefaultUnqualified.

This returns the default Unqualified annotation that will be put on all injection points that do not have any qualifiers.

private List<SystemDescriptor<?>>
getDescriptors(Filter filter, Injectee onBehalfOf, boolean getParents, boolean doValidation, boolean getLocals)

public List<ActiveDescriptor<?>>
getDescriptors(Filter filter)

Implements org.glassfish.hk2.api.ServiceLocator.getDescriptors.

Gets the list of descriptors that match the given filter

private Unqualified
getEffectiveUnqualified(Unqualified givenUnqualified, boolean isIterable, Annotation[] qualifiers)

pack-priv LinkedList<ErrorService>
public ActiveDescriptor<?>
getInjecteeDescriptor(Injectee injectee)

Implements org.glassfish.hk2.api.ServiceLocator.getInjecteeDescriptor.

This method will first find a descriptor for this injectee, and then reify that descriptor.

pack-priv InjectionResolver<?>
getInjectionResolver(Class<? extends Annotation> annoType)

pack-priv InjectionResolver<?>
pack-priv List<InterceptionService>
public long
getLocatorId()

Implements org.glassfish.hk2.api.ServiceLocator.getLocatorId.

This returns the unique locator ID for this locator.

private ServiceLocatorImpl

Returns:

This current object
getMe
()

Used to get the ServiceLocatorImpl in inner classes

public String
getName()

Implements org.glassfish.hk2.api.ServiceLocator.getName.

Returns the name of this ServiceLocator

private static String
getName(String name, Annotation... qualifiers)

public boolean
getNeutralContextClassLoader()

Implements org.glassfish.hk2.api.ServiceLocator.getNeutralContextClassLoader.

This returns the value of neutralContextClassLoader.

pack-priv long
pack-priv int
pack-priv int
public ServiceLocator
getParent()

Implements org.glassfish.hk2.api.ServiceLocator.getParent.

Gets the parent service locator for this locator

pack-priv PerLocatorUtilities
pack-priv int
public <T> T
getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root)

Implements org.glassfish.hk2.api.ServiceLocator.getService.

Deprecated

This method should be called by code resolving injectee's on behalf of some root service, usually by an implementation of InjectionResolver#resolve(Injectee, ServiceHandle).

public <T> T
getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root, Injectee originalRequest)

Implements org.glassfish.hk2.api.ServiceLocator.getService.

This method should be called by code resolving injectee's on behalf of some root service, usually by an implementation of InjectionResolver#resolve(Injectee, ServiceHandle).

public <T> T
getService(Class<T> contractOrImpl, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getService.

Gets the best service from this locator that implements this contract or has this implementation

Use this method only if destroying the service is not important, otherwise use ServiceLocator#getServiceHandle(Class, Annotation...)

public <T> T
getService(Type contractOrImpl, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getService.

Gets the best service from this locator that implements this contract or has this implementation

Use this method only if destroying the service is not important, otherwise use ServiceLocator#getServiceHandle(Type, Annotation...)

public <T> T
getService(Class<T> contractOrImpl, String name, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getService.

Gets the best service from this locator that implements this contract or has this implementation and has the given name

Use this method only if destroying the service is not important, otherwise use ServiceLocator#getServiceHandle(Class, String, Annotation...)

public <T> T
getService(Type contractOrImpl, String name, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getService.

Gets the best service from this locator that implements this contract or has this implementation and has the given name

Use this method only if destroying the service is not important, otherwise use ServiceLocator#getServiceHandle(Type, String, Annotation...)

pack-priv int
pack-priv int
public <T> ServiceHandle<T>
getServiceHandle(ActiveDescriptor<T> activeDescriptor, Injectee injectee)

Implements org.glassfish.hk2.api.ServiceLocator.getServiceHandle.

Gets a ServiceHandle that can be used to get and destroy the service described by the ActiveDescriptor.

public <T> ServiceHandle<T>
getServiceHandle(ActiveDescriptor<T> activeDescriptor)

Implements org.glassfish.hk2.api.ServiceLocator.getServiceHandle.

Gets a ServiceHandle that can be used to get and destroy the service described by the ActiveDescriptor.

public <T> ServiceHandle<T>
getServiceHandle(Class<T> contractOrImpl, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getServiceHandle.

Gets a ServiceHandle that can be used to get and destroy the service that best matches the given criteria

public <T> ServiceHandle<T>
getServiceHandle(Type contractOrImpl, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getServiceHandle.

Gets a ServiceHandle that can be used to get and destroy the service that best matches the given criteria

public <T> ServiceHandle<T>
getServiceHandle(Class<T> contractOrImpl, String name, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getServiceHandle.

Gets a ServiceHandle that can be used to get and destroy the service that best matches the given criteria

public <T> ServiceHandle<T>
getServiceHandle(Type contractOrImpl, String name, Annotation... qualifiers)

Implements org.glassfish.hk2.api.ServiceLocator.getServiceHandle.

Gets a ServiceHandle that can be used to get and destroy the service that best matches the given criteria

private <T> ServiceHandleImpl<T>
getServiceHandleImpl(ActiveDescriptor<T> activeDescriptor, Injectee injectee)

public ServiceLocatorState
getState()

Implements org.glassfish.hk2.api.ServiceLocator.getState.

Returns the current state of this service locator.

pack-priv <T> T
getUnqualifiedService(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers)

This method is only called from the get of IterableProvider.

pack-priv <T> ServiceHandle<T>
getUnqualifiedServiceHandle(Type contractOrImpl, Unqualified unqualified, boolean isIterable, Annotation... qualifiers)

pack-priv boolean
private ServiceLocatorImpl.IgdValue
public void
inject(Object injectMe)

Implements org.glassfish.hk2.api.ServiceLocator.inject.

This will analyze the given object and inject into its fields and methods.

public void
inject(Object injectMe, String strategy)

Implements org.glassfish.hk2.api.ServiceLocator.inject.

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, Annotation... qualifiers)

private <T> ActiveDescriptor<T>
internalGetDescriptor(Injectee onBehalfOf, Type contractOrImpl, String name, Unqualified unqualified, boolean isIterable, boolean calledFromSecondChanceResolveMethod, Annotation... qualifiers)

private ActiveDescriptor<?>
internalGetInjecteeDescriptor(Injectee injectee, boolean calledFromSecondChanceResolveMethod)

private <T> T
internalGetService(Type contractOrImpl, String name, Unqualified unqualified, Annotation... qualifiers)

private <T> T
internalGetService(Type contractOrImpl, String name, Unqualified unqualified, boolean calledFromSecondChanceResolveMethod, Annotation... qualifiers)

private <T> ServiceHandleImpl<T>
internalGetServiceHandle(ActiveDescriptor<T> activeDescriptor, Type requestedType, Injectee originalRequest)

pack-priv boolean
pack-priv boolean
isInjectAnnotation(Annotation annotation, boolean isConstructor)

public boolean
isShutdown()

Implements org.glassfish.hk2.api.ServiceLocator.isShutdown.

Returns whether the state of this service locator is shutdown.

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)

public void
postConstruct(Object postConstructMe)

Implements org.glassfish.hk2.api.ServiceLocator.postConstruct.

This will analyze the given object and call the postConstruct method.

public void
postConstruct(Object postConstructMe, String strategy)

Implements org.glassfish.hk2.api.ServiceLocator.postConstruct.

This will analyze the given object and call the postConstruct method.

public void
preDestroy(Object preDestroyMe)

Implements org.glassfish.hk2.api.ServiceLocator.preDestroy.

This will analyze the given object and call the preDestroy method.

public void
preDestroy(Object preDestroyMe, String strategy)

Implements org.glassfish.hk2.api.ServiceLocator.preDestroy.

This will analyze the given object and call the preDestroy method.

private List<ServiceHandle<?>>
protectedGetAllServiceHandles(final Type contractOrImpl, final Annotation... qualifiers)

private <T> List<T>
protectedGetAllServices(final Type contractOrImpl, final Annotation... qualifiers)

private List<ActiveDescriptor<?>>
public ActiveDescriptor<?>
reifyDescriptor(Descriptor descriptor, Injectee injectee)

Implements org.glassfish.hk2.api.ServiceLocator.reifyDescriptor.

Converts a descriptor to an ActiveDescriptor.

public ActiveDescriptor<?>
reifyDescriptor(Descriptor descriptor)

Implements org.glassfish.hk2.api.ServiceLocator.reifyDescriptor.

Converts a descriptor to an ActiveDescriptor.

private void
private void
pack-priv 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
reupCache(HashSet<String> affectedContracts)

private void
private void
private void
private void
private void
private void
private ActiveDescriptor<?>
public void
setDefaultClassAnalyzerName(String defaultClassAnalyzer)

Implements org.glassfish.hk2.api.ServiceLocator.setDefaultClassAnalyzerName.

Sets the name of the default class analyzer that should be used for all Descriptors that return null as their class analyzer.

public void
setDefaultUnqualified(Unqualified unqualified)

Implements org.glassfish.hk2.api.ServiceLocator.setDefaultUnqualified.

This sets the default Unqualified annotation that will be put on all injection points that do not have any qualifiers.

public void
setNeutralContextClassLoader(boolean neutralContextClassLoader)

Implements org.glassfish.hk2.api.ServiceLocator.setNeutralContextClassLoader.

This sets the value of neutralContextClassLoader.

public void
shutdown()

Implements org.glassfish.hk2.api.ServiceLocator.shutdown.

This method will shutdown every service associated with this ServiceLocator.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv int
unsortIndexes(int newRank, SystemDescriptor<?> desc, Set<IndexedListData> myLists)

private boolean

Returns:

true if every validator returned true
validate
(SystemDescriptor<?>
The descriptor to validate
descriptor
,
Injectee
The fella who is being validated (or null)
onBehalfOf
,
Filter filter)

Must be called under lock

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait