Class CleanerUtil
- java.lang.Object
-
- org.apache.accumulo.core.util.cleaner.CleanerUtil
-
public class CleanerUtil extends Object
This class collects all the cleaner actions executed in various parts of the code.These actions replace the use of finalizers, which are deprecated in Java 9 and later, and should be avoided. These actions are triggered by their respective objects when those objects become phantom reachable.
In the "unclosed*" methods below, the object should have been closed (implements AutoCloseable). We could possibly consolidate these into a single method which only warns, and doesn't try to clean up. We could also delete them entirely, since it is the caller's responsibility to close AutoCloseable resources, not the object's own responsibility to detect that it wasn't closed.
-
-
Constructor Summary
Constructors Constructor Description CleanerUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Cleaner.Cleanable
batchWriterAndClientCloser(Object o, org.slf4j.Logger log, BatchWriter bw, AccumuloClient client)
static Cleaner.Cleanable
shutdownThreadPoolExecutor(ExecutorService pool, AtomicBoolean closed, org.slf4j.Logger log)
static Cleaner.Cleanable
unclosed(AutoCloseable obj, Class<?> objClass, AtomicBoolean closed, org.slf4j.Logger log, AutoCloseable closeable)
Register an action to warn about caller failing to close anAutoCloseable
object.static Cleaner.Cleanable
zooCacheClearer(Object o, ZooCache zc)
-
-
-
Field Detail
-
CLEANER
public static final Cleaner CLEANER
-
-
Method Detail
-
unclosed
public static Cleaner.Cleanable unclosed(AutoCloseable obj, Class<?> objClass, AtomicBoolean closed, org.slf4j.Logger log, AutoCloseable closeable)
Register an action to warn about caller failing to close anAutoCloseable
object.This task will register a generic action to:
- check that the monitored object wasn't closed,
- log a warning that the monitored object was not closed,
- attempt to close a resource within the object, and
- log an error if the resource cannot be closed for any reason
- Parameters:
obj
- the object to monitor for becoming phantom-reachable without having been closedobjClass
- the class whose simple name will be used in the log message foro
(usually an interface name, rather than the actual impl name of the object)closed
- a flag to check whethero
has already been closedlog
- the logger to use when emitting error/warn messagescloseable
- the resource withino
to close wheno
is cleaned; must not contain a reference to themonitoredObject
or it won't become phantom-reachable and will never be cleaned- Returns:
- the registered
Cleaner.Cleanable
fromCleaner.register(Object, Runnable)
-
shutdownThreadPoolExecutor
public static Cleaner.Cleanable shutdownThreadPoolExecutor(ExecutorService pool, AtomicBoolean closed, org.slf4j.Logger log)
-
batchWriterAndClientCloser
public static Cleaner.Cleanable batchWriterAndClientCloser(Object o, org.slf4j.Logger log, BatchWriter bw, AccumuloClient client)
-
zooCacheClearer
public static Cleaner.Cleanable zooCacheClearer(Object o, ZooCache zc)
-
-