Class ReferenceCountingResourceHolder<T>

java.lang.Object
org.apache.druid.collections.ReferenceCountingResourceHolder<T>
All Implemented Interfaces:
Closeable, AutoCloseable, ResourceHolder<T>

public class ReferenceCountingResourceHolder<T> extends Object implements ResourceHolder<T>
  • Constructor Details

    • ReferenceCountingResourceHolder

      public ReferenceCountingResourceHolder(T object, Closeable closer)
  • Method Details

    • leakedResources

      public static long leakedResources()
    • fromCloseable

      public static <T extends Closeable> ReferenceCountingResourceHolder<T> fromCloseable(T object)
    • get

      public T get()
      Returns the resource with an initial reference count of 1. More references can be added by calling increment().
      Specified by:
      get in interface ResourceHolder<T>
    • increment

      public ResourceHolder<T> increment()
      Increments the reference count by 1 and returns a ResourceHolder representing the new references. The returned ResourceHolder "close" method decrements the reference count when the caller no longer needs the resource. Returned ResourceHolder are not thread-safe. If multiple threads need references to the same resource, they should each call this method on the original object.
    • close

      public void close()
      Decrements the reference count by 1. If it reaches to 0, then closes closer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ResourceHolder<T>