org.jclouds.openstack.trove.v1.predicates
Class InstancePredicates

java.lang.Object
  extended by org.jclouds.openstack.trove.v1.predicates.InstancePredicates

public class InstancePredicates
extends Object

Tests to see if instance has reached status. This class is most useful when paired with a RetryablePredicate as in the code below. This class can be used to block execution until the Instance status has reached a desired state. This is useful when your Instance needs to be 100% ready before you can continue with execution.

 Instance instance = instanceApi.create(100);
 
 RetryablePredicate<String> awaitAvailable = RetryablePredicate.create(
    InstancePredicates.available(instanceApi), 600, 10, 10, TimeUnit.SECONDS);
 
 if (!awaitAvailable.apply(instance.getId())) {
    throw new TimeoutException("Timeout on instance: " + instance); 
 }    
 
 
You can also use the static convenience methods as follows.
 Instance instance = instanceApi.create(100);
 
 if (!InstancePredicates.awaitAvailable(instanceApi).apply(instance.getId())) {
    throw new TimeoutException("Timeout on instance: " + instance);     
 }
 
 


Constructor Summary
InstancePredicates()
           
 
Method Summary
static com.google.common.base.Predicate<Instance> awaitAvailable(InstanceApi instanceApi)
          Wait until an Instance is Available.
static com.google.common.base.Predicate<Instance> awaitDeleted(InstanceApi instanceApi)
          Wait until an Instance no longer exists.
static com.google.common.base.Predicate<Instance> awaitStatus(InstanceApi instanceApi, Instance.Status status, long maxWaitInSec, long periodInSec)
          Wait until instance is in the status specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstancePredicates

public InstancePredicates()
Method Detail

awaitAvailable

public static com.google.common.base.Predicate<Instance> awaitAvailable(InstanceApi instanceApi)
Wait until an Instance is Available.

Parameters:
instanceApi - The InstanceApi in the zone where your Instance resides.
Returns:
RetryablePredicate That will check the status every 5 seconds for a maxiumum of 10 minutes.

awaitDeleted

public static com.google.common.base.Predicate<Instance> awaitDeleted(InstanceApi instanceApi)
Wait until an Instance no longer exists.

Parameters:
instanceApi - The InstanceApi in the zone where your Instance resides.
Returns:
RetryablePredicate That will check whether the Instance exists. every 5 seconds for a maxiumum of 10 minutes.

awaitStatus

public static com.google.common.base.Predicate<Instance> awaitStatus(InstanceApi instanceApi,
                                                                     Instance.Status status,
                                                                     long maxWaitInSec,
                                                                     long periodInSec)
Wait until instance is in the status specified.

Parameters:
instanceApi - The InstanceApi in the zone where your Instance resides.
status - Wait until instance in in this status.
maxWaitInSec - Maximum time to wait.
periodInSec - Interval between retries.
Returns:
RetryablePredicate That will check whether the Instance exists.


Copyright © 2009-2014 The Apache Software Foundation. All Rights Reserved.