下面列出了怎么用com.google.common.util.concurrent.ForwardingListenableFuture的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates a new ListenableFuture whose result is set from the supplied
* future when it completes. Cancelling the supplied future will also cancel
* the returned future, but cancelling the returned future will have no
* effect on the supplied future.
*/
public static <T> ListenableFuture<T> nonCancellationPropagating(
final ListenableFuture<T> future)
{
return new ForwardingListenableFuture.SimpleForwardingListenableFuture<T>(future)
{
@Override
public boolean cancel(boolean mayInterruptIfNecessary)
{
return false;
}
};
}
public <T> ListenableFuture<T> scopeCallbacks(final ListenableFuture<T> callback) {
final ScopedObjects scope = getScope();
return new ForwardingListenableFuture<T>() {
@Override
protected ListenableFuture<T> delegate() {
return callback;
}
@Override
public void addListener(Runnable listener, Executor exec) {
super.addListener(listener, scope(exec, scope));
}
};
}