Package com.illumon.util.reference
Class CleanupReferenceProcessor
java.lang.Object
com.illumon.util.reference.CleanupReferenceProcessor
public class CleanupReferenceProcessor extends Object
Utility for draining a reference queue of
CleanupReference
s and invoking their cleanup methods.-
Constructor Summary
Constructors Constructor Description CleanupReferenceProcessor(String name, long shutdownCheckDelayMillis, FunctionalInterfaces.ThrowingTriConsumer<com.fishlib.io.logger.Logger,com.fishlib.base.reference.CleanupReference,Exception,? extends RuntimeException> exceptionHandler)
Construct a newCleanupReferenceProcessor
. -
Method Summary
Modifier and Type Method Description <RT> ReferenceQueue<RT>
getReferenceQueue()
Get the reference queue for this cleaner.void
resetForUnitTests()
Reset this instance so that the next call togetReferenceQueue()
will re-initialize it and provide a new queue.
-
Constructor Details
-
CleanupReferenceProcessor
public CleanupReferenceProcessor(@NotNull String name, long shutdownCheckDelayMillis, @NotNull FunctionalInterfaces.ThrowingTriConsumer<com.fishlib.io.logger.Logger,com.fishlib.base.reference.CleanupReference,Exception,? extends RuntimeException> exceptionHandler)Construct a newCleanupReferenceProcessor
.- Parameters:
name
- The name of the processor, used for naming threadsshutdownCheckDelayMillis
- The frequency with which to check for shutdownexceptionHandler
- Callback for exception handling
-
-
Method Details
-
getReferenceQueue
Get the reference queue for this cleaner.
On the first call after construction or
resetForUnitTests()
, this method initializes the instance as a side effect. Initialization entails:- Constructing a
ReferenceQueue
. - Starting a daemon thread that will drain the reference queue and invoke
CleanupReference.cleanup()
on anyCleanupReference
dequeued.
- Returns:
- The
ReferenceQueue
constructed in the most recent initialization of thisCleanupReferenceProcessor
instance
- Constructing a
-
resetForUnitTests
Reset this instance so that the next call togetReferenceQueue()
will re-initialize it and provide a new queue. Results in eventual termination of the daemon thread that may have been draining the existing queue.
-