Make ListenableFuture compliant with Java 8 lambda

Make it possible to use a ListenableFuture with Java 8
lambda expressions, using a syntax like
listenableFuture.addCallback(() -> ..., () -> ...);

Issue: SPR-11820
This commit is contained in:
Sebastien Deleuze
2014-05-27 17:03:48 +02:00
parent 89b202029a
commit 86e8bdab6b
14 changed files with 392 additions and 41 deletions

View File

@@ -18,8 +18,10 @@ package org.springframework.scheduling.annotation;
import java.util.concurrent.TimeUnit;
import org.springframework.util.concurrent.FailureCallback;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
import org.springframework.util.concurrent.SuccessCallback;
/**
* A pass-through {@code Future} handle that can be used for method signatures
@@ -74,7 +76,15 @@ public class AsyncResult<V> implements ListenableFuture<V> {
@Override
public void addCallback(ListenableFutureCallback<? super V> callback) {
callback.onSuccess(this.value);
addCallback(callback, callback);
}
@Override
public void addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback) {
try {
successCallback.onSuccess(this.value);
} catch(Throwable t) {
failureCallback.onFailure(t);
}
}
}