java.lang.Object
io.helidon.integrations.cdi.referencecountedcontext.ReferenceCountedContext
All Implemented Interfaces:
AlterableContext, Context

@Deprecated(forRemoval=true, since="3.0.3") public final class ReferenceCountedContext extends Object implements AlterableContext
Deprecated, for removal: This API element is subject to removal in a future version.
This class is slated for removal.
A somewhat special-purpose 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 Type
    Method
    Description
    int
    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 supplied Contextual, destroying the instance if and only if the reference count becomes less than or equal to zero, and returns the resulting reference count.
    int
    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 supplied Contextual, 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 the decrementReferenceCount(Contextual) method with the supplied Contextual, 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 supplied Contextual, or null 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 supplied Contextual, creating it if necessary.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns the sole ReferenceCountedContext that is registered with the supplied BeanManager.
    int
    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 supplied Contextual.
    Class<? extends Annotation>
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns ReferenceCounted.class when invoked.
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Returns true when invoked.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • decrementReferenceCount

      public int decrementReferenceCount(Contextual<?> c)
      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 supplied Contextual, 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 - the Contextual whose instance's reference count should be decremented; may be null in which case no action will be taken and 0 will be returned
      Returns:
      the resulting reference count
      See Also:
    • decrementReferenceCount

      public 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 supplied Contextual, 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 - the Contextual whose instance's reference count should be decremented; may be null in which case no action will be taken and 0 will be returned
      amount - the amount by which to decrement; must be greater than or (trivially) equal to 0
      Returns:
      the resulting reference count
      Throws:
      IllegalArgumentException - if amount is less than 0
      See Also:
    • getReferenceCount

      public 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 supplied Contextual.

      Most users will never have to call this method.

      This method never returns a negative number.

      Parameters:
      c - the Contextual whose instance's reference count should be returned; may be null in which case 0 will be returned
      Returns:
      the reference count in question; never a negative number
    • destroy

      public void destroy(Contextual<?> contextual)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Calls the decrementReferenceCount(Contextual) method with the supplied Contextual, destroying it if and only if its thread-specific reference count becomes less than or equal to zero.
      Specified by:
      destroy in interface AlterableContext
      Parameters:
      contextual - the Contextual to destroy; may be null in which case no action will be taken
      See Also:
    • get

      public <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 supplied Contextual, or null if no such contextual instance exists.
      Specified by:
      get in interface Context
      Parameters:
      contextual - the Contextual in question; may be null in which case null wil be returned
      Returns:
      the contextual instance associated with the current thread and the supplied Contextual, or null
    • get

      public <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 supplied Contextual, creating it if necessary.
      Specified by:
      get in interface Context
      Parameters:
      contextual - the Contextual in question; may be null in which case null wil be returned
      cc - a CreationalContext that will hold dependent instances; may be null
      Returns:
      the contextual instance associated with the current thread and the supplied Contextual; may strictly speaking be null but normally is not
    • getScope

      public Class<? extends Annotation> getScope()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns ReferenceCounted.class when invoked.
      Specified by:
      getScope in interface Context
      Returns:
      ReferenceCounted.class in all cases
    • isActive

      public boolean isActive()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns true when invoked.
      Specified by:
      isActive in interface Context
      Returns:
      true in all cases
    • getInstanceFrom

      public static ReferenceCountedContext getInstanceFrom(BeanManager beanManager)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the sole ReferenceCountedContext that is registered with the supplied BeanManager.

      Strictly speaking, this method may return null if the ReferenceCountedExtension has been deliberately disabled and hence has not had a chance to install a ReferenceCountedContext. In all normal usage this method will not return null.

      Parameters:
      beanManager - the BeanManager whose ReferenceCountedContext should be returned; must not be null
      Returns:
      a ReferenceCountedContext, or null in exceptionally rare situations
      Throws:
      NullPointerException - if beanManager is null