com.foxinmy.weixin4j.util
Class SettableFuture<T>

java.lang.Object
  extended by com.foxinmy.weixin4j.util.SettableFuture<T>
All Implemented Interfaces:
Future<T>

public class SettableFuture<T>
extends Object
implements Future<T>

A ListenableFuture whose value can be set via set(Object) or setException(Throwable). It may also be cancelled.

Inspired by com.google.common.util.concurrent.SettableFuture.

Since:
4.1
Author:
Mattias Severson, Rossen Stoyanchev

Constructor Summary
SettableFuture()
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
 T get()
          Retrieve the value.
 T get(long timeout, TimeUnit unit)
          Retrieve the value.
 boolean isCancelled()
           
 boolean isDone()
           
 boolean set(T value)
          Set the value of this future.
 boolean setException(Throwable exception)
          Set the exception of this future.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SettableFuture

public SettableFuture()
Method Detail

set

public boolean set(T value)
Set the value of this future. This method will return true if the value was set successfully, or false if the future has already been set or cancelled.

Parameters:
value - the value that will be set.
Returns:
true if the value was successfully set, else false.

setException

public boolean setException(Throwable exception)
Set the exception of this future. This method will return true if the exception was set successfully, or false if the future has already been set or cancelled.

Parameters:
exception - the value that will be set.
Returns:
true if the exception was successfully set, else false.

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel in interface Future<T>

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface Future<T>

isDone

public boolean isDone()
Specified by:
isDone in interface Future<T>

get

public T get()
      throws InterruptedException,
             ExecutionException
Retrieve the value.

Will return the value if it has been set via set(Object), throw an ExecutionException if it has been set via setException(Throwable) or throw a CancellationException if it has been cancelled.

Specified by:
get in interface Future<T>
Returns:
The value associated with this future.
Throws:
InterruptedException
ExecutionException

get

public T get(long timeout,
             TimeUnit unit)
      throws InterruptedException,
             ExecutionException,
             TimeoutException
Retrieve the value.

Will return the value if it has been set via set(Object), throw an ExecutionException if it has been set via setException(Throwable) or throw a CancellationException if it has been cancelled.

Specified by:
get in interface Future<T>
Parameters:
timeout - the maximum time to wait.
unit - the time unit of the timeout argument.
Returns:
The value associated with this future.
Throws:
InterruptedException
ExecutionException
TimeoutException


Copyright © 2014–2017. All rights reserved.