1 package jdk.internal.ref;
   2 
   3 import java.lang.ref.Cleaner;
   4 import java.util.Objects;
   5 import java.util.concurrent.ThreadFactory;
   6 import java.util.function.BooleanSupplier;
   7 
   8 /**
   9  * An extension of public {@link Cleaner} with operations that can only be
  10  * invoked from within {@code java.base} module or selected modules to
  11  * which {@code jdk.internal.ref} package is exported.
  12  */
  13 public interface ExtendedCleaner extends Cleaner {
  14 
  15     /**
  16      * @return new ExtendedCleaner with default ThreadFactory.
  17      */
  18     static ExtendedCleaner create() {
  19         return new CleanerImpl.ExtendedImpl(null);
  20     }
  21 
  22     /**
  23      * @return new ExtendedCleaner with given ThreadFactory.
  24      */
  25     static ExtendedCleaner create(ThreadFactory threadFactory) {
  26         Objects.requireNonNull(threadFactory, "threadFactory");
  27         return new CleanerImpl.ExtendedImpl(threadFactory);
  28     }
  29 
  30     /**
  31      * Retries given {@code retriableOperation} while helping execute cleaning
  32      * functions of pending Cleanable(s) registered by this ExtendedCleaner
  33      * until the operation returns {@code true} or there are no more pending
  34      * Cleanable(s) to clean.
  35      *
  36      * @param retriableOperation the operation to retry while helping with cleanup.
  37      * @return {@code true} if the operation succeeded by returning {@code true} or
  38      * {@code false} when the operation did not succeed before all pending
  39      * Cleanable(s) have been executed.
  40      */
  41     boolean retryWhileHelpingClean(BooleanSupplier retriableOperation);
  42 }