EMMA Coverage Report (generated Fri Aug 26 14:14:05 EDT 2011)
[all classes][org.jclouds.s3.config]

COVERAGE SUMMARY FOR SOURCE FILE [S3RestClientModule.java]

nameclass, %method, %block, %line, %
S3RestClientModule.java100% (2/2)73%  (8/11)93%  (80/86)83%  (15/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class S3RestClientModule100% (1/1)67%  (6/9)92%  (67/73)82%  (14/17)
bucketToRegion (): Map 0%   (0/1)0%   (0/2)0%   (0/1)
defaultRegionForBucket (String): String 0%   (0/1)0%   (0/2)0%   (0/1)
provideRequestSigner (RequestAuthorizeSignature): RequestSigner 0%   (0/1)0%   (0/2)0%   (0/1)
S3RestClientModule (Class, Class): void 100% (1/1)100% (5/5)100% (2/2)
bindErrorHandlers (): void 100% (1/1)100% (25/25)100% (4/4)
configure (): void 100% (1/1)100% (18/18)100% (5/5)
create (): S3RestClientModule 100% (1/1)100% (6/6)100% (1/1)
provideTimeStamp (Supplier): String 100% (1/1)100% (4/4)100% (1/1)
provideTimeStampCache (long, DateService): Supplier 100% (1/1)100% (9/9)100% (1/1)
     
class S3RestClientModule$1100% (1/1)100% (2/2)100% (13/13)100% (2/2)
S3RestClientModule$1 (S3RestClientModule, DateService): void 100% (1/1)100% (9/9)100% (1/1)
get (): String 100% (1/1)100% (4/4)100% (1/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.s3.config;
20 
21import java.util.Map;
22import java.util.concurrent.TimeUnit;
23 
24import javax.annotation.Nullable;
25import javax.inject.Named;
26import javax.inject.Singleton;
27 
28import org.jclouds.Constants;
29import org.jclouds.aws.config.AWSRestClientModule;
30import org.jclouds.date.DateService;
31import org.jclouds.date.TimeStamp;
32import org.jclouds.http.HttpErrorHandler;
33import org.jclouds.http.RequiresHttp;
34import org.jclouds.http.annotation.ClientError;
35import org.jclouds.http.annotation.Redirection;
36import org.jclouds.http.annotation.ServerError;
37import org.jclouds.location.Region;
38import org.jclouds.rest.ConfiguresRestClient;
39import org.jclouds.rest.RequestSigner;
40import org.jclouds.s3.Bucket;
41import org.jclouds.s3.S3AsyncClient;
42import org.jclouds.s3.S3Client;
43import org.jclouds.s3.filters.RequestAuthorizeSignature;
44import org.jclouds.s3.handlers.ParseS3ErrorFromXmlContent;
45 
46import com.google.common.base.Supplier;
47import com.google.common.base.Suppliers;
48import com.google.common.collect.Maps;
49import com.google.inject.Provides;
50import com.google.inject.Scopes;
51 
52/**
53 * Configures the S3 connection, including logging and http transport.
54 * 
55 * @author Adrian Cole
56 */
57@ConfiguresRestClient
58@RequiresHttp
59public class S3RestClientModule<S extends S3Client, A extends S3AsyncClient> extends AWSRestClientModule<S, A> {
60   public static S3RestClientModule<S3Client, S3AsyncClient> create() {
61      return new S3RestClientModule<S3Client, S3AsyncClient>(S3Client.class, S3AsyncClient.class);
62   }
63 
64   public S3RestClientModule(Class<S> sync, Class<A> async) {
65      super(sync, async);
66   }
67 
68   @Provides
69   @Bucket
70   @Singleton
71   protected Map<String, String> bucketToRegion() {
72      return Maps.newConcurrentMap();
73   }
74 
75   @Provides
76   @Bucket
77   @Singleton
78   @Nullable
79   protected String defaultRegionForBucket(@Nullable @Region String defaultRegion) {
80      return defaultRegion;
81   }
82 
83   @Override
84   protected void configure() {
85      install(new S3ObjectModule());
86      install(new S3ParserModule());
87      bind(RequestAuthorizeSignature.class).in(Scopes.SINGLETON);
88      super.configure();
89   }
90 
91   @Override
92   protected void bindErrorHandlers() {
93      bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseS3ErrorFromXmlContent.class);
94      bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseS3ErrorFromXmlContent.class);
95      bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseS3ErrorFromXmlContent.class);
96   }
97 
98   @Provides
99   @Singleton
100   protected RequestSigner provideRequestSigner(RequestAuthorizeSignature in) {
101      return in;
102   }
103 
104   @Provides
105   @TimeStamp
106   protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
107      return cache.get();
108   }
109 
110   /**
111    * borrowing concurrency code to ensure that caching takes place properly
112    */
113   @Provides
114   @TimeStamp
115   @Singleton
116   protected Supplier<String> provideTimeStampCache(@Named(Constants.PROPERTY_SESSION_INTERVAL) long seconds,
117         final DateService dateService) {
118      return Suppliers.memoizeWithExpiration(new Supplier<String>() {
119         public String get() {
120            return dateService.rfc822DateFormat();
121         }
122      }, seconds, TimeUnit.SECONDS);
123   }
124}

[all classes][org.jclouds.s3.config]
EMMA 2.0.5312 (C) Vladimir Roubtsov