Interface ReferenceCountedObjectProvider<T extends Closeable>

All Known Subinterfaces:
IndexedTable, Joinable
All Known Implementing Classes:
BroadcastSegmentIndexedTable, FrameBasedIndexedTable, IndexedTableJoinable, JoinableClause, LookupJoinable, ReferenceCountedIndexedTableProvider, ReferenceCountedSegmentProvider, RowBasedIndexedTable

public interface ReferenceCountedObjectProvider<T extends Closeable>
Interface to capture the pattern of providing tracked usage of some resource. Callers use acquireReference() to check out a reference to this resource as a Closeable which releases the reference upon close. Implementations of this class are expected to be thread-safe, but the object returned by acquireReference() has no such guarantees, so check with the implementation.

For ease of implementation, implementors may extend ReferenceCountingCloseableObject, using the Closeable from ReferenceCountingCloseableObject.incrementReferenceAndDecrementOnceCloseable() in the close method of the object returned by acquireReference().

  • Method Summary

    Modifier and Type
    Method
    Description
    This method increments a reference count and provides a Closeable that decrements the reference count when closed.
  • Method Details

    • acquireReference

      Optional<T> acquireReference()
      This method increments a reference count and provides a Closeable that decrements the reference count when closed. The object returned by this method may or may not be thread-safe, it is best to check with the implementation.

      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 ideally avoid allowing this method to throw exceptions, but callers are responsible for closing the returned object should any operations on it throw exceptions.

      For callers: if this method returns non-empty, IT MUST BE CLOSED, else reference counts can potentially leak.