EMMA Coverage Report (generated Wed Oct 26 13:47:17 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% (85/85)100% (21/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RestClientModule100% (1/1)100% (8/8)100% (79/79)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): Cache 100% (1/1)100% (8/8)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 * 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.rest.config;
20 
21import java.util.Map;
22 
23import javax.inject.Named;
24import javax.inject.Singleton;
25 
26import org.jclouds.http.RequiresHttp;
27import org.jclouds.internal.ClassMethodArgs;
28import org.jclouds.rest.ConfiguresRestClient;
29import org.jclouds.rest.RestContext;
30import org.jclouds.rest.internal.RestContextImpl;
31 
32import com.google.common.cache.Cache;
33import com.google.common.cache.CacheBuilder;
34import com.google.common.collect.ImmutableMap;
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   Cache<ClassMethodArgs, Object> provideSyncDelegateMap(
129         CreateClientForCaller createClientForCaller) {
130      createClientForCaller.sync2Async = delegates;
131      return CacheBuilder.newBuilder().build(createClientForCaller);
132   }
133 
134}

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