Class Cleanup.CollCloseTask<T>

java.lang.Object
de.aristaflow.adept2.util.CleanupTask.AbstractCleanupTask<Exception>
de.aristaflow.adept2.util.Cleanup.CollCloseTask<T>
Type Parameters:
T - The type of the elements of the collection. This is needed for the conversion before closing.
All Implemented Interfaces:
CleanupTask<Exception>
Enclosing class:
Cleanup<EX extends Exception>

public static final class Cleanup.CollCloseTask<T> extends CleanupTask.AbstractCleanupTask<Exception>
A cleanup task for cleaning up a collection of objects being converted and afterwards being closed in case the conversion yields a AutoCloseable. No cleanup will occur for conversion results being of another type or null.
  • Field Details

    • coll

      protected final Collection<T> coll
      The collection of which to close its elements which are converted to AutoCloseable.
  • Constructor Details

    • CollCloseTask

      public CollCloseTask(String descriptor, Collection<T> coll)
      Creates a new Cleanup.CollCloseTask for the designated Collection and the designated descriptor using Cleanup's default logger.
      Parameters:
      descriptor - A string that meaningfully describes this task when used for logging etc. or null.
      coll - The collection of which to AutoCloseable.close() the elements that are AutoCloseable.
    • CollCloseTask

      public CollCloseTask(String descriptor, Logger logger, Collection<T> coll)
      Creates a new Cleanup.CollCloseTask for the designated Collection, the designated descriptor and the designated logger.
      Parameters:
      descriptor - A string that meaningfully describes this task when used for logging etc. or null.
      logger - The logger for messages and/or problems, e. g. unexpected exceptions.
      coll - The collection of which to AutoCloseable.close() the elements that are AutoCloseable.
    • CollCloseTask

      public CollCloseTask(String descriptor, Logger logger, Collection<T> coll, Function<? super T,AutoCloseable> conversion)
      Creates a new Cleanup.CollCloseTask for the designated Collection, the designated conversion applied to the collection elements before closing them, the designated descriptor and the designated logger.
      Parameters:
      descriptor - A string that meaningfully describes this task when used for logging etc. or null.
      logger - The logger for messages and/or problems, e. g. unexpected exceptions.
      coll - The collection of which to AutoCloseable.close() the elements.
      conversion - A function to convert the collection elements before closing. This allows to handler instances that are wrapped by a close ignoring wrapper. If this is null, this simply casts the collection element to AutoCloseable if appropriate and returns null if inappropriate.
  • Method Details

    • cleanup

      public void cleanup(boolean explicit) throws Exception
      Description copied from interface: CleanupTask
      Performs the actual clean-up. This method is only called by Cleanup and must NOT be called directly!
      Parameters:
      explicit - Whether the clean-up was triggered explicitly via Cleanup.clean(). Otherwise it was triggered implicitly as a post-mortem action by the object becoming phantom reachable.
      Throws:
      Exception