Class SharedResource<T extends Resource<T>>

java.lang.Object
org.apache.qpid.protonj2.resource.SharedResource<T>
Type Parameters:
T - The resource type that whose references are being tracked.
All Implemented Interfaces:
AutoCloseable, Resource<T>
Direct Known Subclasses:
Netty4ToProtonBufferAdapter, Netty5ToProtonBufferAdapter, ProtonByteArrayBuffer, ProtonCompositeBufferImpl

public abstract class SharedResource<T extends Resource<T>> extends Object implements Resource<T>, AutoCloseable
A referenced resource is one in which a number of objects can claim reference and the resource will not close or free claimed resources until all references have been released.
  • Constructor Details

    • SharedResource

      public SharedResource()
  • Method Details

    • acquire

      protected final T acquire()
    • close

      public final void close()
      Description copied from interface: Resource
      Close the resource and free any managed resources it might own. Calling close on a closed resource should not result in any exceptions being thrown.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Resource<T extends Resource<T>>
    • transfer

      public final T transfer()
      Description copied from interface: Resource
      Transfers ownership of this resource from one owner to another.

      Upon transferring a resource the original referenced value is closed and its contents are migrated to a new view that has the same state as the original view but it now the property of the caller and who's life-cycle now must be managed by the caller.

      Specified by:
      transfer in interface Resource<T extends Resource<T>>
      Returns:
      the a new transfered view of the given resource now owned by the caller.
    • isClosed

      public final boolean isClosed()
      Description copied from interface: Resource
      A Resource is closed either following a call to the Resource.close() method or by the resource being transfered by way of the Resource.transfer() method.
      Specified by:
      isClosed in interface Resource<T extends Resource<T>>
      Returns:
      true if this resource is closed, either by being transfered or by direct Resource.close().
    • isShared

      protected final boolean isShared()
    • releaseResourceOwnership

      protected abstract void releaseResourceOwnership()
    • transferTheResource

      protected abstract T transferTheResource()
    • resourceIsClosedException

      protected abstract RuntimeException resourceIsClosedException()