Package org.glassfish.hk2.utilities
Class AbstractActiveDescriptor<T>
- java.lang.Object
-
- org.glassfish.hk2.utilities.DescriptorImpl
-
- org.glassfish.hk2.utilities.AbstractActiveDescriptor<T>
-
- Type Parameters:
T
- The type returned from the cache
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,ActiveDescriptor<T>
,Descriptor
,SingleCache<T>
- Direct Known Subclasses:
ActiveDescriptorBuilderImpl.BuiltActiveDescriptor
,AliasDescriptor
,AutoActiveDescriptor
,ConstantActiveDescriptor
,ConstantActiveDescriptor
,CrossOverDescriptor
,OperationDescriptor
public abstract class AbstractActiveDescriptor<T> extends DescriptorImpl implements ActiveDescriptor<T>
This class can be used as a starting point for those writing their own ActiveDescriptor. It also has some helper methods to deal with metadata and adding and removing contracts and qualifiers, which can be helpful when customizing the implementation- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.reflect.Type>
advertisedContracts
private T
cachedValue
private boolean
cacheSet
private static java.util.Set<java.lang.annotation.Annotation>
EMPTY_QUALIFIER_SET
private java.lang.Long
factoryLocatorId
private java.lang.Long
factoryServiceId
private boolean
isReified
private java.util.Set<java.lang.annotation.Annotation>
qualifiers
private java.util.concurrent.locks.Lock
rLock
private java.util.concurrent.locks.ReentrantReadWriteLock
rwLock
private java.lang.Class<? extends java.lang.annotation.Annotation>
scope
private java.lang.annotation.Annotation
scopeAnnotation
private static long
serialVersionUID
For serializationprivate java.util.concurrent.locks.Lock
wLock
-
Constructor Summary
Constructors Modifier Constructor Description AbstractActiveDescriptor()
For serializationprotected
AbstractActiveDescriptor(java.util.Set<java.lang.reflect.Type> advertisedContracts, java.lang.Class<? extends java.lang.annotation.Annotation> scope, java.lang.String name, java.util.Set<java.lang.annotation.Annotation> qualifiers, DescriptorType descriptorType, DescriptorVisibility descriptorVisibility, int ranking, java.lang.Boolean proxy, java.lang.Boolean proxyForSameScope, java.lang.String analyzerName, java.util.Map<java.lang.String,java.util.List<java.lang.String>> metadata)
This constructor must be called with the information about this descriptorprotected
AbstractActiveDescriptor(Descriptor baseDescriptor)
Creates a NON reified ActiveDescriptor based on a copy of the given baseDescriptor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContractType(java.lang.reflect.Type addMe)
Adds an advertised contract to the set of contracts advertised by this descriptorvoid
addQualifierAnnotation(java.lang.annotation.Annotation addMe)
Adds the given string to the list of qualifiersvoid
dispose(T instance)
Disposes this instance.boolean
equals(java.lang.Object o)
This equals matches only if the following fields of the descriptor match: implementation contracts name scope qualifiers descriptorType descriptorVisibility metadata proxiable proxyForSameScope analysisNameT
getCache()
This can be used for scopes that will only every be created once.java.util.Set<java.lang.reflect.Type>
getContractTypes()
The set of types that this ActiveDescriptor must produce.java.lang.Long
getFactoryLocatorId()
If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.java.lang.Long
getFactoryServiceId()
If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.java.util.List<Injectee>
getInjectees()
Returns the full list of Injectees this class has.java.util.Set<java.lang.annotation.Annotation>
getQualifierAnnotations()
The full set of qualifiers that this ActiveDescriptor providesjava.lang.Class<? extends java.lang.annotation.Annotation>
getScopeAnnotation()
Returns the scope that this ActiveDescriptor belongs tojava.lang.annotation.Annotation
getScopeAsAnnotation()
Returns the scope as anAnnotation
implementation that this ActiveDescriptor belongs toint
hashCode()
boolean
isCacheSet()
Returns true if this cache has been setboolean
isReified()
This method returns true if this descriptor has been reified (class loaded).void
releaseCache()
Removes the cached value and makes it such that this cache has not been setboolean
removeContractType(java.lang.reflect.Type removeMe)
Removes an advertised contract from the set of contracts advertised by this descriptorprivate void
removeNamedQualifier()
boolean
removeQualifierAnnotation(java.lang.annotation.Annotation removeMe)
Removes the given qualifier from the list of qualifiersvoid
setCache(T cacheMe)
Sets the value into the cachevoid
setFactoryId(java.lang.Long locatorId, java.lang.Long serviceId)
Sets the locator and serviceId for the factory.void
setImplementationType(java.lang.reflect.Type t)
void
setName(java.lang.String name)
Sets the name of this descriptor.void
setReified(boolean reified)
This method is called to change the state of the reification of this descriptorvoid
setScopeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation)
Sets the scope annotation for this descriptorvoid
setScopeAsAnnotation(java.lang.annotation.Annotation scopeAnnotation)
Sets the scope as anAnnotation
implementation.-
Methods inherited from class org.glassfish.hk2.utilities.DescriptorImpl
addAdvertisedContract, addMetadata, addMetadata, addQualifier, clearMetadata, descriptorEquals, getAdvertisedContracts, getClassAnalysisName, getDescriptorType, getDescriptorVisibility, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, isProxiable, isProxyForSameScope, pretty, readExternal, readObject, removeAdvertisedContract, removeAllMetadata, removeMetadata, removeQualifier, setClassAnalysisName, setDescriptorType, setDescriptorVisibility, setImplementation, setLoader, setLocatorId, setMetadata, setProxiable, setProxyForSameScope, setRanking, setScope, setServiceId, toString, writeExternal, writeObject
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.glassfish.hk2.api.ActiveDescriptor
create, getImplementationClass, getImplementationType
-
Methods inherited from interface org.glassfish.hk2.api.Descriptor
getAdvertisedContracts, getClassAnalysisName, getDescriptorType, getDescriptorVisibility, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, isProxiable, isProxyForSameScope, setRanking
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization- See Also:
- Constant Field Values
-
EMPTY_QUALIFIER_SET
private static final java.util.Set<java.lang.annotation.Annotation> EMPTY_QUALIFIER_SET
-
advertisedContracts
private java.util.Set<java.lang.reflect.Type> advertisedContracts
-
scopeAnnotation
private java.lang.annotation.Annotation scopeAnnotation
-
scope
private java.lang.Class<? extends java.lang.annotation.Annotation> scope
-
qualifiers
private java.util.Set<java.lang.annotation.Annotation> qualifiers
-
factoryServiceId
private java.lang.Long factoryServiceId
-
factoryLocatorId
private java.lang.Long factoryLocatorId
-
isReified
private boolean isReified
-
cacheSet
private transient boolean cacheSet
-
cachedValue
private transient T cachedValue
-
rwLock
private final java.util.concurrent.locks.ReentrantReadWriteLock rwLock
-
rLock
private final java.util.concurrent.locks.Lock rLock
-
wLock
private final java.util.concurrent.locks.Lock wLock
-
-
Constructor Detail
-
AbstractActiveDescriptor
public AbstractActiveDescriptor()
For serialization
-
AbstractActiveDescriptor
protected AbstractActiveDescriptor(Descriptor baseDescriptor)
Creates a NON reified ActiveDescriptor based on a copy of the given baseDescriptor. The values from the baseDescriptor will be copied deeply- Parameters:
baseDescriptor
- The non-null base descriptor to copy values from
-
AbstractActiveDescriptor
protected AbstractActiveDescriptor(java.util.Set<java.lang.reflect.Type> advertisedContracts, java.lang.Class<? extends java.lang.annotation.Annotation> scope, java.lang.String name, java.util.Set<java.lang.annotation.Annotation> qualifiers, DescriptorType descriptorType, DescriptorVisibility descriptorVisibility, int ranking, java.lang.Boolean proxy, java.lang.Boolean proxyForSameScope, java.lang.String analyzerName, java.util.Map<java.lang.String,java.util.List<java.lang.String>> metadata)
This constructor must be called with the information about this descriptor- Parameters:
advertisedContracts
- The contracts that should be advertised by this descriptor (may not be null, but may be empty)scope
- The scope of this descriptor (may not be null)name
- The name of this descriptor (may be null)qualifiers
- The qualifiers of this descriptor (may not be null, but may be empty)ranking
- The ranking for this descriptorproxy
- whether the descriptor should be proxiedproxyForSameScope
- whether or not to proxy this descriptor for other services in the same scopeanalyzerName
- the name of the service used to analyze this classmetadata
- Metadata to add to this descriptor
-
-
Method Detail
-
removeNamedQualifier
private void removeNamedQualifier()
-
setImplementationType
public void setImplementationType(java.lang.reflect.Type t)
-
setName
public void setName(java.lang.String name)
Sets the name of this descriptor. Will remove any existing Named qualifier and add a Named qualifier for this name- Overrides:
setName
in classDescriptorImpl
- Parameters:
name
- The name for this descriptor
-
getCache
public T 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
public void setCache(T cacheMe)
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
-
setReified
public void setReified(boolean reified)
This method is called to change the state of the reification of this descriptor- Parameters:
reified
- true if this descriptor should appear reified, false otherwise
-
getContractTypes
public java.util.Set<java.lang.reflect.Type> 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
-
addContractType
public void addContractType(java.lang.reflect.Type addMe)
Adds an advertised contract to the set of contracts advertised by this descriptor- Parameters:
addMe
- The contract to add. May not be null
-
removeContractType
public boolean removeContractType(java.lang.reflect.Type removeMe)
Removes an advertised contract from the set of contracts advertised by this descriptor- Parameters:
removeMe
- The contract to remove. May not be null- Returns:
- true if removeMe was removed from the set
-
getScopeAsAnnotation
public java.lang.annotation.Annotation 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
-
setScopeAsAnnotation
public void setScopeAsAnnotation(java.lang.annotation.Annotation scopeAnnotation)
Sets the scope as anAnnotation
implementation. This method will also modify the scope as a Class and the underlying scope as a String- Parameters:
scopeAnnotation
- The scope as anAnnotation
. May not be null
-
getScopeAnnotation
public java.lang.Class<? extends java.lang.annotation.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
-
setScopeAnnotation
public void setScopeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation)
Sets the scope annotation for this descriptor- Parameters:
scopeAnnotation
- The non-null scope annotation for this service
-
getQualifierAnnotations
public java.util.Set<java.lang.annotation.Annotation> 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
-
addQualifierAnnotation
public void addQualifierAnnotation(java.lang.annotation.Annotation addMe)
Adds the given string to the list of qualifiers- Parameters:
addMe
- The fully qualified class name of the qualifier to add. May not be null
-
removeQualifierAnnotation
public boolean removeQualifierAnnotation(java.lang.annotation.Annotation removeMe)
Removes the given qualifier from the list of qualifiers- Parameters:
removeMe
- The fully qualifier class name of the qualifier to remove. May not be null- Returns:
- true if the given qualifier was removed
-
getFactoryServiceId
public java.lang.Long 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
public java.lang.Long 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
-
setFactoryId
public void setFactoryId(java.lang.Long locatorId, java.lang.Long serviceId)
Sets the locator and serviceId for the factory. This descriptor must be of type PROVIDE_METHOD- Parameters:
locatorId
- The locatorId of the factory associated with this methodserviceId
- The serviceId of the factory associated with this method
-
getInjectees
public java.util.List<Injectee> 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
-
dispose
public void dispose(T instance)
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
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classDescriptorImpl
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:DescriptorImpl
This equals matches only if the following fields of the descriptor match:- implementation
- contracts
- name
- scope
- qualifiers
- descriptorType
- descriptorVisibility
- metadata
- proxiable
- proxyForSameScope
- analysisName
- Overrides:
equals
in classDescriptorImpl
- Parameters:
o
- The object to compare to this one. May be null (which will result in a false)- Returns:
- true if the descriptors are equal
-
-