Example usage for org.springframework.util.concurrent ListenableFuture isDone

List of usage examples for org.springframework.util.concurrent ListenableFuture isDone

Introduction

In this page you can find the example usage for org.springframework.util.concurrent ListenableFuture isDone.

Prototype

boolean isDone();

Source Link

Document

Returns true if this task completed.

Usage

From source file:org.springframework.cloud.sleuth.instrument.web.client.TraceAsyncRestTemplate.java

@Override
protected <T> ListenableFuture<T> doExecute(URI url, HttpMethod method, AsyncRequestCallback requestCallback,
        ResponseExtractor<T> responseExtractor) throws RestClientException {
    final ListenableFuture<T> future = super.doExecute(url, method, requestCallback, responseExtractor);
    final Span span = this.tracer.getCurrentSpan();
    future.addCallback(new TraceListenableFutureCallback<>(this.tracer, span));
    // potential race can happen here
    if (span != null && span.equals(this.tracer.getCurrentSpan())) {
        this.tracer.detach(span);
    }/*w w w .java2 s.  c o  m*/
    return new ListenableFuture<T>() {

        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            return future.cancel(mayInterruptIfRunning);
        }

        @Override
        public boolean isCancelled() {
            return future.isCancelled();
        }

        @Override
        public boolean isDone() {
            return future.isDone();
        }

        @Override
        public T get() throws InterruptedException, ExecutionException {
            return future.get();
        }

        @Override
        public T get(long timeout, TimeUnit unit)
                throws InterruptedException, ExecutionException, TimeoutException {
            return future.get(timeout, unit);
        }

        @Override
        public void addCallback(ListenableFutureCallback<? super T> callback) {
            future.addCallback(new TraceListenableFutureCallbackWrapper<>(TraceAsyncRestTemplate.this.tracer,
                    span, callback));
        }

        @Override
        public void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback) {
            future.addCallback(
                    new TraceSuccessCallback<>(TraceAsyncRestTemplate.this.tracer, span, successCallback),
                    new TraceFailureCallback(TraceAsyncRestTemplate.this.tracer, span, failureCallback));
        }
    };
}