EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.deltacloud.config]

COVERAGE SUMMARY FOR SOURCE FILE [DeltacloudRestClientModule.java]

nameclass, %method, %block, %line, %
DeltacloudRestClientModule.java33%  (1/3)21%  (3/14)31%  (44/141)43%  (9/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DeltacloudRestClientModule$10%   (0/1)0%   (0/2)0%   (0/13)0%   (0/2)
DeltacloudRestClientModule$1 (DeltacloudRestClientModule, DeltacloudClient): ... 0%   (0/1)0%   (0/9)0%   (0/1)
get (): Set 0%   (0/1)0%   (0/4)0%   (0/1)
     
class DeltacloudRestClientModule$20%   (0/1)0%   (0/2)0%   (0/12)0%   (0/2)
DeltacloudRestClientModule$2 (String): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (DeltacloudCollection): boolean 0%   (0/1)0%   (0/6)0%   (0/1)
     
class DeltacloudRestClientModule100% (1/1)30%  (3/10)38%  (44/116)50%  (9/18)
findCollectionWithRel (Iterable, String): DeltacloudCollection 0%   (0/1)0%   (0/25)0%   (0/3)
provideCollections (long, DeltacloudClient): Supplier 0%   (0/1)0%   (0/12)0%   (0/1)
provideHardwareProfileCollection (Supplier): URI 0%   (0/1)0%   (0/7)0%   (0/1)
provideImageCollection (Supplier): URI 0%   (0/1)0%   (0/7)0%   (0/1)
provideInstanceCollection (Supplier): URI 0%   (0/1)0%   (0/7)0%   (0/1)
provideInstanceStateCollection (Supplier): URI 0%   (0/1)0%   (0/7)0%   (0/1)
provideRealmCollection (Supplier): URI 0%   (0/1)0%   (0/7)0%   (0/1)
DeltacloudRestClientModule (): void 100% (1/1)100% (10/10)100% (3/3)
bindErrorHandlers (): void 100% (1/1)100% (25/25)100% (4/4)
bindRetryHandlers (): void 100% (1/1)100% (9/9)100% (2/2)

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.deltacloud.config;
20 
21import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
22 
23import java.net.URI;
24import java.util.NoSuchElementException;
25import java.util.Set;
26import java.util.concurrent.atomic.AtomicReference;
27 
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.deltacloud.DeltacloudAsyncClient;
32import org.jclouds.deltacloud.DeltacloudClient;
33import org.jclouds.deltacloud.collections.HardwareProfiles;
34import org.jclouds.deltacloud.collections.Images;
35import org.jclouds.deltacloud.collections.InstanceStates;
36import org.jclouds.deltacloud.collections.Instances;
37import org.jclouds.deltacloud.collections.Realms;
38import org.jclouds.deltacloud.domain.DeltacloudCollection;
39import org.jclouds.deltacloud.handlers.DeltacloudErrorHandler;
40import org.jclouds.deltacloud.handlers.DeltacloudRedirectionRetryHandler;
41import org.jclouds.http.HttpErrorHandler;
42import org.jclouds.http.HttpRetryHandler;
43import org.jclouds.http.RequiresHttp;
44import org.jclouds.http.annotation.ClientError;
45import org.jclouds.http.annotation.Redirection;
46import org.jclouds.http.annotation.ServerError;
47import org.jclouds.rest.AuthorizationException;
48import org.jclouds.rest.ConfiguresRestClient;
49import org.jclouds.rest.config.RestClientModule;
50import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
51 
52import com.google.common.base.Predicate;
53import com.google.common.base.Supplier;
54import com.google.common.collect.Iterables;
55import com.google.inject.Provides;
56 
57/**
58 * Configures the deltacloud connection.
59 * 
60 * @author Adrian Cole
61 */
62@RequiresHttp
63@ConfiguresRestClient
64public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClient, DeltacloudAsyncClient> {
65 
66   public DeltacloudRestClientModule() {
67      super(DeltacloudClient.class, DeltacloudAsyncClient.class);
68   }
69 
70   @Override
71   protected void bindErrorHandlers() {
72      bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(DeltacloudErrorHandler.class);
73      bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(DeltacloudErrorHandler.class);
74      bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(DeltacloudErrorHandler.class);
75   }
76 
77   @Override
78   protected void bindRetryHandlers() {
79      bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(DeltacloudRedirectionRetryHandler.class);
80   }
81 
82   protected AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
83 
84   @Provides
85   @Singleton
86   protected Supplier<Set<? extends DeltacloudCollection>> provideCollections(
87         @Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) {
88      return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends DeltacloudCollection>>(
89            authException, seconds, new Supplier<Set<? extends DeltacloudCollection>>() {
90               @Override
91               public Set<? extends DeltacloudCollection> get() {
92                  return client.getCollections();
93               }
94            });
95   }
96 
97   /**
98    * since the supplier is memoized, and there are no objects created here, this doesn't need to be
99    * singleton.
100    */
101   @Provides
102   @Images
103   protected URI provideImageCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
104      return findCollectionWithRel(collectionSupplier.get(), "images").getHref();
105   }
106 
107   public static DeltacloudCollection findCollectionWithRel(Iterable<? extends DeltacloudCollection> iterable,
108         final String rel) {
109      try {
110         return Iterables.find(iterable, new Predicate<DeltacloudCollection>() {
111 
112            @Override
113            public boolean apply(DeltacloudCollection arg0) {
114               return arg0.getRel().equals(rel);
115            }
116 
117         });
118      } catch (NoSuchElementException e) {
119         throw new NoSuchElementException("could not find rel " + rel + " in collections " + iterable);
120      }
121   }
122 
123   @Provides
124   @HardwareProfiles
125   protected URI provideHardwareProfileCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
126      return findCollectionWithRel(collectionSupplier.get(), "hardware_profiles").getHref();
127   }
128 
129   @Provides
130   @Instances
131   protected URI provideInstanceCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
132      return findCollectionWithRel(collectionSupplier.get(), "instances").getHref();
133   }
134 
135   @Provides
136   @Realms
137   protected URI provideRealmCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
138      return findCollectionWithRel(collectionSupplier.get(), "realms").getHref();
139   }
140 
141   @Provides
142   @InstanceStates
143   protected URI provideInstanceStateCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
144      return findCollectionWithRel(collectionSupplier.get(), "instance_states").getHref();
145   }
146}

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