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 classTracker that can be used to monitor unreleased references. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanacquire()Acquire an active use permit.final REFERENT_TYPEAcquire an active use permit and return the referent, if possible.final voidclear()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 voidclose()Synonym forrelease(), intended for use as aSafeCloseablein a try-with-resources block.final REFERENT_TYPEget()Get the referent.final voidrelease()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:
getin 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:
clearin interfacecom.fishlib.base.reference.SimpleReference<REFERENT_TYPE>
-
close
public final void close()Synonym forrelease(), intended for use as aSafeCloseablein a try-with-resources block.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein 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
-