Interface RefCounted

  • All Known Implementing Classes:
    AbstractRefCounted

    public interface RefCounted
    An interface for objects that need to be notified when all reference to itself are not in user anymore. This implements basic reference counting for instance if async operations holding on to services that are close concurrently but should be functional until all async operations have joined Classes implementing this interface should ref counted at any time ie. if an object is used it's reference count should be increased before using it by calling #incRef and a corresponding #decRef must be called in a try/finally block to release the object again ie.:
          inst.incRef();
          try {
            // use the inst...
    
          } finally {
              inst.decRef();
          }
     
    • Method Summary

      Modifier and Type Method Description
      void decRef()
      Decreases the refCount of this instance.
      void incRef()
      Increments the refCount of this instance.
      boolean tryIncRef()
      Tries to increment the refCount of this instance.
    • Method Detail

      • incRef

        void incRef()
        Increments the refCount of this instance.
        Throws:
        java.lang.IllegalStateException - iff the reference counter can not be incremented.
        See Also:
        decRef(), tryIncRef()
      • tryIncRef

        boolean tryIncRef()
        Tries to increment the refCount of this instance. This method will return true iff the refCount was
        See Also:
        decRef(), incRef()
      • decRef

        void decRef()
        Decreases the refCount of this instance. If the refCount drops to 0, then this instance is considered as closed and should not be used anymore.
        See Also:
        incRef()