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 TypeMethodDescriptionint
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.int
decrementReferenceCount
(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.void
destroy
(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> T
get
(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
, ornull
if no such contextual instance exists.<T> T
get
(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 ReferenceCountedContext
getInstanceFrom
(BeanManager beanManager) Deprecated, for removal: This API element is subject to removal in a future version.Returns the soleReferenceCountedContext
that is registered with the suppliedBeanManager
.int
getReferenceCount
(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.class
when invoked.boolean
isActive()
Deprecated, for removal: This API element is subject to removal in a future version.Returnstrue
when 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
- theContextual
whose instance's reference count should be decremented; may benull
in which case no action will be taken and0
will 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
- theContextual
whose instance's reference count should be decremented; may benull
in which case no action will be taken and0
will be returnedamount
- the amount by which to decrement; must be greater than or (trivially) equal to0
- Returns:
- the resulting reference count
- Throws:
IllegalArgumentException
- ifamount
is 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
- theContextual
whose instance's reference count should be returned; may benull
in which case0
will 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:
destroy
in interfaceAlterableContext
- Parameters:
contextual
- theContextual
to destroy; may benull
in 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
, ornull
if no such contextual instance exists.- Specified by:
get
in interfaceContext
- Parameters:
contextual
- theContextual
in question; may benull
in which casenull
wil 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:
get
in interfaceContext
- Parameters:
contextual
- theContextual
in question; may benull
in which casenull
wil be returnedcc
- aCreationalContext
that will hold dependent instances; may benull
- Returns:
- the contextual instance associated with the current
thread and the supplied
Contextual
; may strictly speaking benull
but normally is not
-
getScope
Deprecated, for removal: This API element is subject to removal in a future version.ReturnsReferenceCounted.class
when invoked.- Specified by:
getScope
in interfaceContext
- Returns:
ReferenceCounted.class
in all cases
-
isActive
public boolean isActive()Deprecated, for removal: This API element is subject to removal in a future version.Returnstrue
when invoked. -
getInstanceFrom
Deprecated, for removal: This API element is subject to removal in a future version.Returns the soleReferenceCountedContext
that is registered with the suppliedBeanManager
.Strictly speaking, this method may return
null
if theReferenceCountedExtension
has been deliberately disabled and hence has not had a chance to install aReferenceCountedContext
. In all normal usage this method will not returnnull
.- Parameters:
beanManager
- theBeanManager
whoseReferenceCountedContext
should be returned; must not benull
- Returns:
- a
ReferenceCountedContext
, ornull
in exceptionally rare situations - Throws:
NullPointerException
- ifbeanManager
isnull
-