com.atlassian.util.concurrent
Class ForwardingPromise<A>

java.lang.Object
  extended by com.google.common.collect.ForwardingObject
      extended by com.google.common.util.concurrent.ForwardingFuture<V>
          extended by com.google.common.util.concurrent.ForwardingListenableFuture<A>
              extended by com.atlassian.util.concurrent.ForwardingPromise<A>
All Implemented Interfaces:
Promise<A>, com.google.common.util.concurrent.ListenableFuture<A>, Future<A>

@Beta
public abstract class ForwardingPromise<A>
extends com.google.common.util.concurrent.ForwardingListenableFuture<A>
implements Promise<A>

A promise which forwards all its method calls to another promise. Subclasses should override one or more methods to modify the behavior of the backing Promise as desired per the decorator pattern.

Since:
2.4

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.common.util.concurrent.ForwardingListenableFuture
com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture<V>
 
Nested classes/interfaces inherited from class com.google.common.util.concurrent.ForwardingFuture
com.google.common.util.concurrent.ForwardingFuture.SimpleForwardingFuture<V>
 
Constructor Summary
protected ForwardingPromise()
          Constructor for use by subclasses.
 
Method Summary
 A claim()
          Blocks the thread waiting for a result.
protected abstract  Promise<A> delegate()
           
 Promise<A> done(Effect<? super A> e)
          Registers a callback to be called when the promised object is available.
 Promise<A> fail(Effect<Throwable> e)
          Registers a callback to be called when an exception is thrown.
<B> Promise<B>
flatMap(com.google.common.base.Function<? super A,? extends Promise<? extends B>> function)
          Transforms this promise from one type to another by way of a transformation function that returns a new Promise, leaving the strategy for that promise production up to the function.
<B> Promise<B>
fold(com.google.common.base.Function<Throwable,? extends B> handleThrowable, com.google.common.base.Function<? super A,? extends B> function)
          Transform this promise from one type to another, also providing a strategy for dealing with any exceptions encountered.
<B> Promise<B>
map(com.google.common.base.Function<? super A,? extends B> function)
          Transforms this Promise from one type to another by way of a transformation function.
 Promise<A> recover(com.google.common.base.Function<Throwable,? extends A> handleThrowable)
          Recover from an exception using the supplied exception strategy
 Promise<A> then(com.google.common.util.concurrent.FutureCallback<? super A> callback)
          Registers a FutureCallback to handle both success and failure (exception) cases.
 
Methods inherited from class com.google.common.util.concurrent.ForwardingListenableFuture
addListener
 
Methods inherited from class com.google.common.util.concurrent.ForwardingFuture
cancel, get, get, isCancelled, isDone
 
Methods inherited from class com.google.common.collect.ForwardingObject
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.common.util.concurrent.ListenableFuture
addListener
 
Methods inherited from interface java.util.concurrent.Future
cancel, get, get, isCancelled, isDone
 

Constructor Detail

ForwardingPromise

protected ForwardingPromise()
Constructor for use by subclasses.

Method Detail

delegate

protected abstract Promise<A> delegate()
Overrides:
delegate in class com.google.common.util.concurrent.ForwardingListenableFuture<A>

claim

public A claim()
Description copied from interface: Promise
Blocks the thread waiting for a result. Exceptions are thrown as runtime exceptions.

Specified by:
claim in interface Promise<A>
Returns:
The promised object

done

public Promise<A> done(Effect<? super A> e)
Description copied from interface: Promise
Registers a callback to be called when the promised object is available. May not be executed in the same thread as the caller.

Specified by:
done in interface Promise<A>
Parameters:
e - The effect to perform with the result
Returns:
This object for chaining

fail

public Promise<A> fail(Effect<Throwable> e)
Description copied from interface: Promise
Registers a callback to be called when an exception is thrown. May not be executed in the same thread as the caller.

Specified by:
fail in interface Promise<A>
Parameters:
e - The effect to perform with the throwable
Returns:
This object for chaining

then

public Promise<A> then(com.google.common.util.concurrent.FutureCallback<? super A> callback)
Description copied from interface: Promise
Registers a FutureCallback to handle both success and failure (exception) cases. May not be executed in the same thread as the caller.

See Promises.futureCallback(Effect, Effect) Promises.onSuccessDo(Effect) and Promises.onFailureDo(Effect) for easy ways of turning an Effect into a FutureCallback

Specified by:
then in interface Promise<A>
Parameters:
callback - The future callback
Returns:
This object for chaining

map

public <B> Promise<B> map(com.google.common.base.Function<? super A,? extends B> function)
Description copied from interface: Promise
Transforms this Promise from one type to another by way of a transformation function.

Note: This is designed for cases in which the transformation is fast and lightweight, as the method is performed on the same thread as the thing producing this promise. For more details see the note on Futures.transform(Future, Function).

Specified by:
map in interface Promise<A>
Parameters:
function - The transformation function
Returns:
A new promise resulting from the transformation

flatMap

public <B> Promise<B> flatMap(com.google.common.base.Function<? super A,? extends Promise<? extends B>> function)
Description copied from interface: Promise
Transforms this promise from one type to another by way of a transformation function that returns a new Promise, leaving the strategy for that promise production up to the function.

Note this is known as flatMap as it first maps to a Promise<Promise<A>> and then flattens that out into a single layer Promise.

Specified by:
flatMap in interface Promise<A>
Parameters:
function - The transformation function to a new Promise value
Returns:
A new promise resulting from the transformation

recover

public Promise<A> recover(com.google.common.base.Function<Throwable,? extends A> handleThrowable)
Description copied from interface: Promise
Recover from an exception using the supplied exception strategy

Specified by:
recover in interface Promise<A>
Parameters:
handleThrowable - rehabilitate the exception with a value of type B
Returns:
A new promise that will not throw an exception (unless handleThrowable itself threw).

fold

public <B> Promise<B> fold(com.google.common.base.Function<Throwable,? extends B> handleThrowable,
                           com.google.common.base.Function<? super A,? extends B> function)
Description copied from interface: Promise
Transform this promise from one type to another, also providing a strategy for dealing with any exceptions encountered.

Specified by:
fold in interface Promise<A>
Parameters:
handleThrowable - rehabilitate the exception with a value of type B
function - mapping function
Returns:
A new promise resulting from the catamorphic transformation. This promise will not throw an exception (unless handleThrowable itself threw).


Copyright © 2014 Atlassian. All Rights Reserved.