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

COVERAGE SUMMARY FOR SOURCE FILE [CreateClientForCaller.java]

nameclass, %method, %block, %line, %
CreateClientForCaller.java100% (2/2)100% (4/4)84%  (87/104)73%  (11.7/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateClientForCaller100% (1/1)100% (3/3)83%  (81/98)71%  (10.7/15)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
load (ClassMethodArgs): Object 100% (1/1)81%  (66/81)59%  (5.9/10)
CreateClientForCaller (Cache, Provider): void 100% (1/1)100% (9/9)100% (4/4)
     
class CreateClientForCaller$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
CreateClientForCaller$1 (CreateClientForCaller): 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 static com.google.common.base.Preconditions.checkState;
22 
23import java.util.Map;
24import java.util.concurrent.ExecutionException;
25 
26import javax.inject.Inject;
27import javax.inject.Named;
28import javax.inject.Provider;
29 
30import com.google.inject.Injector;
31import com.google.inject.Key;
32import com.google.inject.TypeLiteral;
33import com.google.inject.name.Names;
34import org.jclouds.concurrent.internal.SyncProxy;
35import org.jclouds.internal.ClassMethodArgs;
36 
37import com.google.common.base.Throwables;
38import com.google.common.cache.Cache;
39import com.google.common.cache.CacheLoader;
40 
41/**
42 * CreateClientForCaller is parameterized, so clients it creates aren't singletons. For example,
43 * CreateClientForCaller satisfies a call like this:
44 * {@code context.getProviderSpecificContext().getApi().getOrgClientForName(name)}
45 * 
46 * @author Adrian Cole
47 */
48public class CreateClientForCaller extends CacheLoader<ClassMethodArgs, Object> {
49   @Inject
50   Injector injector;
51   private final Cache<ClassMethodArgs, Object> asyncMap;
52   private final Provider<Cache<ClassMethodArgs, Object>> delegateMap;
53   Map<Class<?>, Class<?>> sync2Async;
54 
55   @Inject
56   CreateClientForCaller(@Named("async") Cache<ClassMethodArgs, Object> asyncMap,
57            @Named("sync") Provider<Cache<ClassMethodArgs, Object>> delegateMap) {
58      this.asyncMap = asyncMap;
59      this.delegateMap = delegateMap;
60   }
61 
62   @Override
63   public Object load(ClassMethodArgs from) throws ExecutionException {
64      Class<?> syncClass = from.getMethod().getReturnType();
65      Class<?> asyncClass = sync2Async.get(syncClass);
66      checkState(asyncClass != null, "configuration error, sync class " + syncClass + " not mapped to an async class");
67      Object asyncClient = asyncMap.get(from);
68      checkState(asyncClient != null, "configuration error, sync client for " + from + " not found");
69      try {
70         return SyncProxy.proxy(syncClass, asyncClient, delegateMap.get(), sync2Async,
71                 injector.getInstance(Key.get(new TypeLiteral<Map<String, Long>>() {
72                 }, Names.named("TIMEOUTS"))));
73      } catch (Exception e) {
74         Throwables.propagate(e);
75         assert false : "should have propagated";
76         return null;
77      }
78 
79   }
80}

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