EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.rest.suppliers]

COVERAGE SUMMARY FOR SOURCE FILE [MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java]

nameclass, %method, %block, %line, %
MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java0%   (0/1)0%   (0/3)0%   (0/40)0%   (0/6)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier0%   (0/1)0%   (0/3)0%   (0/40)0%   (0/6)
MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier (AtomicReference... 0%   (0/1)0%   (0/19)0%   (0/4)
get (): Object 0%   (0/1)0%   (0/4)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/17)0%   (0/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.rest.suppliers;
20 
21import static com.google.common.base.Suppliers.memoizeWithExpiration;
22 
23import java.util.concurrent.TimeUnit;
24import java.util.concurrent.atomic.AtomicReference;
25 
26import org.jclouds.concurrent.RetryOnTimeOutExceptionSupplier;
27import org.jclouds.rest.AuthorizationException;
28 
29import com.google.common.base.Supplier;
30 
31/**
32 * This will retry the supplier if it encounters a timeout exception, but not if it encounters an
33 * AuthorizationException.
34 * <p/>
35 * A shared exception reference is used so that anyone who encounters an authorizationexception will
36 * be short-circuited. This prevents accounts from being locked out.
37 * 
38 * <h3>details</h3>
39 * http://code.google.com/p/google-guice/issues/detail?id=483 guice doesn't remember when singleton
40 * providers throw exceptions. in this case, if the supplier fails with an authorization exception,
41 * it is called again for each provider method that depends on it. To short-circuit this, we
42 * remember the last exception trusting that guice is single-threaded.
43 * 
44 * @author Adrian Cole
45 */
46public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> implements Supplier<T> {
47   private final Supplier<T> delegate;
48   private final long seconds;
49 
50   public MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
51         AtomicReference<AuthorizationException> authException, long seconds, Supplier<T> delegate) {
52      this.delegate = memoizeWithExpiration(new RetryOnTimeOutExceptionSupplier<T>(
53            new SetAndThrowAuthorizationExceptionSupplier<T>(delegate, authException)), seconds, TimeUnit.SECONDS);
54      this.seconds = seconds;
55   }
56 
57   @Override
58   public T get() {
59      return delegate.get();
60   }
61 
62   @Override
63   public String toString() {
64      return "memoizeWithExpiration(" + delegate + ", seconds=" + seconds + ")";
65   }
66}

[all classes][org.jclouds.rest.suppliers]
EMMA 2.0.5312 (C) Vladimir Roubtsov