com.basho.riak.client.cap
Class DefaultRetrier

java.lang.Object
  extended by com.basho.riak.client.cap.DefaultRetrier
All Implemented Interfaces:
Retrier

public class DefaultRetrier
extends Object
implements Retrier

A basic retrier implementation that attempts *n* times before throwing a UnresolvedConflictException.

Construct it with the number of times a Callable should be attempted. When attempt is called with a Callable then Callable.call() is run attempts times before throwing a RiakRetryFailedException. It is important to note that there is no backoff between attempts.

Author:
russell

Constructor Summary
DefaultRetrier(int attempts)
           
 
Method Summary
<T> T
attempt(Callable<T> command)
          Called by RiakOperation execute methods to give some measure of fault tolerance.
static
<T> T
attempt(Callable<T> command, int times)
          Calls Callable.call() times before giving up and throwing a RiakRetryFailedException There is no back off.
static Retrier attempts(int attempts)
          Static factory method to create a default retrier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultRetrier

public DefaultRetrier(int attempts)
Parameters:
attempts - how many times the retrier should attempt the call before throwing a RiakRetryFailedException
Method Detail

attempt

public <T> T attempt(Callable<T> command)
          throws RiakRetryFailedException
Description copied from interface: Retrier
Called by RiakOperation execute methods to give some measure of fault tolerance.

Specified by:
attempt in interface Retrier
Type Parameters:
T - the Type the Callable.call() returns
Parameters:
command - the Callable
Returns:
the value of Callable.call()
Throws:
RiakRetryFailedException - if the retrier exceeds its bounds.

attempt

public static <T> T attempt(Callable<T> command,
                            int times)
                 throws RiakRetryFailedException
Calls Callable.call() times before giving up and throwing a RiakRetryFailedException There is no back off.

Type Parameters:
T - the Callable's return type.
Parameters:
command - the Callable to attempt
times - how many times to try before we throw
Returns:
the result of command
Throws:
RiakRetryFailedException - if the Callable throws an exception times times

attempts

public static Retrier attempts(int attempts)
Static factory method to create a default retrier

Parameters:
attempts - how many times the DefaultRetrier will attempt to call a Callable supplied to Retrier.attempt(Callable)
Returns:
a DefaultRetrier configured for attempts retries


Copyright © 2012. All Rights Reserved.