T - the type of the command result@Internal public final class MultiNodeResultAggregator<T> extends java.lang.Object
This class centralizes the logic for collecting results and errors from multi-node command
execution (broadcast commands, multi-shard commands) and determining the final result based on
the CommandFlagsRegistry.ResponsePolicy.
Key behavior differences by policy:
ONE_SUCCEEDED: Returns success if at least one node succeeds, even if others fail.
Only throws if ALL nodes fail.JedisBroadcastException if ANY node fails.| Constructor and Description |
|---|
MultiNodeResultAggregator(CommandFlagsRegistry.ResponsePolicy responsePolicy)
Creates a new aggregator with the specified response policy.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addError(java.lang.Exception error)
Records an error, extracting the node information from the exception if available.
|
void |
addError(HostAndPort node,
java.lang.Exception error)
Records an error from a node.
|
void |
addSuccess(HostAndPort node,
T result)
Records a successful result from a node.
|
void |
addSuccess(T result)
Records a successful result without node information.
|
CommandFlagsRegistry.ResponsePolicy |
getResponsePolicy()
Returns the response policy being used by this aggregator.
|
T |
getResult()
Returns the aggregated result based on the response policy.
|
public MultiNodeResultAggregator(CommandFlagsRegistry.ResponsePolicy responsePolicy)
responsePolicy - the policy that determines how to aggregate results and handle errorspublic void addSuccess(HostAndPort node, T result)
node - the node that returned the resultresult - the result from the nodepublic void addSuccess(T result)
Use this method when the node information is not readily available, such as in multi-shard commands where extracting the node would require additional computation.
result - the result from the operationpublic void addError(HostAndPort node, java.lang.Exception error)
node - the node that returned the errorerror - the exception from the nodepublic void addError(java.lang.Exception error)
This method extracts node information from JedisClusterOperationException if present,
otherwise uses a placeholder "unknown:0" node.
error - the exception from the failed operationpublic T getResult()
For ONE_SUCCEEDED policy: returns the aggregated result if at least one node succeeded,
throws JedisBroadcastException only if all nodes failed.
For all other policies: throws JedisBroadcastException if any node failed, otherwise
returns the aggregated result.
JedisBroadcastException - if the policy criteria are not metpublic CommandFlagsRegistry.ResponsePolicy getResponsePolicy()
Copyright © 2026. All rights reserved.