org.apache.geode.cache.execute

## Interface ResultSender<T>

-     public interface ResultSender<T>

  Provides methods to send results back to the ResultCollector. A ResultSender adds the ability for an execute method to send a single result back, or break its result into multiple pieces and send each piece back to the calling thread's `ResultCollector`. For each result sent using this method, `ResultCollector.addResult(org.apache.geode.distributed.DistributedMember, Object)` is called, making that result available to the calling thread immediately.

  Example:

            execute(FunctionContext context){
                    ResultSender rs = context.getResultSender();
                    int lastResult = -1;
                    for(int i=0;i< 10; i++) {
                            rs.sendResult(i);
                    }
                    rs.lastResult(lastResult);
            }

        Application can receive the results as they are sent using ResultSender in the above for loop.
        It is very important to send a last result as it informs ResultCollector
        to stop waiting for the result.

  Since:
    GemFire 6.0
  See Also:
    `ResultCollector.addResult(org.apache.geode.distributed.DistributedMember, Object)`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `lastResult(T lastResult)` Sends a result back to the FunctionService calling thread and invokes `ResultCollector.addResult(org.apache.geode.distributed.DistributedMember, Object)` and then `ResultCollector.endResults()` if it is the last instance of the Function to report results.
    `void` | `sendException(java.lang.Throwable t)` Sends an Exception back to the FunctionService calling thread.
    `void` | `sendResult(T oneResult)` Sends a result back to the FunctionService calling thread and invokes `ResultCollector.addResult(org.apache.geode.distributed.DistributedMember, Object)`.

- - ### Method Detail

    - #### sendResult

          void sendResult(T oneResult)

      Sends a result back to the FunctionService calling thread and invokes `ResultCollector.addResult(org.apache.geode.distributed.DistributedMember, Object)`.

    - #### lastResult

          void lastResult(T lastResult)

      Sends a result back to the FunctionService calling thread and invokes `ResultCollector.addResult(org.apache.geode.distributed.DistributedMember, Object)` and then `ResultCollector.endResults()` if it is the last instance of the Function to report results. The ResultCollector will keep waiting for results until it receives last result. Therefore, it is very important to use this method to indicate end of function execution.
      Throws:
        `java.lang.IllegalStateException` - if called more than once
      See Also:
        `ResultCollector.endResults()`

    - #### sendException

          void sendException(java.lang.Throwable t)

      Sends an Exception back to the FunctionService calling thread. sendException adds exception to ResultCollector as a result. If sendException is called then `ResultCollector.getResult()` will not throw exception but will have exception as a part of results received. Calling sendException will act as a lastResult.
      Since:
        GemFire 6.3
      See Also:
        `lastResult(Object)`