public class ServiceLocatorImpl extends java.lang.Object implements ServiceLocator
| Modifier and Type | Class and Description |
|---|---|
private static class |
ServiceLocatorImpl.CheckConfigurationData |
private static class |
ServiceLocatorImpl.IgdCacheKey |
private class |
ServiceLocatorImpl.IgdValue |
private static class |
ServiceLocatorImpl.UnqualifiedIndexedFilter |
| Modifier and Type | Field and Description |
|---|---|
private IndexedListData |
allDescriptors |
private java.util.concurrent.ConcurrentHashMap<java.lang.Class<? extends java.lang.annotation.Annotation>,InjectionResolver<?>> |
allResolvers |
private java.util.LinkedHashSet<ValidationService> |
allValidators |
private static java.lang.String |
BIND_TRACING_PATTERN |
private static java.lang.String |
BIND_TRACING_PATTERN_PROPERTY |
private static boolean |
BIND_TRACING_STACKS |
private static java.lang.String |
BIND_TRACING_STACKS_PROPERTY |
private static int |
CACHE_SIZE |
private java.util.Map<ServiceLocatorImpl,ServiceLocatorImpl> |
children |
private java.lang.Object |
classAnalyzerLock |
private java.util.HashMap<java.lang.String,ClassAnalyzer> |
classAnalyzers |
private ClassReflectionHelper |
classReflectionHelper |
private java.util.LinkedList<ServiceHandle<?>> |
configListeners |
private Cache<java.lang.Class<? extends java.lang.annotation.Annotation>,Context<?>> |
contextCache |
private static long |
currentLocatorId |
private java.lang.String |
defaultClassAnalyzer |
private Unqualified |
defaultUnqualified |
(package private) static DescriptorComparator |
DESCRIPTOR_COMPARATOR |
private java.util.HashMap<java.lang.String,IndexedListData> |
descriptorsByAdvertisedContract |
private java.util.HashMap<java.lang.String,IndexedListData> |
descriptorsByName |
private java.util.LinkedList<ErrorService> |
errorHandlers |
private static ServiceHandleComparator |
HANDLE_COMPARATOR |
private boolean |
hasInterceptionServices |
private long |
id |
private WeakCARCache<ServiceLocatorImpl.IgdCacheKey,ServiceLocatorImpl.IgdValue> |
igashCache |
private WeakCARCache<ServiceLocatorImpl.IgdCacheKey,ServiceLocatorImpl.IgdValue> |
igdCache |
private Cache<SystemInjecteeImpl,InjectionResolver<?>> |
injecteeToResolverCache |
private java.util.LinkedList<InterceptionService> |
interceptionServices |
private java.lang.String |
locatorName |
private boolean |
neutralContextClassLoader |
private java.util.concurrent.atomic.AtomicLong |
nextServiceId |
private ServiceLocatorImpl |
parent |
private PerLocatorUtilities |
perLocatorUtilities |
private Context<PerLookup> |
perLookupContext |
private java.util.concurrent.locks.ReentrantReadWriteLock |
readWriteLock |
private java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock |
rLock |
private Context<javax.inject.Singleton> |
singletonContext |
private static java.lang.Object |
sLock |
private ServiceLocatorState |
state |
private java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
wLock |
| Constructor and Description |
|---|
ServiceLocatorImpl(java.lang.String name,
ServiceLocatorImpl parent)
Called by the Generator, and hence must be a public method
|
| Modifier and Type | Method and Description |
|---|---|
private Context<?> |
_resolveContext(java.lang.Class<? extends java.lang.annotation.Annotation> scope) |
private void |
addChild(ServiceLocatorImpl child) |
(package private) void |
addConfiguration(DynamicConfigurationImpl dci) |
private java.util.List<SystemDescriptor<?>> |
addConfigurationInternal(DynamicConfigurationImpl dci) |
private void |
callAllConfigurationListeners(java.util.List<ServiceHandle<?>> allListeners) |
private boolean |
callValidate(ValidationService vs,
ValidationInformation vi)
Must have read lock held
|
private ServiceLocatorImpl.CheckConfigurationData |
checkConfiguration(DynamicConfigurationImpl dci)
Checks the configuration operation before anything happens to the internal data structures.
|
private void |
checkState() |
(package private) void |
clearReflectionCache() |
(package private) void |
clearServiceCache() |
<T> T |
create(java.lang.Class<T> createMe)
This method will analyze the given class, and create it if can.
|
<T> T |
create(java.lang.Class<T> createMe,
java.lang.String strategy)
This method will analyze the given class, and create it if can.
|
<U> U |
createAndInitialize(java.lang.Class<U> createMe)
Creates, injects and postConstructs, all in one
|
<U> U |
createAndInitialize(java.lang.Class<U> createMe,
java.lang.String strategy)
Creates, injects and postConstructs, all in one
|
private static boolean |
doTrace(ActiveDescriptor<?> desc) |
private void |
getAllChildren(java.util.LinkedList<ServiceLocatorImpl> allMyChildren) |
private static java.util.List<java.lang.String> |
getAllContracts(ActiveDescriptor<?> desc) |
java.util.List<ServiceHandle<?>> |
getAllServiceHandles(java.lang.annotation.Annotation qualifier,
java.lang.annotation.Annotation... qualifiers)
Gets a list of
ServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteria |
<T> java.util.List<ServiceHandle<T>> |
getAllServiceHandles(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets a list of
ServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteria |
java.util.List<ServiceHandle<?>> |
getAllServiceHandles(Filter searchCriteria)
Gets a list of
ServiceHandle whose ActiveDescriptors match
the supplied filter. |
java.util.List<ServiceHandle<?>> |
getAllServiceHandles(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets a list of
ServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteria |
<T> java.util.List<T> |
getAllServices(java.lang.annotation.Annotation qualifier,
java.lang.annotation.Annotation... qualifiers)
Gets all services from this locator that have the provided qualifiers
|
<T> java.util.List<T> |
getAllServices(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets all services from this locator that implement this contract or have this
implementation and have the provided qualifiers
|
java.util.List<?> |
getAllServices(Filter searchCriteria)
Gets all services from this locator that match the provided
Filter |
<T> java.util.List<T> |
getAllServices(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets all services from this locator that implement this contract or have this
implementation and have the provided qualifiers
|
(package private) java.util.List<ServiceHandle<?>> |
getAllUnqualifiedServiceHandles(java.lang.reflect.Type contractOrImpl,
Unqualified unqualified,
boolean isIterable,
java.lang.annotation.Annotation... qualifiers) |
private java.util.LinkedHashSet<ValidationService> |
getAllValidators() |
(package private) ClassAnalyzer |
getAnalyzer(java.lang.String name,
Collector collector) |
private static long |
getAndIncrementLocatorId() |
ActiveDescriptor<?> |
getBestDescriptor(Filter filter)
Gets the descriptor that best matches this filter, taking ranking
and service id into account
|
(package private) ClassReflectionHelper |
getClassReflectionHelper() |
java.lang.String |
getDefaultClassAnalyzerName()
Gets the name of the default class analyzer service
|
Unqualified |
getDefaultUnqualified()
This returns the default
Unqualified annotation that will be
put on all injection points that do not have any qualifiers. |
java.util.List<ActiveDescriptor<?>> |
getDescriptors(Filter filter)
Gets the list of descriptors that match the given filter
|
private java.util.List<SystemDescriptor<?>> |
getDescriptors(Filter filter,
Injectee onBehalfOf,
boolean getParents,
boolean doValidation,
boolean getLocals) |
private Unqualified |
getEffectiveUnqualified(Unqualified givenUnqualified,
boolean isIterable,
java.lang.annotation.Annotation[] qualifiers) |
(package private) java.util.LinkedList<ErrorService> |
getErrorHandlers() |
ActiveDescriptor<?> |
getInjecteeDescriptor(Injectee injectee)
This method will first find a descriptor for this injectee, and then
reify that descriptor.
|
(package private) InjectionResolver<?> |
getInjectionResolver(java.lang.Class<? extends java.lang.annotation.Annotation> annoType) |
(package private) InjectionResolver<?> |
getInjectionResolverForInjectee(SystemInjecteeImpl injectee) |
(package private) java.util.List<InterceptionService> |
getInterceptionServices() |
long |
getLocatorId()
This returns the unique locator ID for this locator.
|
private ServiceLocatorImpl |
getMe()
Used to get the ServiceLocatorImpl in inner classes
|
java.lang.String |
getName()
Returns the name of this ServiceLocator
|
private static java.lang.String |
getName(java.lang.String name,
java.lang.annotation.Annotation... qualifiers) |
boolean |
getNeutralContextClassLoader()
This returns the value of neutralContextClassLoader.
|
(package private) long |
getNextServiceId() |
(package private) int |
getNumberOfChildren() |
(package private) int |
getNumberOfDescriptors() |
ServiceLocator |
getParent()
Gets the parent service locator for this locator
|
(package private) PerLocatorUtilities |
getPerLocatorUtilities() |
(package private) int |
getReflectionCacheSize() |
<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 of
InjectionResolver.resolve(Injectee, ServiceHandle). |
<T> T |
getService(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets the best service from this locator that implements
this contract or has this implementation
|
<T> T |
getService(java.lang.Class<T> contractOrImpl,
java.lang.String name,
java.lang.annotation.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(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets the best service from this locator that implements
this contract or has this implementation
|
<T> T |
getService(java.lang.reflect.Type contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
Gets the best service from this locator that implements
this contract or has this implementation and has the given
name
|
(package private) int |
getServiceCacheMaximumSize() |
(package private) int |
getServiceCacheSize() |
<T> ServiceHandle<T> |
getServiceHandle(ActiveDescriptor<T> activeDescriptor)
Gets a
ServiceHandle that can be used to get and destroy the service
described by the ActiveDescriptor. |
<T> ServiceHandle<T> |
getServiceHandle(ActiveDescriptor<T> activeDescriptor,
Injectee injectee)
Gets a
ServiceHandle that can be used to get and destroy the service
described by the ActiveDescriptor. |
<T> ServiceHandle<T> |
getServiceHandle(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets a
ServiceHandle that can be used to get and destroy the
service that best matches the given criteria |
<T> ServiceHandle<T> |
getServiceHandle(java.lang.Class<T> contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
Gets a
ServiceHandle that can be used to get and destroy the
service that best matches the given criteria |
<T> ServiceHandle<T> |
getServiceHandle(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets a
ServiceHandle that can be used to get and destroy the
service that best matches the given criteria |
<T> ServiceHandle<T> |
getServiceHandle(java.lang.reflect.Type contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
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) |
ServiceLocatorState |
getState()
Returns the current state of this service locator.
|
(package private) <T> T |
getUnqualifiedService(java.lang.reflect.Type contractOrImpl,
Unqualified unqualified,
boolean isIterable,
java.lang.annotation.Annotation... qualifiers) |
(package private) <T> ServiceHandle<T> |
getUnqualifiedServiceHandle(java.lang.reflect.Type contractOrImpl,
Unqualified unqualified,
boolean isIterable,
java.lang.annotation.Annotation... qualifiers) |
(package private) boolean |
hasInjectAnnotation(java.lang.reflect.AnnotatedElement annotated) |
private ServiceLocatorImpl.IgdValue |
igdCacheCompute(ServiceLocatorImpl.IgdCacheKey key) |
void |
inject(java.lang.Object injectMe)
This will analyze the given object and inject into its fields and methods.
|
void |
inject(java.lang.Object injectMe,
java.lang.String strategy)
This will analyze the given object and inject into its fields and methods.
|
private java.util.List<?> |
internalGetAllServiceHandles(java.lang.reflect.Type contractOrImpl,
Unqualified unqualified,
boolean getHandles,
boolean isIterable,
java.lang.annotation.Annotation... qualifiers) |
private <T> ActiveDescriptor<T> |
internalGetDescriptor(Injectee onBehalfOf,
java.lang.reflect.Type contractOrImpl,
java.lang.String name,
Unqualified unqualified,
boolean isIterable,
java.lang.annotation.Annotation... qualifiers) |
private <T> ActiveDescriptor<T> |
internalGetDescriptor(Injectee onBehalfOf,
java.lang.reflect.Type contractOrImpl,
java.lang.String name,
Unqualified unqualified,
boolean isIterable,
boolean calledFromSecondChanceResolveMethod,
java.lang.annotation.Annotation... qualifiers) |
private ActiveDescriptor<?> |
internalGetInjecteeDescriptor(Injectee injectee,
boolean calledFromSecondChanceResolveMethod) |
private <T> T |
internalGetService(java.lang.reflect.Type contractOrImpl,
java.lang.String name,
Unqualified unqualified,
java.lang.annotation.Annotation... qualifiers) |
private <T> ServiceHandleImpl<T> |
internalGetServiceHandle(ActiveDescriptor<T> activeDescriptor,
java.lang.reflect.Type requestedType,
Injectee originalRequest) |
(package private) boolean |
isInjectAnnotation(java.lang.annotation.Annotation annotation) |
(package private) boolean |
isInjectAnnotation(java.lang.annotation.Annotation annotation,
boolean isConstructor) |
private java.lang.Class<?> |
loadClass(Descriptor descriptor,
Injectee injectee) |
private ImmediateResults |
narrow(ServiceLocator locator,
java.util.List<SystemDescriptor<?>> candidates,
java.lang.reflect.Type requiredType,
java.lang.String name,
Injectee injectee,
boolean onlyOne,
boolean doValidation,
NarrowResults cachedResults,
Filter filter,
java.lang.annotation.Annotation... qualifiers) |
void |
postConstruct(java.lang.Object postConstructMe)
This will analyze the given object and call the postConstruct method.
|
void |
postConstruct(java.lang.Object postConstructMe,
java.lang.String strategy)
This will analyze the given object and call the postConstruct method.
|
void |
preDestroy(java.lang.Object preDestroyMe)
This will analyze the given object and call the preDestroy method.
|
void |
preDestroy(java.lang.Object preDestroyMe,
java.lang.String strategy)
This will analyze the given object and call the preDestroy method.
|
private java.util.List<ServiceHandle<?>> |
protectedGetAllServiceHandles(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers) |
private <T> java.util.List<T> |
protectedGetAllServices(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers) |
private java.util.List<ActiveDescriptor<?>> |
protectedGetDescriptors(Filter filter) |
ActiveDescriptor<?> |
reifyDescriptor(Descriptor descriptor)
Converts a descriptor to an ActiveDescriptor.
|
ActiveDescriptor<?> |
reifyDescriptor(Descriptor descriptor,
Injectee injectee)
Converts a descriptor to an ActiveDescriptor.
|
private void |
removeChild(ServiceLocatorImpl child) |
private void |
removeConfigurationInternal(java.util.List<SystemDescriptor<?>> unbinds) |
(package private) Context<?> |
resolveContext(java.lang.Class<? extends java.lang.annotation.Annotation> scope) |
private void |
reup(java.util.List<SystemDescriptor<?>> thingsAdded,
boolean instanceListenersModified,
boolean injectionResolversModified,
boolean errorHandlersModified,
boolean classAnalyzersModified,
boolean dynamicConfigurationListenersModified,
java.util.HashSet<java.lang.String> affectedContracts,
boolean interceptionServicesModified) |
private void |
reupCache(java.util.HashSet<java.lang.String> affectedContracts) |
private void |
reupClassAnalyzers() |
private void |
reupConfigListeners() |
private void |
reupErrorHandlers() |
private void |
reupInjectionResolvers() |
private void |
reupInstanceListenersHandlers(java.util.Collection<SystemDescriptor<?>> checkList) |
private void |
reupInterceptionServices() |
private ActiveDescriptor<?> |
secondChanceResolve(Injectee injectee) |
void |
setDefaultClassAnalyzerName(java.lang.String defaultClassAnalyzer)
Sets the name of the default class analyzer that should be used for all
Descriptors that return null as their class analyzer. |
void |
setDefaultUnqualified(Unqualified unqualified)
This sets the default
Unqualified 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.
|
java.lang.String |
toString() |
(package private) int |
unsortIndexes(int newRank,
SystemDescriptor<?> desc,
java.util.Set<IndexedListData> myLists) |
private boolean |
validate(SystemDescriptor<?> descriptor,
Injectee onBehalfOf,
Filter filter)
Must be called under lock
|
private static final java.lang.String BIND_TRACING_PATTERN_PROPERTY
private static final java.lang.String BIND_TRACING_PATTERN
private static final java.lang.String BIND_TRACING_STACKS_PROPERTY
private static boolean BIND_TRACING_STACKS
private static final int CACHE_SIZE
private static final java.lang.Object sLock
private static long currentLocatorId
static final DescriptorComparator DESCRIPTOR_COMPARATOR
private static final ServiceHandleComparator HANDLE_COMPARATOR
private final java.util.concurrent.locks.ReentrantReadWriteLock readWriteLock
private final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock wLock
private final java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock rLock
private final java.util.concurrent.atomic.AtomicLong nextServiceId
private final java.lang.String locatorName
private final long id
private final ServiceLocatorImpl parent
private volatile boolean neutralContextClassLoader
private final ClassReflectionHelper classReflectionHelper
private final PerLocatorUtilities perLocatorUtilities
private final IndexedListData allDescriptors
private final java.util.HashMap<java.lang.String,IndexedListData> descriptorsByAdvertisedContract
private final java.util.HashMap<java.lang.String,IndexedListData> descriptorsByName
private final Context<javax.inject.Singleton> singletonContext
private final java.util.LinkedHashSet<ValidationService> allValidators
private final java.util.LinkedList<ErrorService> errorHandlers
private final java.util.LinkedList<ServiceHandle<?>> configListeners
private volatile boolean hasInterceptionServices
private final java.util.LinkedList<InterceptionService> interceptionServices
private final Cache<java.lang.Class<? extends java.lang.annotation.Annotation>,Context<?>> contextCache
private final java.util.Map<ServiceLocatorImpl,ServiceLocatorImpl> children
private final java.lang.Object classAnalyzerLock
private final java.util.HashMap<java.lang.String,ClassAnalyzer> classAnalyzers
private java.lang.String defaultClassAnalyzer
private volatile Unqualified defaultUnqualified
private java.util.concurrent.ConcurrentHashMap<java.lang.Class<? extends java.lang.annotation.Annotation>,InjectionResolver<?>> allResolvers
private final Cache<SystemInjecteeImpl,InjectionResolver<?>> injecteeToResolverCache
private ServiceLocatorState state
private final WeakCARCache<ServiceLocatorImpl.IgdCacheKey,ServiceLocatorImpl.IgdValue> igdCache
private final WeakCARCache<ServiceLocatorImpl.IgdCacheKey,ServiceLocatorImpl.IgdValue> igashCache
public ServiceLocatorImpl(java.lang.String name,
ServiceLocatorImpl parent)
name - The name of this locatorparent - The parent of this locator (may be null)private static long getAndIncrementLocatorId()
private boolean callValidate(ValidationService vs, ValidationInformation vi)
vi - The non-null validationprivate boolean validate(SystemDescriptor<?> descriptor, Injectee onBehalfOf, Filter filter)
descriptor - The descriptor to validateonBehalfOf - The fella who is being validated (or null)private java.util.List<SystemDescriptor<?>> getDescriptors(Filter filter, Injectee onBehalfOf, boolean getParents, boolean doValidation, boolean getLocals)
private java.util.List<ActiveDescriptor<?>> protectedGetDescriptors(Filter filter)
public java.util.List<ActiveDescriptor<?>> getDescriptors(Filter filter)
ServiceLocatorgetDescriptors in interface ServiceLocatorfilter - A filter to use when determining which services should applypublic ActiveDescriptor<?> getBestDescriptor(Filter filter)
ServiceLocatorgetBestDescriptor in interface ServiceLocatorfilter - The non-null filter to use to retrieve the best descriptorpublic ActiveDescriptor<?> reifyDescriptor(Descriptor descriptor, Injectee injectee) throws MultiException
ServiceLocatorreifyDescriptor in interface ServiceLocatordescriptor - 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 unknownHK2LoaderMultiException - if there were errors when loading or analyzing the classpublic ActiveDescriptor<?> reifyDescriptor(Descriptor descriptor) throws MultiException
ServiceLocatorreifyDescriptor in interface ServiceLocatordescriptor - The descriptor to convert, may not be nullHK2LoaderMultiException - if there were errors when loading or analyzing the classprivate ActiveDescriptor<?> secondChanceResolve(Injectee injectee)
private ActiveDescriptor<?> internalGetInjecteeDescriptor(Injectee injectee, boolean calledFromSecondChanceResolveMethod)
public ActiveDescriptor<?> getInjecteeDescriptor(Injectee injectee) throws MultiException
ServiceLocator
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
getInjecteeDescriptor in interface ServiceLocatorinjectee - the injection point for whom to find the ActiveDescriptorMultiException - if there were errors when loading or analyzing the classpublic <T> ServiceHandle<T> getServiceHandle(ActiveDescriptor<T> activeDescriptor, Injectee injectee) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy the service
described by the ActiveDescriptor. The injectee may be used to discover
the proper classloader to use when attempting to reify the ActiveDescriptorgetServiceHandle in interface ServiceLocatoractiveDescriptor - The descriptor for which to create a ServiceHandle.
May not be nullinjectee - The injectee on behalf of whom this service is being injected. May
be null if the injectee is unknownServiceHandle that may be used to create or destroy the service
associated with this ActiveDescriptorMultiException - if there was an error during service handle creationprivate <T> ServiceHandleImpl<T> getServiceHandleImpl(ActiveDescriptor<T> activeDescriptor, Injectee injectee) throws MultiException
MultiExceptionpublic <T> ServiceHandle<T> getServiceHandle(ActiveDescriptor<T> activeDescriptor) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy the service
described by the ActiveDescriptor.getServiceHandle in interface ServiceLocatoractiveDescriptor - The descriptor for which to create a ServiceHandle.
May not be nullServiceHandle that may be used to create or destroy the service
associated with this ActiveDescriptorMultiException - if there was an error during service handle creationprivate <T> ServiceHandleImpl<T> internalGetServiceHandle(ActiveDescriptor<T> activeDescriptor, java.lang.reflect.Type requestedType, Injectee originalRequest)
@Deprecated public <T> T getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root) throws MultiException
ServiceLocatorInjectionResolver.resolve(Injectee, ServiceHandle). In
this way the objects associated with the root object can be destroyed in the proper sequencegetService in interface ServiceLocatoractiveDescriptor - The descriptor whose service to createroot - The ultimate parent of this service creation. May be nullMultiException - if there was an error during service creationpublic <T> T getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root, Injectee originalRequest) throws MultiException
ServiceLocatorInjectionResolver.resolve(Injectee, ServiceHandle). In
this way the objects associated with the root object can be destroyed in the proper sequencegetService in interface ServiceLocatoractiveDescriptor - The descriptor whose service to createroot - The ultimate parent of this service creation. May be nulloriginalRequest - The injectee passed into the InjectionResolver.resolve(Injectee, ServiceHandle) if known,
null otherwiseMultiException - if there was an error during service creationpublic <T> T getService(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
ServiceLocator
Use this method only if destroying the service is not important,
otherwise use ServiceLocator.getServiceHandle(Class, Annotation...)
getService in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic <T> T getService(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
ServiceLocator
Use this method only if destroying the service is not important,
otherwise use ServiceLocator.getServiceHandle(Type, Annotation...)
getService in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic <T> T getService(java.lang.Class<T> contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
ServiceLocator
Use this method only if destroying the service is not important,
otherwise use ServiceLocator.getServiceHandle(Class, String, Annotation...)
getService in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic <T> T getService(java.lang.reflect.Type contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
ServiceLocator
Use this method only if destroying the service is not important,
otherwise use ServiceLocator.getServiceHandle(Type, String, Annotation...)
getService in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationprivate <T> T internalGetService(java.lang.reflect.Type contractOrImpl,
java.lang.String name,
Unqualified unqualified,
java.lang.annotation.Annotation... qualifiers)
<T> T getUnqualifiedService(java.lang.reflect.Type contractOrImpl,
Unqualified unqualified,
boolean isIterable,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
MultiExceptionprivate <T> java.util.List<T> protectedGetAllServices(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
public <T> java.util.List<T> getAllServices(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
ServiceLocator
Use this method only if destroying the service is not important,
otherwise use ServiceLocator.getAllServiceHandles(Class, Annotation...)
getAllServices in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic <T> java.util.List<T> getAllServices(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
ServiceLocator
Use this method only if destroying the service is not important,
otherwise use ServiceLocator.getAllServiceHandles(Type, Annotation...)
getAllServices in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic <T> java.util.List<T> getAllServices(java.lang.annotation.Annotation qualifier,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
ServiceLocator
Use this method only if destroying the services is not important,
otherwise use ServiceLocator.getAllServiceHandles(Annotation, Annotation...)
getAllServices in interface ServiceLocatorqualifier - May not be null, and is a qualifier that must
match the service definitionqualifiers - The set of qualifiers that must match this service
definitionMultiException - if there was an error during service creationpublic java.util.List<?> getAllServices(Filter searchCriteria) throws MultiException
ServiceLocatorFilter
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
getAllServices in interface ServiceLocatorsearchCriteria - The returned service will match the Filter
(in other words, searchCriteria.matches returns true). May not
be nullMultiException - if there was an error during service creationpublic java.lang.String getName()
ServiceLocatorgetName in interface ServiceLocatorpublic ServiceLocatorState getState()
ServiceLocatorgetState in interface ServiceLocatorpublic void shutdown()
ServiceLocatorshutdown in interface ServiceLocatorpublic <T> T create(java.lang.Class<T> createMe)
ServiceLocatorcreate in interface ServiceLocatorcreateMe - The class to create, may not be nullpublic <T> T create(java.lang.Class<T> createMe,
java.lang.String strategy)
ServiceLocatorcreate in interface ServiceLocatorcreateMe - The class to create, may not be nullstrategy - The name of the ClassAnalyzer that should be used. If
null the default analyzer will be usedpublic void inject(java.lang.Object injectMe)
ServiceLocatorinject in interface ServiceLocatorinjectMe - The object to be analyzed and injected intopublic void inject(java.lang.Object injectMe,
java.lang.String strategy)
ServiceLocatorinject in interface ServiceLocatorinjectMe - The object to be analyzed and injected intostrategy - The name of the ClassAnalyzer that should be used. If
null the default analyzer will be usedpublic void postConstruct(java.lang.Object postConstructMe)
ServiceLocatorpostConstruct in interface ServiceLocatorpostConstructMe - The object to postConstructpublic void postConstruct(java.lang.Object postConstructMe,
java.lang.String strategy)
ServiceLocatorpostConstruct in interface ServiceLocatorpostConstructMe - The object to postConstructstrategy - The name of the ClassAnalyzer that should be used. If
null the default analyzer will be usedpublic void preDestroy(java.lang.Object preDestroyMe)
ServiceLocatorpreDestroy in interface ServiceLocatorpreDestroyMe - The object to preDestroypublic void preDestroy(java.lang.Object preDestroyMe,
java.lang.String strategy)
ServiceLocatorpreDestroy in interface ServiceLocatorpreDestroyMe - The object to preDestroystrategy - The name of the ClassAnalyzer that should be used. If
null the default analyzer will be usedpublic <U> U createAndInitialize(java.lang.Class<U> createMe)
createAndInitialize in interface ServiceLocatorcreateMe - The non-null class to create this object frompublic <U> U createAndInitialize(java.lang.Class<U> createMe,
java.lang.String strategy)
createAndInitialize in interface ServiceLocatorcreateMe - The non-null class to create this object fromstrategy - The name of the ClassAnalyzer that should be used. If
null the default analyzer will be usedprivate static java.lang.String getName(java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
private ServiceLocatorImpl.IgdValue igdCacheCompute(ServiceLocatorImpl.IgdCacheKey key)
private Unqualified getEffectiveUnqualified(Unqualified givenUnqualified, boolean isIterable, java.lang.annotation.Annotation[] qualifiers)
private <T> ActiveDescriptor<T> internalGetDescriptor(Injectee onBehalfOf, java.lang.reflect.Type contractOrImpl, java.lang.String name, Unqualified unqualified, boolean isIterable, java.lang.annotation.Annotation... qualifiers) throws MultiException
MultiExceptionprivate <T> ActiveDescriptor<T> internalGetDescriptor(Injectee onBehalfOf, java.lang.reflect.Type contractOrImpl, java.lang.String name, Unqualified unqualified, boolean isIterable, boolean calledFromSecondChanceResolveMethod, java.lang.annotation.Annotation... qualifiers) throws MultiException
MultiExceptionpublic <T> ServiceHandle<T> getServiceHandle(java.lang.Class<T> contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy the
service that best matches the given criteriagetServiceHandle in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic <T> ServiceHandle<T> getServiceHandle(java.lang.reflect.Type contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy the
service that best matches the given criteriagetServiceHandle in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creation<T> ServiceHandle<T> getUnqualifiedServiceHandle(java.lang.reflect.Type contractOrImpl, Unqualified unqualified, boolean isIterable, java.lang.annotation.Annotation... qualifiers) throws MultiException
MultiExceptionprivate java.util.List<ServiceHandle<?>> protectedGetAllServiceHandles(java.lang.reflect.Type contractOrImpl, java.lang.annotation.Annotation... qualifiers)
public <T> java.util.List<ServiceHandle<T>> getAllServiceHandles(java.lang.Class<T> contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteriagetAllServiceHandles in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic java.util.List<ServiceHandle<?>> getAllServiceHandles(java.lang.reflect.Type contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteriagetAllServiceHandles in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationjava.util.List<ServiceHandle<?>> getAllUnqualifiedServiceHandles(java.lang.reflect.Type contractOrImpl, Unqualified unqualified, boolean isIterable, java.lang.annotation.Annotation... qualifiers) throws MultiException
MultiExceptionprivate java.util.List<?> internalGetAllServiceHandles(java.lang.reflect.Type contractOrImpl,
Unqualified unqualified,
boolean getHandles,
boolean isIterable,
java.lang.annotation.Annotation... qualifiers)
throws MultiException
MultiExceptionpublic <T> ServiceHandle<T> getServiceHandle(java.lang.Class<T> contractOrImpl, java.lang.String name, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy the
service that best matches the given criteriagetServiceHandle in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic <T> ServiceHandle<T> getServiceHandle(java.lang.reflect.Type contractOrImpl, java.lang.String name, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy the
service that best matches the given criteriagetServiceHandle in interface ServiceLocatorcontractOrImpl - 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
definitionMultiException - if there was an error during service creationpublic java.util.List<ServiceHandle<?>> getAllServiceHandles(Filter searchCriteria) throws MultiException
ServiceLocatorServiceHandle whose ActiveDescriptors match
the supplied filter. The returned ServiceHandles may be used to
get or destroy the services associated with the matching descriptorsgetAllServiceHandles in interface ServiceLocatorsearchCriteria - A filter to use when determining which descriptors should applyMultiException - if there was an error during service handle creationpublic java.util.List<ServiceHandle<?>> getAllServiceHandles(java.lang.annotation.Annotation qualifier, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceLocatorServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteriagetAllServiceHandles in interface ServiceLocatorqualifier - May not be null, and is a qualifier that must
match the service definitionqualifiers - The set of qualifiers that must match this service
definitionMultiException - if there was an error during service creationjava.util.List<InterceptionService> getInterceptionServices()
private ServiceLocatorImpl.CheckConfigurationData checkConfiguration(DynamicConfigurationImpl dci)
dci - The configuration that contains the proposed modificationsprivate static java.util.List<java.lang.String> getAllContracts(ActiveDescriptor<?> desc)
private void removeConfigurationInternal(java.util.List<SystemDescriptor<?>> unbinds)
private static boolean doTrace(ActiveDescriptor<?> desc)
private java.util.List<SystemDescriptor<?>> addConfigurationInternal(DynamicConfigurationImpl dci)
private void reupInjectionResolvers()
private void reupInterceptionServices()
private void reupErrorHandlers()
private void reupConfigListeners()
private void reupInstanceListenersHandlers(java.util.Collection<SystemDescriptor<?>> checkList)
private void reupClassAnalyzers()
private void reupCache(java.util.HashSet<java.lang.String> affectedContracts)
private void reup(java.util.List<SystemDescriptor<?>> thingsAdded, boolean instanceListenersModified, boolean injectionResolversModified, boolean errorHandlersModified, boolean classAnalyzersModified, boolean dynamicConfigurationListenersModified, java.util.HashSet<java.lang.String> affectedContracts, boolean interceptionServicesModified)
private void getAllChildren(java.util.LinkedList<ServiceLocatorImpl> allMyChildren)
private void callAllConfigurationListeners(java.util.List<ServiceHandle<?>> allListeners)
void addConfiguration(DynamicConfigurationImpl dci)
boolean isInjectAnnotation(java.lang.annotation.Annotation annotation)
boolean isInjectAnnotation(java.lang.annotation.Annotation annotation,
boolean isConstructor)
InjectionResolver<?> getInjectionResolver(java.lang.Class<? extends java.lang.annotation.Annotation> annoType)
private Context<?> _resolveContext(java.lang.Class<? extends java.lang.annotation.Annotation> scope) throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionContext<?> resolveContext(java.lang.Class<? extends java.lang.annotation.Annotation> scope) throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionprivate java.lang.Class<?> loadClass(Descriptor descriptor, Injectee injectee)
private ImmediateResults narrow(ServiceLocator locator, java.util.List<SystemDescriptor<?>> candidates, java.lang.reflect.Type requiredType, java.lang.String name, Injectee injectee, boolean onlyOne, boolean doValidation, NarrowResults cachedResults, Filter filter, java.lang.annotation.Annotation... qualifiers)
public long getLocatorId()
ServiceLocatorgetLocatorId in interface ServiceLocatorlong getNextServiceId()
private void addChild(ServiceLocatorImpl child)
private void removeChild(ServiceLocatorImpl child)
private void checkState()
private java.util.LinkedHashSet<ValidationService> getAllValidators()
public java.lang.String getDefaultClassAnalyzerName()
ServiceLocatorgetDefaultClassAnalyzerName in interface ServiceLocatorpublic void setDefaultClassAnalyzerName(java.lang.String defaultClassAnalyzer)
ServiceLocatorDescriptors that return null as their class analyzer. If null is given
then the default class analyzer name of ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME
will be usedsetDefaultClassAnalyzerName in interface ServiceLocatordefaultClassAnalyzer - 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)public Unqualified getDefaultUnqualified()
ServiceLocatorUnqualified annotation that will be
put on all injection points that do not have any qualifiers. This
Unqualified will not be returned by the Injectee.getUnqualified()
method as it is considered to be the systems default Unqualified
annotation. If an injection point has its own Unqualified
annotation returned from Injectee.getUnqualified() then that
one takes precedence over this one. Further any injection point that
is a javax.inject.IterableProvider will not have the default
unqualified applied to itgetDefaultUnqualified in interface ServiceLocatorUnqualified annotation that will be (virtually) put
on injection points that have no qualifiers and no other Unqualified
annotation. If null then this ServiceLocator has no default Unqualified
annotation to be appliedpublic void setDefaultUnqualified(Unqualified unqualified)
ServiceLocatorUnqualified annotation that will be
put on all injection points that do not have any qualifiers. This
Unqualified will not be returned by the Injectee.getUnqualified()
method as it is considered to be the systems default Unqualified
annotation. If an injection point has its own Unqualified
annotation returned from Injectee.getUnqualified() then that
one takes precedence over this one. Further any injection point that
is a javax.inject.IterableProvider will not have the default
unqualified applied to it
This method may be called at any time, but will only affect lookups and injections that have not yet occurred
setDefaultUnqualified in interface ServiceLocatorunqualified - The Unqualified annotation that will be (virtually) put
on injection points that have no qualifiers and no other Unqualified
annotation. If null then this ServiceLocator has no default Unqualified
annotation to be appliedorg.glassfish.hk2.utilities.UnqualifiedImpl}ClassAnalyzer getAnalyzer(java.lang.String name, Collector collector)
public ServiceLocator getParent()
ServiceLocatorgetParent in interface ServiceLocatorpublic boolean getNeutralContextClassLoader()
ServiceLocatorWhen 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
getNeutralContextClassLoader in interface ServiceLocatorpublic void setNeutralContextClassLoader(boolean neutralContextClassLoader)
ServiceLocatorWhen 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
setNeutralContextClassLoader in interface ServiceLocatorneutralContextClassLoader - 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 callsprivate ServiceLocatorImpl getMe()
boolean hasInjectAnnotation(java.lang.reflect.AnnotatedElement annotated)
InjectionResolver<?> getInjectionResolverForInjectee(SystemInjecteeImpl injectee)
ClassReflectionHelper getClassReflectionHelper()
java.util.LinkedList<ErrorService> getErrorHandlers()
PerLocatorUtilities getPerLocatorUtilities()
int getNumberOfDescriptors()
int getNumberOfChildren()
int getServiceCacheSize()
int getServiceCacheMaximumSize()
void clearServiceCache()
int getReflectionCacheSize()
void clearReflectionCache()
int unsortIndexes(int newRank,
SystemDescriptor<?> desc,
java.util.Set<IndexedListData> myLists)
public java.lang.String toString()
toString in class java.lang.Object