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 BaseObject
baseObject
protected Phaser
referents
-
Constructor Summary
Constructors Constructor Description ReferenceCountingCloseableObject(BaseObject object)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
decrement()
Decrement the reference count by one.Closeable
decrementOnceCloseable()
Returns aCloseable
which action is to calldecrement()
only once.int
getNumReferences()
boolean
increment()
Increment the reference count by one.Optional<Closeable>
incrementReferenceAndDecrementOnceCloseable()
Returns anOptional
of aCloseable
fromdecrementOnceCloseable()
, if it is able to successfullyincrement()
, else nothing indicating that the reference could not be acquired.boolean
isClosed()
-
-
-
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 anOptional
of aCloseable
fromdecrementOnceCloseable()
, if it is able to successfullyincrement()
, else nothing indicating that the reference could not be acquired.
-
decrementOnceCloseable
public Closeable decrementOnceCloseable()
Returns aCloseable
which 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-