Java 类com.google.common.util.concurrent.ForwardingFuture 实例源码

项目:status    文件:TestHealthcheckFramework.java   
@Override
public Future<CheckResult> submit (final Dependency dependency) {
    final Future<CheckResult> delegate = super.submit(dependency);

    return new ForwardingFuture<CheckResult>() {
        @Override
        protected Future<CheckResult> delegate() {
            return delegate;
        }

        @Override
        public CheckResult get () throws InterruptedException, ExecutionException {
            doInterrupt();
            return super.get();
        }

        @Override
        public CheckResult get (final long l, @Nonnull final TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
            doInterrupt();
            return super.get(l, timeUnit);
        }

        private void doInterrupt() throws InterruptedException {
            if (shouldInterrupt.get()) {
                Thread.currentThread().interrupt();
                Thread.sleep(1000);

                // Shouldn't get here.
                testInvalid.set(true);
            }
        }
    };
}