public interface ReferenceCountedObject
Closeable
. This is intended to be
used with an implementation of ReferenceCountingCloseableObject
, or anything else that wishes to provide
a method to account for the acquire and release of a reference to the object.Modifier and Type | Method and Description |
---|---|
Optional<Closeable> |
acquireReferences()
This method is expected to increment a reference count and provide a
Closeable that decrements the
reference count when closed. |
Optional<Closeable> acquireReferences()
Closeable
that decrements the
reference count when closed. This is likely just a wrapper around
ReferenceCountingCloseableObject.incrementReferenceAndDecrementOnceCloseable()
, but may also include any
other associated references which should be incremented when this method is called, and decremented/released by the
closeable.
IMPORTANT NOTE: to fulfill the contract of this method, implementors must return a closeable to indicate that the
reference can be acquired, even if there is nothing to close. Implementors should avoid allowing this method or the
Closeable
it creates to throw exceptions.
For callers: if this method returns non-empty, IT MUST BE CLOSED, else reference counts can potentially leak.Copyright © 2011–2021 The Apache Software Foundation. All rights reserved.