org.jclouds.rest.suppliers
Class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T>

java.lang.Object
  extended by com.google.common.collect.ForwardingObject
      extended by org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T>
All Implemented Interfaces:
com.google.common.base.Supplier<T>

public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T>
extends com.google.common.collect.ForwardingObject
implements com.google.common.base.Supplier<T>

This will retry the supplier if it encounters a timeout exception, but not if it encounters an AuthorizationException.

A shared exception reference is used so that anyone who encounters an authorizationexception will be short-circuited. This prevents accounts from being locked out.

details

http://code.google.com/p/google-guice/issues/detail?id=483 guice doesn't remember when singleton providers throw exceptions. in this case, if the supplier fails with an authorization exception, it is called again for each provider method that depends on it. To short-circuit this, we remember the last exception trusting that guice is single-threaded. Note this implementation is folded into the same class, vs being decorated as stacktraces are exceptionally long and difficult to grok otherwise. We use LoadingCache to deal with concurrency issues related to the supplier.

Author:
Adrian Cole

Method Summary
static
<T> MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T>
create(AtomicReference<AuthorizationException> authException, com.google.common.base.Supplier<T> delegate, long duration, TimeUnit unit)
           
protected  com.google.common.base.Supplier<T> delegate()
           
 T get()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static <T> MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> create(AtomicReference<AuthorizationException> authException,
                                                                                         com.google.common.base.Supplier<T> delegate,
                                                                                         long duration,
                                                                                         TimeUnit unit)

delegate

protected com.google.common.base.Supplier<T> delegate()
Specified by:
delegate in class com.google.common.collect.ForwardingObject

get

public T get()
Specified by:
get in interface com.google.common.base.Supplier<T>

toString

public String toString()
Overrides:
toString in class com.google.common.collect.ForwardingObject


Copyright © 2009-2013 jclouds. All Rights Reserved.