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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Tracker that can be used to monitor unreleased references. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
acquire()
Acquire an active use permit.final REFERENT_TYPE
Acquire an active use permit and return the referent, if possible.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.final void
close()
Synonym forrelease()
, intended for use as aSafeCloseable
in a try-with-resources block.final REFERENT_TYPE
get()
Get the referent.final void
release()
Release an active use permit.track
(PooledObjectReference.Tracker<REFERENT_TYPE> tracker) Create a wrapper around this PooledObjectReference that tracks the last acquisition.
-
Method Details
-
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 interfacecom.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
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 interfacecom.fishlib.base.reference.SimpleReference<REFERENT_TYPE>
-
close
public final void close()Synonym forrelease()
, intended for use as aSafeCloseable
in a try-with-resources block.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSafeCloseable
-
track
public final PooledObjectReference<REFERENT_TYPE> track(@NotNull PooledObjectReference.Tracker<REFERENT_TYPE> tracker) 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
-