Class ResultAggregator

java.lang.Object
com.tnsai.coordination.ResultAggregator

public class ResultAggregator extends Object
Aggregates results from multiple workers in the orchestrator-worker pattern. Thread-safe result collection with waiting capability.
  • Constructor Details

    • ResultAggregator

      public ResultAggregator(String name, int expectedResults)
  • Method Details

    • addResult

      public void addResult(TaskResult result)
      Adds a task result. Thread-safe operation. Only counts down the latch for new (not duplicate) results.
      Parameters:
      result - the task result
    • awaitCompletion

      public void awaitCompletion() throws InterruptedException
      Waits for all expected results to arrive. Blocks until all results are collected.
      Throws:
      InterruptedException - if interrupted while waiting
    • awaitCompletion

      public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException
      Waits for all expected results with a timeout.
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit
      Returns:
      true if all results collected, false if timeout
      Throws:
      InterruptedException - if interrupted while waiting
    • getAllResults

      public List<TaskResult> getAllResults()
      Gets all collected results.
      Returns:
      immutable list of results
    • getSuccessfulResults

      public List<TaskResult> getSuccessfulResults()
      Gets successful results only.
      Returns:
      list of successful results
    • getFailedResults

      public List<TaskResult> getFailedResults()
      Gets failed results only.
      Returns:
      list of failed results
    • getResult

      public TaskResult getResult(String taskId)
      Gets a specific result by task ID.
      Parameters:
      taskId - the task ID
      Returns:
      the result, or null if not found
    • isComplete

      public boolean isComplete()
      Checks if all expected results have been collected.
      Returns:
      true if complete
    • getResultCount

      public int getResultCount()
      Gets the number of results collected so far.
      Returns:
      result count
    • getExpectedResults

      public int getExpectedResults()
      Gets the number of expected results.
      Returns:
      expected count
    • getStatistics

      Gets statistics about the aggregated results.
      Returns:
      aggregation statistics
    • getName

      public String getName()
    • toString

      public String toString()
      Overrides:
      toString in class Object