Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (C) 2008 The Guava Authors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.common.util.concurrent;
A CheckedFuture is a ListenableFuture that includes versions of the get methods that can throw a checked exception. This makes it easier to create a future that executes logic which can throw an exception.

A common implementation is Futures.immediateCheckedFuture(java.lang.Object).

Implementations of this interface must adapt the exceptions thrown by Future#get(): java.util.concurrent.CancellationException, java.util.concurrent.ExecutionException and java.lang.InterruptedException into the type specified by the E type parameter.

This interface also extends the ListenableFuture interface to allow listeners to be added. This allows the future to be used as a normal java.util.concurrent.Future or as an asynchronous callback mechanism as needed. This allows multiple callbacks to be registered for a particular task, and the future will guarantee execution of all listeners when the task completes.

For a simpler alternative to CheckedFuture, consider accessing Future values with Futures.get().

Author(s):
Sven Mawson
Since:
1.0
public interface CheckedFuture<V, X extends Exception>
    extends ListenableFuture<V> {

  
Exception checking version of java.util.concurrent.Future.get() that will translate java.lang.InterruptedException, java.util.concurrent.CancellationException and java.util.concurrent.ExecutionException into application-specific exceptions.

Returns:
the result of executing the future.
Throws:
X on interruption, cancellation or execution exceptions.
  V checkedGet() throws X;

  
Exception checking version of java.util.concurrent.Future.get(long,java.util.concurrent.TimeUnit) that will translate java.lang.InterruptedException, java.util.concurrent.CancellationException and java.util.concurrent.ExecutionException into application-specific exceptions. On timeout this method throws a normal java.util.concurrent.TimeoutException.

Returns:
the result of executing the future.
Throws:
java.util.concurrent.TimeoutException if retrieving the result timed out.
X on interruption, cancellation or execution exceptions.
  V checkedGet(long timeoutTimeUnit unitthrows TimeoutException, X;
New to GrepCode? Check out our FAQ X