Class ReferenceCountedContext

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int decrementReferenceCount​(javax.enterprise.context.spi.Contextual<?> c)
      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 decrementReferenceCount​(javax.enterprise.context.spi.Contextual<?> c, int amount)
      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​(javax.enterprise.context.spi.Contextual<?> contextual)
      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​(javax.enterprise.context.spi.Contextual<T> contextual)
      Returns the contextual instance associated with the current thread and the supplied Contextual, or null if no such contextual instance exists.
      <T> T get​(javax.enterprise.context.spi.Contextual<T> contextual, javax.enterprise.context.spi.CreationalContext<T> cc)
      Returns the contextual instance associated with the current thread and the supplied Contextual, creating it if necessary.
      static ReferenceCountedContext getInstanceFrom​(javax.enterprise.inject.spi.BeanManager beanManager)
      Returns the sole ReferenceCountedContext that is registered with the supplied BeanManager.
      int getReferenceCount​(javax.enterprise.context.spi.Contextual<?> c)
      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> getScope()
      Returns ReferenceCounted.class when invoked.
      boolean isActive()
      Returns true when invoked.
    • Method Detail

      • decrementReferenceCount

        public int decrementReferenceCount​(javax.enterprise.context.spi.Contextual<?> c)
        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:
        Contextual.destroy(Object, CreationalContext), get(Contextual, CreationalContext)
      • decrementReferenceCount

        public int decrementReferenceCount​(javax.enterprise.context.spi.Contextual<?> c,
                                           int amount)
        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:
        Contextual.destroy(Object, CreationalContext), get(Contextual, CreationalContext), decrementReferenceCount(Contextual)
      • getReferenceCount

        public int getReferenceCount​(javax.enterprise.context.spi.Contextual<?> c)
        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​(javax.enterprise.context.spi.Contextual<?> contextual)
        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 javax.enterprise.context.spi.AlterableContext
        Parameters:
        contextual - the Contextual to destroy; may be null in which case no action will be taken
        See Also:
        decrementReferenceCount(Contextual), get(Contextual, CreationalContext)
      • get

        public <T> T get​(javax.enterprise.context.spi.Contextual<T> contextual)
        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 javax.enterprise.context.spi.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​(javax.enterprise.context.spi.Contextual<T> contextual,
                         javax.enterprise.context.spi.CreationalContext<T> cc)
        Returns the contextual instance associated with the current thread and the supplied Contextual, creating it if necessary.
        Specified by:
        get in interface javax.enterprise.context.spi.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
      • isActive

        public boolean isActive()
        Returns true when invoked.
        Specified by:
        isActive in interface javax.enterprise.context.spi.Context
        Returns:
        true in all cases