public interface ResultCollector<T,S>
Defines the interface for a container that gathers results from function execution.
GemFire provides a default implementation for ResultCollector. Applications can choose to
implement their own custom ResultCollector. A custom ResultCollector facilitates result sorting
or aggregation. Aggregation functions like sum, minimum, maximum and average can also be applied
to the result using a custom ResultCollector. Results arrive as they are sent using the
ResultSender.sendResult(Object)
and can be used as they arrive. To indicate that all
results have been received endResults()
is called.
Example:
Region region ;
Set keySet = Collections.singleton("myKey");
Function multiGetFunction ;
Object args ;
ResultCollector rc = FunctionService.onRegion(region)
.setArguments(args)
.withFilter(keySet)
.withCollector(new MyCustomResultCollector())
.execute(multiGetFunction.getId());
Application can do something else here before retrieving the result
Or it can have some logic in {addResult(DistributedMember, Object)
to use the partial results.
If it wants to see all the results it can use
Object functionResult = rc.getResult();
or
Object functionResult = rc.getResult(timeout,TimeUnit);
depending on if it wants to wait for all the results or wait for a timeout period.
GemFire provides default implementation of ResultCollector which collects results in Arraylist.
There is no need to provide a synchronization mechanism in the user implementations of
ResultCollectorModifier and Type | Method and Description |
---|---|
void |
addResult(DistributedMember memberID,
T resultOfSingleExecution)
Method used to feed result to the ResultCollector.
|
void |
clearResults()
GemFire will invoke this method before re-executing function (in case of Function Execution
HA).
|
void |
endResults()
GemFire will invoke this method when function execution has completed and all results for the
execution have been obtained and
added to the
ResultCollector Unless the ResultCollector has received
last result from all the executing nodes, it keeps
waiting for more results to come. |
S |
getResult()
Method used to pull results from the ResultCollector.
|
S |
getResult(long timeout,
TimeUnit unit)
Method used to pull results from the ResultCollector.
|
S getResult() throws FunctionException
all the results are available
has
been called.FunctionException
- if result retrieval failsS getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException
all the results are
available
. If all the results are not received in provided time a FunctionException is thrown.timeout
- the maximum time to waitunit
- the time unit of the timeout argumentFunctionException
- if result retrieval fails within timeout providedInterruptedException
- if the current thread was interrupted while waitingvoid addResult(DistributedMember memberID, T resultOfSingleExecution)
memberID
- DistributedMember ID to which result belongsresultOfSingleExecution
- the result to addvoid endResults()
added to the
ResultCollector
Unless the ResultCollector
has received
last result
from all the executing nodes, it keeps
waiting for more results to come.ResultSender.lastResult(Object)
void clearResults()