public abstract class ReferenceCountingCloseableObject<BaseObject extends Closeable> extends Object implements Closeable
Phaser.
ReferenceCountingCloseableObject allows consumers to call close() before some other "users", which called
increment() or incrementReferenceAndDecrementOnceCloseable(), but have not called
decrement() yet or the closer for incrementReferenceAndDecrementOnceCloseable(), and the wrapped
object won't be actually closed until that all references are released.| Modifier and Type | Field and Description |
|---|---|
protected BaseObject |
baseObject |
protected Phaser |
referents |
| Constructor and Description |
|---|
ReferenceCountingCloseableObject(BaseObject object) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
decrement()
Decrement the reference count by one.
|
Closeable |
decrementOnceCloseable()
Returns a
Closeable which action is to call decrement() only once. |
int |
getNumReferences() |
boolean |
increment()
Increment the reference count by one.
|
Optional<Closeable> |
incrementReferenceAndDecrementOnceCloseable()
Returns an
Optional of a Closeable from decrementOnceCloseable(), if it is able to
successfully increment(), else nothing indicating that the reference could not be acquired. |
boolean |
isClosed() |
protected final Phaser referents
protected final BaseObject extends Closeable baseObject
public ReferenceCountingCloseableObject(BaseObject object)
public int getNumReferences()
public boolean isClosed()
public boolean increment()
public void decrement()
public Optional<Closeable> incrementReferenceAndDecrementOnceCloseable()
Optional of a Closeable from decrementOnceCloseable(), if it is able to
successfully increment(), else nothing indicating that the reference could not be acquired.public Closeable decrementOnceCloseable()
Closeable which action is to call decrement() only once. If close() is called on the
returned Closeable object for the second time, it won't call decrement() again.public void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2011–2023 The Apache Software Foundation. All rights reserved.