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

COVERAGE SUMMARY FOR SOURCE FILE [RestClientModule.java]

nameclass, %method, %block, %line, %
RestClientModule.java100% (2/2)100% (9/9)100% (87/87)100% (21/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RestClientModule100% (1/1)100% (8/8)100% (81/81)100% (21/21)
RestClientModule (Class, Class): void 100% (1/1)100% (8/8)100% (2/2)
RestClientModule (Class, Class, Map): void 100% (1/1)100% (12/12)100% (5/5)
bindAsyncClient (): void 100% (1/1)100% (6/6)100% (2/2)
bindClient (): void 100% (1/1)100% (10/10)100% (2/2)
bindErrorHandlers (): void 100% (1/1)100% (1/1)100% (1/1)
bindRetryHandlers (): void 100% (1/1)100% (1/1)100% (1/1)
configure (): void 100% (1/1)100% (33/33)100% (6/6)
provideSyncDelegateMap (CreateClientForCaller): ConcurrentMap 100% (1/1)100% (10/10)100% (2/2)
     
class RestClientModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
RestClientModule$1 (RestClientModule): void 100% (1/1)100% (6/6)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.rest.config;
20 
21import java.util.Map;
22import java.util.concurrent.ConcurrentMap;
23 
24import javax.inject.Named;
25import javax.inject.Singleton;
26 
27import org.jclouds.http.RequiresHttp;
28import org.jclouds.internal.ClassMethodArgs;
29import org.jclouds.rest.ConfiguresRestClient;
30import org.jclouds.rest.RestContext;
31import org.jclouds.rest.internal.RestContextImpl;
32 
33import com.google.common.collect.ImmutableMap;
34import com.google.common.collect.MapMaker;
35import com.google.inject.AbstractModule;
36import com.google.inject.Provides;
37import com.google.inject.Scopes;
38import com.google.inject.TypeLiteral;
39import com.google.inject.util.Types;
40 
41/**
42 * 
43 * @author Adrian Cole
44 */
45@ConfiguresRestClient
46@RequiresHttp
47public class RestClientModule<S, A> extends AbstractModule {
48 
49   protected final Class<A> asyncClientType;
50   protected final Class<S> syncClientType;
51   protected final Map<Class<?>, Class<?>> delegates;
52 
53   public RestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
54         Map<Class<?>, Class<?>> delegates) {
55      this.asyncClientType = asyncClientType;
56      this.syncClientType = syncClientType;
57      this.delegates = delegates;
58   }
59 
60   public RestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
61      this(syncClientType, asyncClientType, ImmutableMap
62            .<Class<?>, Class<?>> of(syncClientType, asyncClientType));
63   }
64 
65   @SuppressWarnings({ "unchecked", "rawtypes" })
66   @Override
67   protected void configure() {
68      // Ensures the restcontext can be looked up without generic types.
69      bind(new TypeLiteral<RestContext>() {
70      }).to(
71            (TypeLiteral) TypeLiteral.get(Types.newParameterizedType(
72                  RestContextImpl.class, syncClientType, asyncClientType))).in(
73            Scopes.SINGLETON);
74      bindAsyncClient();
75      bindClient();
76      bindErrorHandlers();
77      bindRetryHandlers();
78   }
79 
80   /**
81    * overrides this to change the default retry handlers for the http engine
82    * 
83    * ex.
84    * 
85    * <pre>
86    * bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
87    *       AWSRedirectionRetryHandler.class);
88    * bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
89    *       AWSClientErrorRetryHandler.class);
90    * </pre>
91    * 
92    */
93   protected void bindRetryHandlers() {
94   }
95 
96   /**
97    * overrides this to change the default error handlers for the http engine
98    * 
99    * ex.
100    * 
101    * <pre>
102    * bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
103    *       ParseAWSErrorFromXmlContent.class);
104    * bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
105    *       ParseAWSErrorFromXmlContent.class);
106    * bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
107    *       ParseAWSErrorFromXmlContent.class);
108    * </pre>
109    * 
110    * 
111    */
112   protected void bindErrorHandlers() {
113   }
114 
115   protected void bindAsyncClient() {
116      BinderUtils.bindAsyncClient(binder(), asyncClientType);
117   }
118 
119   protected void bindClient() {
120      BinderUtils.bindClient(binder(), syncClientType, asyncClientType,
121            delegates);
122   }
123 
124 
125   @Provides
126   @Singleton
127   @Named("sync")
128   ConcurrentMap<ClassMethodArgs, Object> provideSyncDelegateMap(
129         CreateClientForCaller createClientForCaller) {
130      createClientForCaller.sync2Async = delegates;
131      return new MapMaker().makeComputingMap(createClientForCaller);
132   }
133 
134}

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