GemFire 6.0.1

com.gemstone.gemfire.cache.execute
Interface ResultCollector<T extends Serializable>


public interface ResultCollector<T extends Serializable>

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 it is sent using the ResultSender.sendResult(Serializable) and can be used as it arrives. To indicate if all the results have been received endResults() is called.

Example:
  Region region ; 
  Set keySet = Collections.singleton("myKey");
  Function multiGetFunction ;
  Serializable args ;
  ResultCollector rc = FunctionService.onRegion(region)
                                      .withArgs(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(Serializable) to use the partial results.
  If it wants to see all the results it can use 
  Serializable functionResult = rc.getResult();
  or
  Serializable functionResult = rc.getResult(timeout,TimeUnit);
  depending on if it wants to wait for all the results or wait for a timeout period.  
 

Since:
6.0

Method Summary
 void addResult(T resultOfSingleExecution)
          Adds a single function execution result to the ResultCollector It is invoked every time a result is sent using ResultSender.
 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.
 T getResult()
          Returns the result of function execution, potentially blocking until all the results are available has been called.
 T getResult(long timeout, TimeUnit unit)
          Returns the result of function execution, blocking for the timeout period until all the results are available.
 

Method Detail

getResult

T getResult()
                                 throws FunctionException
Returns the result of function execution, potentially blocking until all the results are available has been called.

Returns:
the result
Throws:
FunctionException - if result retrieval fails
Since:
6.0

getResult

T getResult(long timeout,
            TimeUnit unit)
                                 throws FunctionException,
                                        InterruptedException
Returns the result of function execution, blocking for the timeout period until all the results are available. If all the results are not received in provided time a FunctionException is thrown.

Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
the result
Throws:
FunctionException - if result retrieval fails within timeout provided
InterruptedException - if the current thread was interrupted while waiting
Since:
6.0

addResult

void addResult(T resultOfSingleExecution)
Adds a single function execution result to the ResultCollector It is invoked every time a result is sent using ResultSender.

Parameters:
resultOfSingleExecution -
Since:
6.0

endResults

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.

Since:
6.0
See Also:
ResultSender.lastResult(Serializable)

GemFire 6.0.1

Copyright © 2002-2009 GemStone Systems, Inc. All Rights Reserved.