Did this page help you?

   Yes   No   Tell us about it...

com.amazonaws.services.simpleworkflow.flow.core
Class Settable<V>

java.lang.Object
  extended by com.amazonaws.services.simpleworkflow.flow.core.Promise<V>
      extended by com.amazonaws.services.simpleworkflow.flow.core.Settable<V>
Type Parameters:
V - The type of value accepted and returned by this Settable.Use Void to represent Promise that indicates completion of operation that doesn't return a value.

public class Settable<V>
extends Promise<V>

It is an implementation of Promise, which exposes an additional set(Object) and chain(Promise) methods. Calling set(Object) puts it in ready state, with value retrievable through get() method. chain(Promise) links state of this Settable to another Promise. When another promise changes its state to ready the chained one is also becomes ready.

Use settable.set(null) to set Settable<Void> to the ready state.

Settable is frequently used to return data from code contained in anonymous classes. For example:

 
 Promise<Integer> foo() {
     final Settable<Integer> result = new Settable<Integer>();
     new TryCatch() {
                            
         protected void doTry() throws Throwable {
             Promise<Integer> activity1Result = activities.callActivity1();
             result.chain(activity1Result);
         }
                            
         protected void doCatch(Throwable e) throws Throwable {
             Promise<Void> handled = handleFailure(e);
             rethrow(e, handled);
         }
      };
      return result;
 }
 
 


Constructor Summary
Settable()
           
Settable(V value)
           
 
Method Summary
 void chain(Promise<V> chainTo)
          Used to chain this Settable with the passed in Promise.
 V get()
           
 java.lang.String getDescription()
           
 boolean isReady()
           
 void set(V value)
           
 void setDescription(java.lang.String description)
           
 java.lang.String toString()
           
 void unchain()
          Used to unchain this Settable from the Promise object passed in last invocation of chain.
 
Methods inherited from class com.amazonaws.services.simpleworkflow.flow.core.Promise
asPromise, Void
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Settable

public Settable(V value)

Settable

public Settable()
Method Detail

get

public V get()
Specified by:
get in class Promise<V>
Returns:
The value passed in when set() is called
Throws:
java.lang.IllegalStateException - If set() is never called for this instance of Settable

isReady

public boolean isReady()
Specified by:
isReady in class Promise<V>
Returns:
true if set() is called for this Settable

set

public void set(V value)
Parameters:
value - Object to return when get() is called for this Settable. Use null to set Settable<Void> to the ready state.
Throws:
java.lang.IllegalStateException - if the Promise is already in ready state

chain

public void chain(Promise<V> chainTo)
Used to chain this Settable with the passed in Promise. This allows the Settable to be ready whenever the passed in Promise is ready and the value for the chained Promise can be retrieved by calling get() method on this Settable.

Parameters:
chainTo - Promise object to chain this Settable to. Chaining to null equates calling set(Object) with null argument.
Throws:
java.lang.IllegalStateException - if Settable is already in ready state or it is already chained to some other Promise
See Also:
unchain()

unchain

public void unchain()
Used to unchain this Settable from the Promise object passed in last invocation of chain. There is no requirement to unchain unless there is a need to chain the Settable to another Promise. Such need usually appears when implementing recursive functions or in TryCatchFinally.doCatch(Throwable) blocks. It is safe to call unchain if chain is never called for this Settable.

Throws:
java.lang.IllegalStateException - If the Promise it is chained to is already in the ready state

getDescription

public java.lang.String getDescription()
Overrides:
getDescription in class Promise<V>
Returns:
human friendly description on what this promise represents. Emitted for example as part of AsyncScope.getAsynchronousThreadDumpAsString()

setDescription

public void setDescription(java.lang.String description)
Parameters:
description - human readable description of what this Promise represents.
See Also:
Promise.getDescription()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.