A completion service for the RpcRetryingCallerFactory.
Keeps the list of the futures, and allows to cancel them all.
This means as well that it can be used for a small set of tasks only.
Implementation is not Thread safe.
CompletedTasks is implemented as a queue, the entry is added based on the time order. I.e,
when the first task completes (whether it is a success or failure), it is added as a first
entry in the queue, the next completed task is added as a second entry in the queue, ...
When iterating through the queue, we know it is based on time order. If the first
completed task succeeds, it is returned. If it is failure, the iteration goes on until it
finds a success.
Poll for the first successfully completed task whose completed order is in startIndex,
timeout - - time to wait before it times out
unit - - time unit for timeout
startIndex - - start index, starting from 0, inclusive
endIndex - - end index, exclusive
If within timeout time, there is no successfully completed task, return null; If all
tasks get execution exception, it will throw out the last execution exception,
otherwise return the first successfully completed task's result.