Class DefaultResourceCleaner.Builder<T>

  • Type Parameters:
    T - The functional interface that's being translated into the internally used DefaultResourceCleaner.CleanupFn.
    Enclosing class:
    DefaultResourceCleaner<T>

    public static class DefaultResourceCleaner.Builder<T>
    extends Object
    Builder for creating DefaultResourceCleaner instances.
    • Method Detail

      • withPrioritizedCleanup

        public DefaultResourceCleaner.Builder<T> withPrioritizedCleanup​(String label,
                                                                        T prioritizedCleanup)
        Prioritized cleanups run before their regular counterparts. This method enables the caller to model dependencies between cleanup tasks. The order in which cleanable resources are added matters, i.e. if two cleanable resources are added as prioritized cleanup tasks, the resource being added first will block the cleanup of the second resource. All prioritized cleanup resources will run and finish before any resource that is added using withRegularCleanup(String, Object) is started.
        Parameters:
        label - The label being used when logging errors in the given cleanup.
        prioritizedCleanup - The cleanup callback that is going to be prioritized.
      • withRegularCleanup

        public DefaultResourceCleaner.Builder<T> withRegularCleanup​(String label,
                                                                    T regularCleanup)
        Regular cleanups are resources for which the cleanup is triggered after all prioritized cleanups succeeded. All added regular cleanups will run concurrently to each other.
        Parameters:
        label - The label being used when logging errors in the given cleanup.
        regularCleanup - The cleanup callback that is going to run after all prioritized cleanups are finished.
        See Also:
        withPrioritizedCleanup(String, Object)