*
* @return true if the specified future has been resolved without throwing an exception or being
* cancelled.
*/
public static boolean isSuccess(ListenableFuture<?> future) throws InterruptedException {
if (!future.isDone()) {
return false;
}
try {
// Try to get the future, but ignore (and preserve) the thread interrupted state.
// This should be fast because we know the future is already complete.
future.get();
return true;
} catch (ExecutionExceptione) {
// The computation threw an exception, so it did not complete successfully.
return false;
} catch (CancellationExceptione) {
// The computation was cancelled, so it did not complete successfully.
return false;