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

COVERAGE SUMMARY FOR SOURCE FILE [RestModule.java]

nameclass, %method, %block, %line, %
RestModule.java100% (4/4)100% (9/9)100% (140/140)100% (27/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RestModule100% (1/1)100% (4/4)100% (59/59)100% (13/13)
RestModule (): void 100% (1/1)100% (3/3)100% (2/2)
configure (): void 100% (1/1)100% (48/48)100% (9/9)
provideAsyncDelegateMap (RestModule$CreateAsyncClientForCaller): Cache 100% (1/1)100% (4/4)100% (1/1)
seedAnnotationCache (SeedAnnotationCache): Cache 100% (1/1)100% (4/4)100% (1/1)
     
class RestModule$CreateAsyncClientForCaller100% (1/1)100% (2/2)100% (64/64)100% (12/12)
RestModule$CreateAsyncClientForCaller (Injector, AsyncRestClientProxy$Factory... 100% (1/1)100% (9/9)100% (4/4)
load (ClassMethodArgs): Object 100% (1/1)100% (55/55)100% (8/8)
     
class RestModule$CreateAsyncClientForCaller$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
RestModule$CreateAsyncClientForCaller$1 (RestModule$CreateAsyncClientForCalle... 100% (1/1)100% (6/6)100% (1/1)
     
class RestModule$Factory100% (1/1)100% (2/2)100% (11/11)100% (2/2)
RestModule$Factory (): void 100% (1/1)100% (3/3)100% (1/1)
create (HttpRequest, Function): TransformingHttpCommand 100% (1/1)100% (8/8)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 javax.inject.Named;
22import javax.inject.Singleton;
23import javax.ws.rs.core.UriBuilder;
24 
25import org.jclouds.functions.IdentityFunction;
26import org.jclouds.http.HttpRequest;
27import org.jclouds.http.HttpResponse;
28import org.jclouds.http.TransformingHttpCommand;
29import org.jclouds.http.TransformingHttpCommandExecutorService;
30import org.jclouds.http.TransformingHttpCommandImpl;
31import org.jclouds.http.functions.config.SaxParserModule;
32import org.jclouds.internal.ClassMethodArgs;
33import org.jclouds.json.config.GsonModule;
34import org.jclouds.rest.AsyncClientFactory;
35import org.jclouds.rest.HttpAsyncClient;
36import org.jclouds.rest.HttpClient;
37import org.jclouds.rest.binders.BindToJsonPayloadWrappedWith;
38import org.jclouds.rest.internal.AsyncRestClientProxy;
39import org.jclouds.rest.internal.RestAnnotationProcessor;
40import org.jclouds.rest.internal.SeedAnnotationCache;
41 
42import com.google.common.base.Function;
43import com.google.common.cache.Cache;
44import com.google.common.cache.CacheBuilder;
45import com.google.common.cache.CacheLoader;
46import com.google.common.collect.ImmutableMap;
47import com.google.inject.AbstractModule;
48import com.google.inject.Inject;
49import com.google.inject.Injector;
50import com.google.inject.Key;
51import com.google.inject.Provides;
52import com.google.inject.Scopes;
53import com.google.inject.TypeLiteral;
54import com.google.inject.assistedinject.FactoryModuleBuilder;
55import com.google.inject.name.Names;
56import com.google.inject.util.Types;
57import com.sun.jersey.api.uri.UriBuilderImpl;
58 
59/**
60 * 
61 * @author Adrian Cole
62 */
63public class RestModule extends AbstractModule {
64 
65   @Override
66   protected void configure() {
67      install(new SaxParserModule());
68      install(new GsonModule());
69      install(new FactoryModuleBuilder().build(BindToJsonPayloadWrappedWith.Factory.class));
70      bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE);
71      bind(UriBuilder.class).to(UriBuilderImpl.class);
72      bind(AsyncRestClientProxy.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
73      BinderUtils.bindAsyncClient(binder(), HttpAsyncClient.class);
74      BinderUtils.bindClient(binder(), HttpClient.class, HttpAsyncClient.class, ImmutableMap.<Class<?>, Class<?>> of(
75               HttpClient.class, HttpAsyncClient.class));
76   }
77 
78   @Provides
79   @Singleton
80   protected Cache<Class<?>, Boolean> seedAnnotationCache(SeedAnnotationCache seedAnnotationCache) {
81      return CacheBuilder.newBuilder().build(seedAnnotationCache);
82   }
83 
84   @Provides
85   @Singleton
86   @Named("async")
87   Cache<ClassMethodArgs, Object> provideAsyncDelegateMap(CreateAsyncClientForCaller createAsyncClientForCaller) {
88      return CacheBuilder.newBuilder().build(createAsyncClientForCaller);
89   }
90 
91   static class CreateAsyncClientForCaller extends CacheLoader<ClassMethodArgs, Object> {
92      private final Injector injector;
93      private final AsyncRestClientProxy.Factory factory;
94 
95      @Inject
96      CreateAsyncClientForCaller(Injector injector, AsyncRestClientProxy.Factory factory) {
97         this.injector = injector;
98         this.factory = factory;
99      }
100 
101      @SuppressWarnings( { "unchecked", "rawtypes" })
102      @Override
103      public Object load(final ClassMethodArgs from) {
104         Class clazz = from.getAsyncClass();
105         TypeLiteral typeLiteral = TypeLiteral.get(clazz);
106         RestAnnotationProcessor util = (RestAnnotationProcessor) injector.getInstance(Key.get(TypeLiteral.get(Types
107                  .newParameterizedType(RestAnnotationProcessor.class, clazz))));
108         // cannot use child injectors due to the super coarse guice lock on
109         // Singleton
110         util.setCaller(from);
111         Cache<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
112                  new TypeLiteral<Cache<ClassMethodArgs, Object>>() {
113                  }, Names.named("async")));
114         AsyncRestClientProxy proxy = new AsyncRestClientProxy(injector, factory, util, typeLiteral, delegateMap);
115         injector.injectMembers(proxy);
116         return AsyncClientFactory.create(clazz, proxy);
117      }
118   }
119 
120   private static class Factory implements AsyncRestClientProxy.Factory {
121      @Inject
122      private TransformingHttpCommandExecutorService executorService;
123 
124      @SuppressWarnings( { "unchecked", "rawtypes" })
125      @Override
126      public TransformingHttpCommand<?> create(HttpRequest request, Function<HttpResponse, ?> transformer) {
127         return new TransformingHttpCommandImpl(executorService, request, transformer);
128      }
129 
130   }
131 
132}

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