本文整理汇总了Java中com.google.common.util.concurrent.ForwardingListenableFuture类的典型用法代码示例。如果您正苦于以下问题:Java ForwardingListenableFuture类的具体用法?Java ForwardingListenableFuture怎么用?Java ForwardingListenableFuture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ForwardingListenableFuture类属于com.google.common.util.concurrent包,在下文中一共展示了ForwardingListenableFuture类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scopeCallbacks
import com.google.common.util.concurrent.ForwardingListenableFuture; //导入依赖的package包/类
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));
}
};
}
示例2: wrapListenableFuture
import com.google.common.util.concurrent.ForwardingListenableFuture; //导入依赖的package包/类
private <T> ListenableFuture<T> wrapListenableFuture(final ListenableFuture<T> delegate) {
/*
* This creates a forwarding Future that overrides calls to get(...) to check, via the
* ThreadLocal, if the caller is doing a blocking call on a thread from this executor. If
* so, we detect this as a deadlock and throw an ExecutionException even though it may not
* be a deadlock if there are more than 1 thread in the pool. Either way, there's bad
* practice somewhere, either on the client side for doing a blocking call or in the
* framework's threading model.
*/
return new ForwardingListenableFuture.SimpleForwardingListenableFuture<T>(delegate) {
@Override
public T get() throws InterruptedException, ExecutionException {
checkDeadLockDetectorTL();
return super.get();
}
@Override
public T get(final long timeout, @Nonnull final TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
checkDeadLockDetectorTL();
return super.get(timeout, unit);
}
void checkDeadLockDetectorTL() throws ExecutionException {
if (deadlockDetector.get().isSet()) {
throw new ExecutionException("A potential deadlock was detected.",
deadlockExceptionFunction.get());
}
}
};
}