Package com.tnsai.coordination
Class ResultAggregator
java.lang.Object
com.tnsai.coordination.ResultAggregator
Aggregates results from multiple workers in the orchestrator-worker pattern.
Thread-safe result collection with waiting capability.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAggregation statistics. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddResult(TaskResult result) Adds a task result.voidWaits for all expected results to arrive.booleanawaitCompletion(long timeout, TimeUnit unit) Waits for all expected results with a timeout.Gets all collected results.intGets the number of expected results.Gets failed results only.getName()Gets a specific result by task ID.intGets the number of results collected so far.Gets statistics about the aggregated results.Gets successful results only.booleanChecks if all expected results have been collected.toString()
-
Constructor Details
-
ResultAggregator
-
-
Method Details
-
addResult
Adds a task result. Thread-safe operation. Only counts down the latch for new (not duplicate) results.- Parameters:
result- the task result
-
awaitCompletion
Waits for all expected results to arrive. Blocks until all results are collected.- Throws:
InterruptedException- if interrupted while waiting
-
awaitCompletion
Waits for all expected results with a timeout.- Parameters:
timeout- the maximum time to waitunit- the time unit- Returns:
- true if all results collected, false if timeout
- Throws:
InterruptedException- if interrupted while waiting
-
getAllResults
Gets all collected results.- Returns:
- immutable list of results
-
getSuccessfulResults
Gets successful results only.- Returns:
- list of successful results
-
getFailedResults
Gets failed results only.- Returns:
- list of failed results
-
getResult
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
-
toString
-