EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.http.handlers]

COVERAGE SUMMARY FOR SOURCE FILE [DelegatingRetryHandler.java]

nameclass, %method, %block, %line, %
DelegatingRetryHandler.java100% (1/1)40%  (2/5)63%  (40/63)71%  (12/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DelegatingRetryHandler100% (1/1)40%  (2/5)63%  (40/63)71%  (12/17)
getClientErrorRetryHandler (): HttpRetryHandler 0%   (0/1)0%   (0/3)0%   (0/1)
getRedirectionRetryHandler (): HttpRetryHandler 0%   (0/1)0%   (0/3)0%   (0/1)
getServerErrorRetryHandler (): HttpRetryHandler 0%   (0/1)0%   (0/3)0%   (0/1)
shouldRetryRequest (HttpCommand, HttpResponse): boolean 100% (1/1)67%  (28/42)78%  (7/9)
DelegatingRetryHandler (BackoffLimitedRetryHandler, RedirectionRetryHandler):... 100% (1/1)100% (12/12)100% (5/5)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.http.handlers;
20 
21import javax.inject.Singleton;
22 
23import org.jclouds.http.HttpCommand;
24import org.jclouds.http.HttpResponse;
25import org.jclouds.http.HttpRetryHandler;
26import org.jclouds.http.annotation.ClientError;
27import org.jclouds.http.annotation.Redirection;
28import org.jclouds.http.annotation.ServerError;
29 
30import com.google.common.annotations.VisibleForTesting;
31import com.google.inject.Inject;
32 
33/**
34 * Delegates to {@link HttpRetryHandler HttpRetryHandlers} who are annotated according to the
35 * response codes they relate to.
36 * 
37 * @author Adrian Cole
38 */
39@Singleton
40public class DelegatingRetryHandler implements HttpRetryHandler {
41 
42   @VisibleForTesting
43   @Inject(optional = true)
44   @Redirection
45   HttpRetryHandler redirectionRetryHandler;
46 
47   @VisibleForTesting
48   @Inject(optional = true)
49   @ClientError
50   HttpRetryHandler clientErrorRetryHandler;
51 
52   @VisibleForTesting
53   @Inject(optional = true)
54   @ServerError
55   HttpRetryHandler serverErrorRetryHandler;
56 
57   @Inject
58   public DelegatingRetryHandler(BackoffLimitedRetryHandler backOff,
59            RedirectionRetryHandler redirectionRetryHandler) {
60      this.serverErrorRetryHandler = backOff;
61      this.redirectionRetryHandler = redirectionRetryHandler;
62      this.clientErrorRetryHandler = HttpRetryHandler.NEVER_RETRY;
63   }
64 
65   public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
66      int statusCode = response.getStatusCode();
67      boolean retryRequest = false;
68      if (statusCode >= 300 && statusCode < 400) {
69         retryRequest = redirectionRetryHandler.shouldRetryRequest(command, response);
70      } else if (statusCode >= 400 && statusCode < 500) {
71         retryRequest = clientErrorRetryHandler.shouldRetryRequest(command, response);
72      } else if (statusCode >= 500) {
73         retryRequest = serverErrorRetryHandler.shouldRetryRequest(command, response);
74      }
75      return retryRequest;
76   }
77 
78   public HttpRetryHandler getRedirectionRetryHandler() {
79      return redirectionRetryHandler;
80   }
81 
82   public HttpRetryHandler getClientErrorRetryHandler() {
83      return clientErrorRetryHandler;
84   }
85 
86   public HttpRetryHandler getServerErrorRetryHandler() {
87      return serverErrorRetryHandler;
88   }
89}

[all classes][org.jclouds.http.handlers]
EMMA 2.0.5312 (C) Vladimir Roubtsov