Package org.apache.druid.collections
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 Summary
Constructors Constructor Description ReferenceCountingResourceHolder(T object, Closeable closer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Decrements the reference count by 1.static <T extends Closeable>
ReferenceCountingResourceHolder<T>fromCloseable(T object)
T
get()
Returns the resource with an initial reference count of 1.ResourceHolder<T>
increment()
Increments the reference count by 1 and returns aResourceHolder
representing the new references.static long
leakedResources()
-
-
-
Method Detail
-
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 callingincrement()
.- Specified by:
get
in interfaceResourceHolder<T>
-
increment
public ResourceHolder<T> increment()
Increments the reference count by 1 and returns aResourceHolder
representing the new references. The returnedResourceHolder
"close" method decrements the reference count when the caller no longer needs the resource. ReturnedResourceHolder
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 closescloser
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceResourceHolder<T>
-
-