Class SystemDescriptor<T>
- Type Parameters:
T
- The type from the cache
- All Implemented Interfaces:
ActiveDescriptor<T>
,Descriptor
,SingleCache<T>
,Closeable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ActiveDescriptor
<T> private final Descriptor
private T
private final Object
private boolean
private boolean
private Long
private Long
private final Long
private Class
<?> private Type
private final List
<InstanceLifecycleListener> private final Set
<IndexedListData> private boolean
private Set
<Annotation> private boolean
private boolean
private Class
<? extends Annotation> private Annotation
private final ServiceLocatorImpl
private int
private final HashMap
<ValidationService, Boolean> -
Constructor Summary
ConstructorsConstructorDescriptionSystemDescriptor
(Descriptor baseDescriptor, boolean requiresDeepCopy, ServiceLocatorImpl locator, Long serviceId) -
Method Summary
Modifier and TypeMethodDescription(package private) void
addList
(IndexedListData indexedList) private void
boolean
close()
Idempotent close method.create
(ServiceHandle<?> root) Creates an instance of the ActiveDescriptor.void
Disposes this instance.boolean
Returns the base class name of the contracts that this service describes.getCache()
This can be used for scopes that will only every be created once.Returns the name of theClassAnalyzer
service that should be used to discover the constructors, initialization methods, field and postConstruct and preDestory methods.The set of types that this ActiveDescriptor must produce.Returns CLASS if this is a class descriptor and FACTORY if this is a descriptor describing a factory for a type, in which case the implClass should point to the implementation class of the factoryReturns the visibility of this descriptor.private ActiveDescriptor
<?> getFactoryDescriptor
(Method provideMethod, Type factoryProvidedType, ServiceLocatorImpl locator, Collector collector) If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.Returns the fully qualified class name of the implementation class.Class
<?> The implementation class that should be used to generate new instances of this descriptor.If known the Type of the implementation.Returns the full list of Injectees this class has.This returns the loader that should be used when classloading this descriptor.This returns the id of the ServiceLocator which this descriptor is registered with.Returns all of the metadata associated that this object should be registered with or looked up bygetName()
The name of this descriptor.(package private) Class
<?> The full set of qualifiers that this ActiveDescriptor providesReturns all of the annotation classes that this object should be registered with or looked up byint
Returns the ranking of this descriptor.getScope()
Returns the fully qualified class name of the scope annotation that should be associated with this descriptor.Class
<? extends Annotation> Returns the scope that this ActiveDescriptor belongs toReturns the scope as anAnnotation
implementation that this ActiveDescriptor belongs toThis returns the unique identifier for this descriptor.(package private) int
int
hashCode()
private void
internalReify
(Class<?> implClass, Collector collector) The service locator must hold its lock for this cal(package private) void
boolean
Returns true if this cache has been setboolean
isClosed()
Returns true if the instance has been closedIf this returns true then the system will create a proxy for instances of this descriptor.This value determines whether or not this service should be proxied when being injected into other services of the same scope.boolean
This method returns true if this descriptor has been reified (class loaded).(package private) boolean
isValidating
(ValidationService service) Gets the decision of the filter from this service.(package private) void
void
Removes the cached value and makes it such that this cache has not been set(package private) void
removeList
(IndexedListData indexedList) (package private) void
reupInstanceListeners
(List<InstanceLifecycleListener> listeners) void
Sets the value into the cache(package private) void
setFactoryIds
(Long factoryLocatorId, Long factoryServiceId) int
setRanking
(int ranking) Returns the ranking of this descriptor.(package private) int
setRankWithLock
(int ranking) (package private) void
setSingletonGeneration
(int gen) toString()
-
Field Details
-
baseDescriptor
-
id
-
activeDescriptor
-
sdLocator
-
reified
private volatile boolean reified -
reifying
private boolean reifying -
preAnalyzed
private boolean preAnalyzed -
closed
private volatile boolean closed -
cacheLock
-
cacheSet
private boolean cacheSet -
cachedValue
-
implClass
-
scopeAnnotation
-
scope
-
contracts
-
qualifiers
-
creator
-
factoryLocatorId
-
factoryServiceId
-
implType
-
validationServiceCache
-
instanceListeners
-
myLists
-
singletonGeneration
private int singletonGeneration
-
-
Constructor Details
-
SystemDescriptor
SystemDescriptor(Descriptor baseDescriptor, boolean requiresDeepCopy, ServiceLocatorImpl locator, Long serviceId)
-
-
Method Details
-
getImplementation
Description copied from interface:Descriptor
Returns the fully qualified class name of the implementation class. If this is a factory descriptor then this will return the fully qualified name of the class implementing the factory interface.- Specified by:
getImplementation
in interfaceDescriptor
- Returns:
- Might return null in some cases, but will usually return the fully qualified class name of the implementation class or of the factory class for this descriptor
-
getAdvertisedContracts
Description copied from interface:Descriptor
Returns the base class name of the contracts that this service describes. If the contract is a paramterized type this will return the raw class. If this service can be looked up by its implementation class then the name of the implementation class must also be found in this list- Specified by:
getAdvertisedContracts
in interfaceDescriptor
- Returns:
- Will never return null, but may return an empty set. The returned strings are the fully qualified class names of contracts the predicate describes
-
getScope
Description copied from interface:Descriptor
Returns the fully qualified class name of the scope annotation that should be associated with this descriptor.- Specified by:
getScope
in interfaceDescriptor
- Returns:
- If this returns null then this descriptor is assumed to be in the default scope, which is PerLookup
-
getName
Description copied from interface:Descriptor
The name of this descriptor. Note that if this returns not null then there must also be the Named qualifier in the set of qualifiers with the same value- Specified by:
getName
in interfaceDescriptor
- Returns:
- The name of this descriptor, or null if there is no name associated with this qualifier
-
getQualifiers
Description copied from interface:Descriptor
Returns all of the annotation classes that this object should be registered with or looked up by- Specified by:
getQualifiers
in interfaceDescriptor
- Returns:
- Never returns null, but may return an empty set. The set of fully qualified class names that are annotations that this object must have
-
getDescriptorType
Description copied from interface:Descriptor
Returns CLASS if this is a class descriptor and FACTORY if this is a descriptor describing a factory for a type, in which case the implClass should point to the implementation class of the factory- Specified by:
getDescriptorType
in interfaceDescriptor
- Returns:
- Either CLASS or PROVIDE_METHOD
-
getDescriptorVisibility
Description copied from interface:Descriptor
Returns the visibility of this descriptor.If the visibility is NORMAL then this descriptor may be seen by all children locators of the locator in which this descriptor is bound
If the visibility is LOCAL then this descriptor may only be seen by the servcie locator in which it is bound, and in none of the children of that locator
- Specified by:
getDescriptorVisibility
in interfaceDescriptor
- Returns:
- Either NORMAL or LOCAL
-
getMetadata
Description copied from interface:Descriptor
Returns all of the metadata associated that this object should be registered with or looked up by- Specified by:
getMetadata
in interfaceDescriptor
- Returns:
- Never returns null, but may return an empty set. The set of metadata associated with the object. The values in the returned map will never be null, and will always have at least one member
-
getLoader
Description copied from interface:Descriptor
This returns the loader that should be used when classloading this descriptor. If this method returns null then the class will be loaded with the classloader of the Injectee if there is one, or with the classloader that loaded HK2 itself; failing that the context class loader on the thread will be tried.- Specified by:
getLoader
in interfaceDescriptor
- Returns:
- An HK2Loader that can be used to load this descriptor, or null if the default classloading algorithm should be used
-
getRanking
public int getRanking()Description copied from interface:Descriptor
Returns the ranking of this descriptor. Rankings with higher value will be considered "better" than rankings of lower value. Descriptors with the same ranking will be returned in the reverse ServiceID order (in other words, the least service ID is considered "better" than any higher service ID).- Specified by:
getRanking
in interfaceDescriptor
- Returns:
- the ranking that should be associated with this descriptor
-
isProxiable
Description copied from interface:Descriptor
If this returns true then the system will create a proxy for instances of this descriptor. As with all proxies, the proxy created will also implement theProxyCtl
interfaceIt is an error for this method to return true if the scope that this descriptor is in is
Unproxiable
(such as PerLookup).- Specified by:
isProxiable
in interfaceDescriptor
- Returns:
- true if this descriptor must be proxied, false if this
descriptor must NOT be proxied (even if it is in an Unproxiable scope)
and null if this descriptor should take its proxiable status from
the scope it is in (i.e., it will only be proxied if the scope is
marked
Proxiable
)
-
isProxyForSameScope
Description copied from interface:Descriptor
This value determines whether or not this service should be proxied when being injected into other services of the same scope. If a scope is proxiable then it will have a default setting for whether or not its services should be proxied when being injected into the same scope. If this method returns null then the default setting for the scope will be used. Otherwise the value returned will determine whether or not this service will be proxied when being injected into a service of the same scope.- Specified by:
isProxyForSameScope
in interfaceDescriptor
- Returns:
- null if this descriptor should use the default ProxyForSameScope value for the scope. If it returns true then this service will be proxied even when being injected into the same scope. If it returns false then this service will NOT be proxied when being injected into the same scope (i.e., it cannot be used for lazy initialization of the service when injected into the same scope)
-
getClassAnalysisName
Description copied from interface:Descriptor
Returns the name of theClassAnalyzer
service that should be used to discover the constructors, initialization methods, field and postConstruct and preDestory methods. If null the default implementation will be used. Will be ignored for descriptors that are not automatically analyzed by hk2- Specified by:
getClassAnalysisName
in interfaceDescriptor
- Returns:
- the possibly null name of the ClassAnalysis service that should be used to analyze the class represented by this descriptor. If null then the HK2 default analysis will be performed
-
setRanking
public int setRanking(int ranking) Description copied from interface:Descriptor
Returns the ranking of this descriptor. Rankings with higher value will be considered "better" than rankings of lower value. Descriptors with the same ranking will be returned in the reverse ServiceID order (in other words, the least service ID is considered "better" than any higher service ID).The ranking of a service may change at any time during the life of the descriptor
- Specified by:
setRanking
in interfaceDescriptor
- Parameters:
ranking
- The new ranking this descriptor should have- Returns:
- the previous ranking that this descriptor had
-
setRankWithLock
int setRankWithLock(int ranking) -
addList
-
removeList
-
getServiceId
Description copied from interface:Descriptor
This returns the unique identifier for this descriptor. This field will be ignored upon binding, and will then be assigned by the system. However, this field can be set on search operations, in which case this search will match exactly one Provider in the system.- Specified by:
getServiceId
in interfaceDescriptor
- Returns:
- The service id for this object. Note that this field may return null if this is an initial bind, as it is not the responsibility of the binder to set this value. If this returns non-null on a bind operation the return value will be ignored
-
getCache
Description copied from interface:SingleCache
This can be used for scopes that will only every be created once. The returned value must have been set previously with setCache. If this is called when isCacheSet is false will result in a RuntimeException- Specified by:
getCache
in interfaceSingleCache<T>
- Returns:
- A value cached with this ActiveDescriptor
-
isCacheSet
public boolean isCacheSet()Description copied from interface:SingleCache
Returns true if this cache has been set- Specified by:
isCacheSet
in interfaceSingleCache<T>
- Returns:
- true if there is a currently cached value, false otherwise
-
setCache
Description copied from interface:SingleCache
Sets the value into the cache- Specified by:
setCache
in interfaceSingleCache<T>
- Parameters:
cacheMe
- A single value that can be cached in this active descriptor
-
releaseCache
public void releaseCache()Description copied from interface:SingleCache
Removes the cached value and makes it such that this cache has not been set- Specified by:
releaseCache
in interfaceSingleCache<T>
-
isReified
public boolean isReified()Description copied from interface:ActiveDescriptor
This method returns true if this descriptor has been reified (class loaded). If this method returns false then the other methods in this interface will throw an IllegalStateException. Once this method returns true it may be- Specified by:
isReified
in interfaceActiveDescriptor<T>
- Returns:
- true if this descriptor has been reified, false otherwise
-
getImplementationClass
Description copied from interface:ActiveDescriptor
The implementation class that should be used to generate new instances of this descriptor.If the class returned is a Factory, then the factory is used to create instances. In this case the system will get an instance of the factory and use it to create the instances
- Specified by:
getImplementationClass
in interfaceActiveDescriptor<T>
- Returns:
- The class that directly implements the contract types, or the class that is the factory for an object that implements the contract types
-
getImplementationType
Description copied from interface:ActiveDescriptor
If known the Type of the implementation. If unknown will return the same asActiveDescriptor.getImplementationClass()
- Specified by:
getImplementationType
in interfaceActiveDescriptor<T>
- Returns:
- The type of the implementation or the implementation class
-
getContractTypes
Description copied from interface:ActiveDescriptor
The set of types that this ActiveDescriptor must produce. These types may be Classes or ParameterizedTypes, and may be no other subclass of Type- Specified by:
getContractTypes
in interfaceActiveDescriptor<T>
- Returns:
- the set of types this ActiveDescriptor must implement or extend
-
getScopeAsAnnotation
Description copied from interface:ActiveDescriptor
Returns the scope as anAnnotation
implementation that this ActiveDescriptor belongs to- Specified by:
getScopeAsAnnotation
in interfaceActiveDescriptor<T>
- Returns:
- The scope of this ActiveDescriptor as an
Annotation
-
getScopeAnnotation
Description copied from interface:ActiveDescriptor
Returns the scope that this ActiveDescriptor belongs to- Specified by:
getScopeAnnotation
in interfaceActiveDescriptor<T>
- Returns:
- The scope of this ActiveDescriptor
-
getQualifierAnnotations
Description copied from interface:ActiveDescriptor
The full set of qualifiers that this ActiveDescriptor provides- Specified by:
getQualifierAnnotations
in interfaceActiveDescriptor<T>
- Returns:
- The set of annotations that this ActiveDescriptor provides
-
getInjectees
Description copied from interface:ActiveDescriptor
Returns the full list of Injectees this class has. These references will be resolved prior to the class being constructed, even if these injectees are field or method injectees.If this descriptor is describing a factory created type then this list must have zero length
- Specified by:
getInjectees
in interfaceActiveDescriptor<T>
- Returns:
- Will not return null, but may return an empty list. The set of Injectees that must be resolved before this ActiveDescriptor can be constructed
-
getFactoryServiceId
Description copied from interface:ActiveDescriptor
If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service. Otherwise this method should return null- Specified by:
getFactoryServiceId
in interfaceActiveDescriptor<T>
- Returns:
- The service ID of the associated factory service
-
getFactoryLocatorId
Description copied from interface:ActiveDescriptor
If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service. Otherwise this method should return null- Specified by:
getFactoryLocatorId
in interfaceActiveDescriptor<T>
- Returns:
- The locator ID of the associated factory service
-
setFactoryIds
-
invokeInstanceListeners
-
create
Description copied from interface:ActiveDescriptor
Creates an instance of the ActiveDescriptor. All of the Injectee's must be created prior to instantiation, and associated with the ExtendedProvider so that they can be destroyed properly- Specified by:
create
in interfaceActiveDescriptor<T>
- Parameters:
root
- The root service handle, which can be used to associated all the PerLookup objects with this creation- Returns:
- An instance of this ActiveDescriptor
-
dispose
Description copied from interface:ActiveDescriptor
Disposes this instance. All the PerLookup objects that were created for this instance will be destroyed after this object has been destroyed- Specified by:
dispose
in interfaceActiveDescriptor<T>
- Parameters:
instance
- The instance to destroy
-
checkState
private void checkState() -
getFactoryDescriptor
private ActiveDescriptor<?> getFactoryDescriptor(Method provideMethod, Type factoryProvidedType, ServiceLocatorImpl locator, Collector collector) -
reify
-
internalReify
The service locator must hold its lock for this cal- Parameters:
implClass
- The impl class to reifycollector
- An error collector for errors
-
getLocatorId
Description copied from interface:Descriptor
This returns the id of the ServiceLocator which this descriptor is registered with. Returns null if this descriptor is not yet registered with a ServiceLocator- Specified by:
getLocatorId
in interfaceDescriptor
- Returns:
- The id of the ServiceLocator this Descriptor is registered with, or null if this Descriptor is not registered with a ServiceLocator
-
close
public boolean close()Description copied from interface:Closeable
Idempotent close method. Returns true if the instance had already been closed -
isClosed
public boolean isClosed()Description copied from interface:Closeable
Returns true if the instance has been closed -
isValidating
Gets the decision of the filter from this service. May use a cache- Parameters:
service
- The service to get the isValidating decision from- Returns:
- true if this validation service should validate this descriptor
-
reupInstanceListeners
-
getPreAnalyzedClass
Class<?> getPreAnalyzedClass() -
getSingletonGeneration
int getSingletonGeneration() -
setSingletonGeneration
void setSingletonGeneration(int gen) -
hashCode
public int hashCode() -
equals
-
toString
-