Package org.apache.druid.segment
Class ReferenceCountingCloseableObject<BaseObject extends Closeable>
java.lang.Object
org.apache.druid.segment.ReferenceCountingCloseableObject<BaseObject>
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
ReferenceCountedIndexedTableProvider,ReferenceCountedSegmentProvider
public abstract class ReferenceCountingCloseableObject<BaseObject extends Closeable>
extends Object
implements Closeable
ReferenceCountingCloseableObject implements something like automatic reference count-based resource management,
backed by a
Phaser.
ReferenceCountingCloseableObject allows consumers to call close() before some other "users" which have
checked out references via increment() or incrementReferenceAndDecrementOnceCloseable(), but have
not called decrement() yet or the closer for incrementReferenceAndDecrementOnceCloseable().
The wrapped object won't be closed until all references are released.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidDecrement the reference count by one.Returns aCloseablewhich action is to calldecrement()only once.intbooleanIncrement the reference count by one.Returns anOptionalof aCloseablefromdecrementOnceCloseable(), if it is able to successfullyincrement(), else nothing indicating that the reference could not be acquired.booleanisClosed()
-
Field Details
-
referents
-
baseObject
-
-
Constructor Details
-
ReferenceCountingCloseableObject
-
-
Method Details
-
getNumReferences
public int getNumReferences() -
isClosed
public boolean isClosed() -
increment
public boolean increment()Increment the reference count by one. -
decrement
public void decrement()Decrement the reference count by one. -
incrementReferenceAndDecrementOnceCloseable
Returns anOptionalof aCloseablefromdecrementOnceCloseable(), if it is able to successfullyincrement(), else nothing indicating that the reference could not be acquired. -
decrementOnceCloseable
Returns aCloseablewhich action is to calldecrement()only once. If close() is called on the returned Closeable object for the second time, it won't calldecrement()again. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-