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

COVERAGE SUMMARY FOR SOURCE FILE [OpenStackAuthenticationModule.java]

nameclass, %method, %block, %line, %
OpenStackAuthenticationModule.java0%   (0/4)0%   (0/14)0%   (0/108)0%   (0/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OpenStackAuthenticationModule0%   (0/1)0%   (0/6)0%   (0/30)0%   (0/7)
OpenStackAuthenticationModule (): void 0%   (0/1)0%   (0/3)0%   (0/2)
configure (): void 0%   (0/1)0%   (0/1)0%   (0/1)
provideAuthenticationResponse (Supplier): OpenStackAuthAsyncClient$Authentica... 0%   (0/1)0%   (0/4)0%   (0/1)
provideAuthenticationResponseCache (OpenStackAuthenticationModule$GetAuthenti... 0%   (0/1)0%   (0/8)0%   (0/1)
provideAuthenticationTokenCache (Supplier): Supplier 0%   (0/1)0%   (0/6)0%   (0/1)
provideCacheBusterDate (): Supplier 0%   (0/1)0%   (0/8)0%   (0/1)
     
class OpenStackAuthenticationModule$10%   (0/1)0%   (0/2)0%   (0/15)0%   (0/2)
OpenStackAuthenticationModule$1 (OpenStackAuthenticationModule, Supplier): void 0%   (0/1)0%   (0/9)0%   (0/1)
get (): String 0%   (0/1)0%   (0/6)0%   (0/1)
     
class OpenStackAuthenticationModule$20%   (0/1)0%   (0/2)0%   (0/10)0%   (0/2)
OpenStackAuthenticationModule$2 (OpenStackAuthenticationModule): void 0%   (0/1)0%   (0/6)0%   (0/1)
get (): Date 0%   (0/1)0%   (0/4)0%   (0/1)
     
class OpenStackAuthenticationModule$GetAuthenticationResponse0%   (0/1)0%   (0/4)0%   (0/53)0%   (0/13)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
OpenStackAuthenticationModule$GetAuthenticationResponse (AsyncClientFactory, ... 0%   (0/1)0%   (0/15)0%   (0/5)
authenticate (): Future 0%   (0/1)0%   (0/8)0%   (0/1)
get (): OpenStackAuthAsyncClient$AuthenticationResponse 0%   (0/1)0%   (0/22)0%   (0/6)

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.openstack.config;
20 
21import java.util.Date;
22import java.util.concurrent.ExecutionException;
23import java.util.concurrent.Future;
24import java.util.concurrent.TimeUnit;
25import java.util.concurrent.TimeoutException;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.Constants;
32import org.jclouds.concurrent.RetryOnTimeOutExceptionSupplier;
33import org.jclouds.date.TimeStamp;
34import org.jclouds.http.RequiresHttp;
35import org.jclouds.openstack.Authentication;
36import org.jclouds.openstack.OpenStackAuthAsyncClient;
37import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
38import org.jclouds.rest.AsyncClientFactory;
39 
40import com.google.common.base.Supplier;
41import com.google.common.base.Suppliers;
42import com.google.common.base.Throwables;
43import com.google.inject.AbstractModule;
44import com.google.inject.Provides;
45 
46/**
47 * Configures the Rackspace authentication service connection, including logging and http transport.
48 * 
49 * @author Adrian Cole
50 */
51@RequiresHttp
52public class OpenStackAuthenticationModule extends AbstractModule {
53 
54   @Override
55   protected void configure() {
56   }
57 
58   /**
59    * borrowing concurrency code to ensure that caching takes place properly
60    */
61   @Provides
62   @Singleton
63   @Authentication
64   protected Supplier<String> provideAuthenticationTokenCache(final Supplier<AuthenticationResponse> supplier)
65            throws InterruptedException, ExecutionException, TimeoutException {
66      return new Supplier<String>() {
67         public String get() {
68            return supplier.get().getAuthToken();
69         }
70      };
71   }
72 
73   @Singleton
74   public static class GetAuthenticationResponse implements Supplier<AuthenticationResponse> {
75      protected final OpenStackAuthAsyncClient client;
76      protected final String user;
77      protected final String key;
78 
79      @Inject
80      public GetAuthenticationResponse(AsyncClientFactory factory, @Named(Constants.PROPERTY_IDENTITY) String user,
81               @Named(Constants.PROPERTY_CREDENTIAL) String key) {
82         this.client = factory.create(OpenStackAuthAsyncClient.class);
83         this.user = user;
84         this.key = key;
85      }
86 
87      @Override
88      public AuthenticationResponse get() {
89         try {
90            Future<AuthenticationResponse> response = authenticate();
91            return response.get(30, TimeUnit.SECONDS);
92         } catch (Exception e) {
93            Throwables.propagate(e);
94            assert false : e;
95            return null;
96         }
97      }
98 
99      protected Future<AuthenticationResponse> authenticate() {
100         return client.authenticate(user, key);
101      }
102 
103   }
104 
105   @Provides
106   @Singleton
107   Supplier<AuthenticationResponse> provideAuthenticationResponseCache(
108            final GetAuthenticationResponse getAuthenticationResponse) {
109      return Suppliers.memoizeWithExpiration(new RetryOnTimeOutExceptionSupplier<AuthenticationResponse>(
110               getAuthenticationResponse), 23, TimeUnit.HOURS);
111   }
112 
113   @Provides
114   @Singleton
115   @TimeStamp
116   protected Supplier<Date> provideCacheBusterDate() {
117      return Suppliers.memoizeWithExpiration(new Supplier<Date>() {
118         public Date get() {
119            return new Date();
120         }
121      }, 1, TimeUnit.SECONDS);
122   }
123 
124   @Provides
125   @Singleton
126   protected AuthenticationResponse provideAuthenticationResponse(Supplier<AuthenticationResponse> supplier)
127            throws InterruptedException, ExecutionException, TimeoutException {
128      return supplier.get();
129   }
130 
131}

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