Class PooledObjectReference<REFERENT_TYPE>

java.lang.Object
com.illumon.iris.db.util.caching.redesign.PooledObjectReference<REFERENT_TYPE>
All Implemented Interfaces:
com.fishlib.base.reference.SimpleReference<REFERENT_TYPE>, SafeCloseable, AutoCloseable

public abstract class PooledObjectReference<REFERENT_TYPE>
extends Object
implements com.fishlib.base.reference.SimpleReference<REFERENT_TYPE>, SafeCloseable
SimpleReference implementation with built-in reference-counting and pooling support.
  • Method Details

    • get

      public final REFERENT_TYPE get()
      Get the referent. It is an error to call this method if the caller does not have any outstanding permits.
      Specified by:
      get in interface com.fishlib.base.reference.SimpleReference<REFERENT_TYPE>
      Returns:
      The referent if this reference has not been cleared, null otherwise (which implies an error by the caller)
    • acquire

      public final boolean acquire()
      Acquire an active use permit.
      Returns:
      Whether a permit was acquired
    • acquireAndGet

      @Nullable public final REFERENT_TYPE acquireAndGet()
      Acquire an active use permit and return the referent, if possible.
      Returns:
      The referent, or null if no permit could be acquired
    • release

      public final void release()
      Release an active use permit. It is a serious error to release more permits than acquired.
    • clear

      public final void clear()
      Clear this reference (and return its referent to the pool) when it no longer has any outstanding permits, which may mean immediately if the number of outstanding permits is already zero. All invocations after the first will have no effect.
      Specified by:
      clear in interface com.fishlib.base.reference.SimpleReference<REFERENT_TYPE>
    • close

      public final void close()
      Synonym for release(), intended for use as a SafeCloseable in a try-with-resources block.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SafeCloseable
    • track

      Create a wrapper around this PooledObjectReference that tracks the last acquisition.
      Parameters:
      tracker - Tracker that will be responsible for monitoring this acquisition
      Returns:
      The wrapper