Class RetryTracker<T>

java.lang.Object
net.preibisch.mvrecon.process.export.RetryTracker<T>

public class RetryTracker<T> extends Object
Simple utility to track retry attempts and handle retry logic for failed blocks. Keeps the parallelization code separate while avoiding retry logic duplication.
  • Constructor Details

    • RetryTracker

      public RetryTracker(Function<T,String> keyExtractor, String operationName, int maxRetries, boolean giveUpOnFailure, long retryDelayMs, boolean triggerGC, int totalBlocks)
  • Method Details

    • forGridBlocks

      public static RetryTracker<long[][]> forGridBlocks(String operationName, int totalBlocks)
      Convenience constructor for grid blocks with default settings
      Parameters:
      operationName - any descriptive name for the operation for output messages
      totalBlocks - number of blocks that will be processed
      Returns:
      the RetryTracker instance
    • keyExtractor

      public Function<T,String> keyExtractor()
    • beginAttempt

      public boolean beginAttempt()
      Call this before each retry cycle. Returns false if max total attempts exceeded.
      Returns:
      if begin was successful
    • createFailedBlocksMap

      public HashMap<String,T> createFailedBlocksMap(Collection<T> grid)
      Create the map of all blocks, from which we then remove each one that succeeded piece by piece
      Parameters:
      grid - - all blocks
      Returns:
      HashMap from created unique key to block
    • processWithFutures

      public Set<T> processWithFutures(List<Future<T>> futures, Collection<T> grid)
      Method to process all results when running with a service that returns futures. When running with Spark, this method needs to be adjusted.
      Parameters:
      futures - - list of Futures
      grid - - list blocks that were processed
      Returns:
      set of failed blocks
    • processFailures

      public boolean processFailures(Set<T> failedBlocks)
      Remove successful blocks from the failed set and update retry counts. Returns false if should stop due to too many individual block failures.
      Parameters:
      failedBlocks - failed block to re-process
      Returns:
      if it did not give up now
    • getTotalAttempts

      public int getTotalAttempts()