EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.atmos.handlers]

COVERAGE SUMMARY FOR SOURCE FILE [AtmosClientErrorRetryHandler.java]

nameclass, %method, %block, %line, %
AtmosClientErrorRetryHandler.java0%   (0/1)0%   (0/2)0%   (0/97)0%   (0/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AtmosClientErrorRetryHandler0%   (0/1)0%   (0/2)0%   (0/97)0%   (0/24)
AtmosClientErrorRetryHandler (BackoffLimitedRetryHandler, AtmosUtils): void 0%   (0/1)0%   (0/15)0%   (0/6)
shouldRetryRequest (HttpCommand, HttpResponse): boolean 0%   (0/1)0%   (0/82)0%   (0/18)

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.atmos.handlers;
20 
21import javax.annotation.Resource;
22import javax.inject.Named;
23 
24import org.jclouds.Constants;
25import org.jclouds.atmos.domain.AtmosError;
26import org.jclouds.atmos.util.AtmosUtils;
27import org.jclouds.http.HttpCommand;
28import org.jclouds.http.HttpException;
29import org.jclouds.http.HttpResponse;
30import org.jclouds.http.HttpRetryHandler;
31import org.jclouds.http.HttpUtils;
32import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
33import org.jclouds.logging.Logger;
34 
35import com.google.inject.Inject;
36 
37/**
38 * Handles Retryable responses with error codes in the 4xx range
39 * 
40 * @author Adrian Cole
41 */
42public class AtmosClientErrorRetryHandler implements HttpRetryHandler {
43   private final AtmosUtils utils;
44   private final BackoffLimitedRetryHandler backoffHandler;
45 
46   @Inject
47   public AtmosClientErrorRetryHandler(BackoffLimitedRetryHandler backoffHandler,
48            AtmosUtils utils) {
49      this.backoffHandler = backoffHandler;
50      this.utils = utils;
51   }
52 
53   @Inject(optional = true)
54   @Named(Constants.PROPERTY_MAX_RETRIES)
55   private int retryCountLimit = 5;
56   @Resource
57   protected Logger logger = Logger.NULL;
58 
59   public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
60      if (command.getFailureCount() > retryCountLimit)
61         return false;
62      if (response.getStatusCode() == 404 && command.getCurrentRequest().getMethod().equals("DELETE")) {
63         command.incrementFailureCount();
64         return true;
65      } else if (response.getStatusCode() == 409 || response.getStatusCode() == 400) {
66         byte[] content = HttpUtils.closeClientButKeepContentStream(response);
67         // Content can be null in the case of HEAD requests
68         if (content != null) {
69            try {
70               AtmosError error = utils.parseAtmosErrorFromContent(command, response,
71                        new String(content));
72               if (error.getCode() == 1016) {
73                  return backoffHandler.shouldRetryRequest(command, response);
74               }
75               // don't increment count before here, since backoff handler does already
76               command.incrementFailureCount();
77            } catch (HttpException e) {
78               logger.warn(e, "error parsing response: %s", new String(content));
79            }
80         } else {
81            command.incrementFailureCount();
82         }
83         return true;
84      }
85      return false;
86   }
87 
88}

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