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:
ReferenceCountingIndexedTable,ReferenceCountingSegment
public abstract class ReferenceCountingCloseableObject<BaseObject extends Closeable> extends Object implements Closeable
ReferenceCountingCloseableObject implements something like automatic reference count-based resource management, backed by aPhaser. ReferenceCountingCloseableObject allows consumers to callclose()before some other "users", which calledincrement()orincrementReferenceAndDecrementOnceCloseable(), but have not calleddecrement()yet or the closer forincrementReferenceAndDecrementOnceCloseable(), and the wrapped object won't be actually closed until that all references are released.
-
-
Field Summary
Fields Modifier and Type Field Description protected BaseObjectbaseObjectprotected Phaserreferents
-
Constructor Summary
Constructors Constructor Description ReferenceCountingCloseableObject(BaseObject object)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voiddecrement()Decrement the reference count by one.CloseabledecrementOnceCloseable()Returns aCloseablewhich action is to calldecrement()only once.intgetNumReferences()booleanincrement()Increment the reference count by one.Optional<Closeable>incrementReferenceAndDecrementOnceCloseable()Returns anOptionalof aCloseablefromdecrementOnceCloseable(), if it is able to successfullyincrement(), else nothing indicating that the reference could not be acquired.booleanisClosed()
-
-
-
Field Detail
-
referents
protected final Phaser referents
-
baseObject
protected final BaseObject extends Closeable baseObject
-
-
Constructor Detail
-
ReferenceCountingCloseableObject
public ReferenceCountingCloseableObject(BaseObject object)
-
-
Method Detail
-
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
public Optional<Closeable> incrementReferenceAndDecrementOnceCloseable()
Returns anOptionalof aCloseablefromdecrementOnceCloseable(), if it is able to successfullyincrement(), else nothing indicating that the reference could not be acquired.
-
decrementOnceCloseable
public Closeable 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
-
-