Programming to Get Function Results
The client may use the default result collector. If the client needs special results handling, code a custom ResultsCollector
implementation to replace the default. Use the Execution::withCollector
method to define the custom collector.
Note: This section applies only to functions that return results.
To program your client to get the results from a function, use the result collector returned from the function execution, like this:
ResultCollectorPtr rc = FunctionService::onRegion(region)
->withArgs(args)
->withFilter(keySet)
->withCollector(new MyCustomResultCollector())
.execute(Function);
CacheableVectorPtr functionResult = rc.getResult();
The getResult
methods of the default result collector block until all results are received, then return the full result set.
To handle the results in a custom manner:
- Write a class that implements the
ResultCollector
interface to handle the results in a custom manner. The methods are of two types: one handles data and information from GemFire and populates the results set, while the other returns the compiled results to the calling application:-
addResult
is called when results arrive from theFunction
methods. UseaddResult
to add a single result to the ResultCollector. -
endResults
is called to signal the end of all results from the function execution. -
getResult
is available to your executing application (the one that callsExecution.execute
) to retrieve the results. This may block until all results are available. -
clearResults
is called to clear partial results from the results collector. This is used only for highly availableonRegion
functions where the calling application waits for the results. If the call fails, before GemFire retries the execution, it callsclearResults
to ready the instance for a clean set of results.
-
- Use the
Execution
object in your executing member to callwithCollector
, passing your custom collector, as shown in the example above.