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

COVERAGE SUMMARY FOR SOURCE FILE [ClientProvider.java]

nameclass, %method, %block, %line, %
ClientProvider.java100% (3/3)100% (5/5)82%  (68/83)72%  (10.8/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ClientProvider100% (1/1)100% (3/3)79%  (56/71)67%  (8.8/13)
get (): Object 100% (1/1)75%  (38/51)43%  (3/7)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
ClientProvider (Class, Class, Map): void 100% (1/1)100% (12/12)100% (5/5)
     
class ClientProvider$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ClientProvider$1 (ClientProvider): void 100% (1/1)100% (6/6)100% (1/1)
     
class ClientProvider$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ClientProvider$2 (ClientProvider): 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.Inject;
24import javax.inject.Singleton;
25 
26import org.jclouds.concurrent.internal.SyncProxy;
27import org.jclouds.internal.ClassMethodArgs;
28 
29import com.google.common.base.Throwables;
30import com.google.common.cache.Cache;
31import com.google.inject.Injector;
32import com.google.inject.Key;
33import com.google.inject.Provider;
34import com.google.inject.TypeLiteral;
35import com.google.inject.name.Names;
36 
37/**
38 * ClientProvider makes the primary interface for the provider context. ex. {@code
39 * context.getProviderSpecificContext().getApi()} is created by ClientProvider, which is a singleton
40 * 
41 * @author Adrian Cole
42 */
43@Singleton
44public class ClientProvider<S, A> implements Provider<S> {
45   @Inject
46   Injector injector;
47   private final Class<S> syncClientType;
48   private final Class<A> asyncClientType;
49   private final Map<Class<?>, Class<?>> sync2Async;
50 
51   @Inject
52   ClientProvider(Class<S> syncClientType, Class<A> asyncClientType, Map<Class<?>, Class<?>> sync2Async) {
53      this.asyncClientType = asyncClientType;
54      this.syncClientType = syncClientType;
55      this.sync2Async = sync2Async;
56   }
57 
58   @Override
59   @Singleton
60   public S get() {
61      A client = (A) injector.getInstance(Key.get(asyncClientType));
62      Cache<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
63               new TypeLiteral<Cache<ClassMethodArgs, Object>>() {
64               }, Names.named("sync")));
65      try {
66         return (S) SyncProxy.proxy(syncClientType, client, delegateMap, sync2Async,
67                 injector.getInstance(Key.get(new TypeLiteral<Map<String, Long>>() {
68               }, Names.named("TIMEOUTS"))));
69      } catch (Exception e) {
70         Throwables.propagate(e);
71         assert false : "should have propagated";
72         return null;
73      }
74   }
75}

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