EMMA Coverage Report (generated Fri Apr 27 15:03:37 EDT 2012)
[all classes][org.jclouds.ec2.compute.config]

COVERAGE SUMMARY FOR SOURCE FILE [EC2ComputeServiceContextModule.java]

nameclass, %method, %block, %line, %
EC2ComputeServiceContextModule.java60%  (3/5)60%  (9/15)53%  (83/156)61%  (15.2/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2ComputeServiceContextModule$10%   (0/1)0%   (0/1)0%   (0/6)0%   (0/1)
EC2ComputeServiceContextModule$1 (EC2ComputeServiceContextModule): void 0%   (0/1)0%   (0/6)0%   (0/1)
     
class EC2ComputeServiceContextModule$20%   (0/1)0%   (0/2)0%   (0/17)0%   (0/2)
EC2ComputeServiceContextModule$2 (EC2ComputeServiceContextModule, Supplier): ... 0%   (0/1)0%   (0/9)0%   (0/1)
get (): Set 0%   (0/1)0%   (0/8)0%   (0/1)
     
class EC2ComputeServiceContextModule$3100% (1/1)50%  (1/2)41%  (14/34)40%  (2/5)
load (RegionAndName): Image 0%   (0/1)0%   (0/20)0%   (0/3)
EC2ComputeServiceContextModule$3 (EC2ComputeServiceContextModule, RegionAndId... 100% (1/1)100% (14/14)100% (2/2)
     
class EC2ComputeServiceContextModule$3$1100% (1/1)50%  (1/2)45%  (9/20)25%  (1/4)
get (): Image 0%   (0/1)0%   (0/11)0%   (0/3)
EC2ComputeServiceContextModule$3$1 (EC2ComputeServiceContextModule$3, RegionA... 100% (1/1)100% (9/9)100% (1/1)
     
class EC2ComputeServiceContextModule100% (1/1)88%  (7/8)76%  (60/79)82%  (13.9/17)
supplyNonParsingImageCache (AtomicReference, long, Supplier, Injector): Supplier 0%   (0/1)0%   (0/15)0%   (0/2)
amiOwners (String): String [] 100% (1/1)81%  (13/16)67%  (2/3)
shouldEagerlyParseImages (Injector): boolean 100% (1/1)93%  (14/15)96%  (1.9/2)
EC2ComputeServiceContextModule (): void 100% (1/1)100% (3/3)100% (1/1)
configure (): void 100% (1/1)100% (15/15)100% (5/5)
installDependencies (): void 100% (1/1)100% (6/6)100% (2/2)
provideRegionAndNameToImageSupplierCache (RegionAndNameToImageSupplier): Supp... 100% (1/1)100% (2/2)100% (1/1)
provideRegionAndNameToImageSupplierCacheLoader (RegionAndIdToImage): Supplier 100% (1/1)100% (7/7)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.ec2.compute.config;
20 
21import static com.google.common.collect.Iterables.toArray;
22import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
23import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
24 
25import java.util.Set;
26import java.util.concurrent.ExecutionException;
27import java.util.concurrent.atomic.AtomicReference;
28 
29import javax.inject.Named;
30import javax.inject.Singleton;
31 
32import org.jclouds.compute.ComputeServiceContext;
33import org.jclouds.compute.config.BaseComputeServiceContextModule;
34import org.jclouds.compute.domain.Image;
35import org.jclouds.concurrent.RetryOnTimeOutExceptionSupplier;
36import org.jclouds.ec2.compute.EC2ComputeService;
37import org.jclouds.ec2.compute.domain.RegionAndName;
38import org.jclouds.ec2.compute.loaders.RegionAndIdToImage;
39import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier;
40import org.jclouds.rest.AuthorizationException;
41import org.jclouds.rest.suppliers.SetAndThrowAuthorizationExceptionSupplier;
42 
43import com.google.common.base.Splitter;
44import com.google.common.base.Supplier;
45import com.google.common.base.Suppliers;
46import com.google.common.base.Throwables;
47import com.google.common.cache.CacheLoader;
48import com.google.common.cache.LoadingCache;
49import com.google.common.collect.ImmutableSet;
50import com.google.inject.Injector;
51import com.google.inject.Key;
52import com.google.inject.Provides;
53import com.google.inject.TypeLiteral;
54import com.google.inject.name.Names;
55 
56/**
57 * Configures the {@link ComputeServiceContext}; requires {@link EC2ComputeService} bound.
58 * 
59 * @author Adrian Cole
60 */
61public class EC2ComputeServiceContextModule extends BaseComputeServiceContextModule {
62   @Override
63   protected void configure() {
64      installDependencies();
65      install(new EC2BindComputeStrategiesByClass());
66      install(new EC2BindComputeSuppliersByClass());
67      super.configure();
68   }
69   
70   protected void installDependencies(){
71      install(new EC2ComputeServiceDependenciesModule());
72   }
73   
74   @Override
75   protected boolean shouldEagerlyParseImages(Injector injector) {
76      // If no owners to query, then will never lookup all images
77      String[] amiOwners = injector.getInstance(Key.get(String[].class, Names.named(PROPERTY_EC2_AMI_OWNERS)));
78      return (amiOwners.length > 0);
79   }
80 
81   @Override
82   protected Supplier<Set<? extends Image>> supplyNonParsingImageCache(
83            AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
84            final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
85      final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key.get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {}));
86      return new Supplier<Set<? extends Image>>() {
87         @Override
88         public Set<? extends Image> get() {
89            return ImmutableSet.copyOf(cache.get().asMap().values());
90         }
91      };
92   }
93 
94   @Provides
95   @Singleton
96   protected Supplier<LoadingCache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
97            final RegionAndNameToImageSupplier supplier) {
98      return supplier;
99   }
100 
101   @Provides
102   @Singleton
103   protected Supplier<CacheLoader<RegionAndName, Image>> provideRegionAndNameToImageSupplierCacheLoader(
104            final RegionAndIdToImage delegate) {
105      return Suppliers.<CacheLoader<RegionAndName, Image>>ofInstance(new CacheLoader<RegionAndName, Image>() {
106         private final AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
107 
108         @Override
109         public Image load(final RegionAndName key) throws Exception {
110            // raw lookup of an image
111            Supplier<Image> rawSupplier = new Supplier<Image>() {
112               @Override public Image get() {
113                  try {
114                     return delegate.load(key);
115                  } catch (ExecutionException e) {
116                     throw Throwables.propagate(e);
117                  }
118               }
119            };
120            
121            // wrap in retry logic
122            Supplier<Image> retryingSupplier = new RetryOnTimeOutExceptionSupplier<Image>(
123                  new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException));
124            
125            return retryingSupplier.get();
126         }
127         
128      });
129   }
130 
131   @Provides
132   @Singleton
133   @Named(PROPERTY_EC2_AMI_OWNERS)
134   String[] amiOwners(@Named(PROPERTY_EC2_AMI_OWNERS) String amiOwners) {
135      if (amiOwners.trim().equals(""))
136         return new String[] {};
137      return toArray(Splitter.on(',').split(amiOwners), String.class);
138   }
139 
140}
141 

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