Class ReferenceCountedContext
- All Implemented Interfaces:
AlterableContext,Context
AlterableContext that
destroys a contextual instance
when its thread-specific reference count drops to zero or less than
zero.
A contextual instance's thread-specific reference count is
incremented when either the get(Contextual) or get(Contextual, CreationalContext) method is called. It is
decremented when the obtained instance is passed to the decrementReferenceCount(Contextual) method, which is indirectly
and solely responsible for that instance's ultimate removal from
this ReferenceCountedContext.
Internally, the destroy(Contextual) method simply calls
decrementReferenceCount(Contextual).
Thread Safety
Instances of this class are safe for concurrent use by multiple threads.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionintDeprecated, for removal: This API element is subject to removal in a future version.Decrements the reference count of the contextual instance, if any, associated with the combination of the current thread and the suppliedContextual, destroying the instance if and only if the reference count becomes less than or equal to zero, and returns the resulting reference count.intdecrementReferenceCount(Contextual<?> c, int amount) Deprecated, for removal: This API element is subject to removal in a future version.Decrements the reference count of the contextual instance, if any, associated with the combination of the current thread and the suppliedContextual, destroying the instance if and only if the reference count becomes less than or equal to zero, and returns the resulting reference count.voiddestroy(Contextual<?> contextual) Deprecated, for removal: This API element is subject to removal in a future version.Calls thedecrementReferenceCount(Contextual)method with the suppliedContextual, destroying it if and only if its thread-specific reference count becomes less than or equal to zero.<T> Tget(Contextual<T> contextual) Deprecated, for removal: This API element is subject to removal in a future version.Returns the contextual instance associated with the current thread and the suppliedContextual, ornullif no such contextual instance exists.<T> Tget(Contextual<T> contextual, CreationalContext<T> cc) Deprecated, for removal: This API element is subject to removal in a future version.Returns the contextual instance associated with the current thread and the suppliedContextual, creating it if necessary.static ReferenceCountedContextgetInstanceFrom(BeanManager beanManager) Deprecated, for removal: This API element is subject to removal in a future version.Returns the soleReferenceCountedContextthat is registered with the suppliedBeanManager.intgetReferenceCount(Contextual<?> c) Deprecated, for removal: This API element is subject to removal in a future version.Returns the reference count of the contextual instance, if any, associated with the combination of the current thread and the suppliedContextual.Class<? extends Annotation> getScope()Deprecated, for removal: This API element is subject to removal in a future version.ReturnsReferenceCounted.classwhen invoked.booleanisActive()Deprecated, for removal: This API element is subject to removal in a future version.Returnstruewhen invoked.
-
Method Details
-
decrementReferenceCount
Deprecated, for removal: This API element is subject to removal in a future version.Decrements the reference count of the contextual instance, if any, associated with the combination of the current thread and the suppliedContextual, destroying the instance if and only if the reference count becomes less than or equal to zero, and returns the resulting reference count.- Parameters:
c- theContextualwhose instance's reference count should be decremented; may benullin which case no action will be taken and0will be returned- Returns:
- the resulting reference count
- See Also:
-
decrementReferenceCount
Deprecated, for removal: This API element is subject to removal in a future version.Decrements the reference count of the contextual instance, if any, associated with the combination of the current thread and the suppliedContextual, destroying the instance if and only if the reference count becomes less than or equal to zero, and returns the resulting reference count.Most users will never have to call this method.
- Parameters:
c- theContextualwhose instance's reference count should be decremented; may benullin which case no action will be taken and0will be returnedamount- the amount by which to decrement; must be greater than or (trivially) equal to0- Returns:
- the resulting reference count
- Throws:
IllegalArgumentException- ifamountis less than0- See Also:
-
getReferenceCount
Deprecated, for removal: This API element is subject to removal in a future version.Returns the reference count of the contextual instance, if any, associated with the combination of the current thread and the suppliedContextual.Most users will never have to call this method.
This method never returns a negative number.
- Parameters:
c- theContextualwhose instance's reference count should be returned; may benullin which case0will be returned- Returns:
- the reference count in question; never a negative number
-
destroy
Deprecated, for removal: This API element is subject to removal in a future version.Calls thedecrementReferenceCount(Contextual)method with the suppliedContextual, destroying it if and only if its thread-specific reference count becomes less than or equal to zero.- Specified by:
destroyin interfaceAlterableContext- Parameters:
contextual- theContextualto destroy; may benullin which case no action will be taken- See Also:
-
get
Deprecated, for removal: This API element is subject to removal in a future version.Returns the contextual instance associated with the current thread and the suppliedContextual, ornullif no such contextual instance exists.- Specified by:
getin interfaceContext- Parameters:
contextual- theContextualin question; may benullin which casenullwil be returned- Returns:
- the contextual instance associated with the current
thread and the supplied
Contextual, ornull
-
get
Deprecated, for removal: This API element is subject to removal in a future version.Returns the contextual instance associated with the current thread and the suppliedContextual, creating it if necessary.- Specified by:
getin interfaceContext- Parameters:
contextual- theContextualin question; may benullin which casenullwil be returnedcc- aCreationalContextthat will hold dependent instances; may benull- Returns:
- the contextual instance associated with the current
thread and the supplied
Contextual; may strictly speaking benullbut normally is not
-
getScope
Deprecated, for removal: This API element is subject to removal in a future version.ReturnsReferenceCounted.classwhen invoked.- Specified by:
getScopein interfaceContext- Returns:
ReferenceCounted.classin all cases
-
isActive
public boolean isActive()Deprecated, for removal: This API element is subject to removal in a future version.Returnstruewhen invoked. -
getInstanceFrom
Deprecated, for removal: This API element is subject to removal in a future version.Returns the soleReferenceCountedContextthat is registered with the suppliedBeanManager.Strictly speaking, this method may return
nullif theReferenceCountedExtensionhas been deliberately disabled and hence has not had a chance to install aReferenceCountedContext. In all normal usage this method will not returnnull.- Parameters:
beanManager- theBeanManagerwhoseReferenceCountedContextshould be returned; must not benull- Returns:
- a
ReferenceCountedContext, ornullin exceptionally rare situations - Throws:
NullPointerException- ifbeanManagerisnull
-