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

COVERAGE SUMMARY FOR SOURCE FILE [GoGridRestClientModule.java]

nameclass, %method, %block, %line, %
GoGridRestClientModule.java100% (2/2)75%  (6/8)89%  (72/81)85%  (11/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class GoGridRestClientModule$1100% (1/1)50%  (1/2)55%  (6/11)50%  (1/2)
get (): Long 0%   (0/1)0%   (0/5)0%   (0/1)
GoGridRestClientModule$1 (GoGridRestClientModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class GoGridRestClientModule100% (1/1)83%  (5/6)94%  (66/70)92%  (11/12)
provideTimeStamp (Supplier): Long 0%   (0/1)0%   (0/4)0%   (0/1)
<static initializer> 100% (1/1)100% (19/19)100% (1/1)
GoGridRestClientModule (): void 100% (1/1)100% (6/6)100% (2/2)
bindErrorHandlers (): void 100% (1/1)100% (25/25)100% (4/4)
configure (): void 100% (1/1)100% (8/8)100% (3/3)
provideTimeStampCache (long): Supplier 100% (1/1)100% (8/8)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.gogrid.config;
20 
21import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
22 
23import java.util.Map;
24import java.util.concurrent.TimeUnit;
25 
26import javax.inject.Named;
27 
28import org.jclouds.date.TimeStamp;
29import org.jclouds.gogrid.GoGridAsyncClient;
30import org.jclouds.gogrid.GoGridClient;
31import org.jclouds.gogrid.handlers.GoGridErrorHandler;
32import org.jclouds.gogrid.services.GridImageAsyncClient;
33import org.jclouds.gogrid.services.GridImageClient;
34import org.jclouds.gogrid.services.GridIpAsyncClient;
35import org.jclouds.gogrid.services.GridIpClient;
36import org.jclouds.gogrid.services.GridJobAsyncClient;
37import org.jclouds.gogrid.services.GridJobClient;
38import org.jclouds.gogrid.services.GridLoadBalancerAsyncClient;
39import org.jclouds.gogrid.services.GridLoadBalancerClient;
40import org.jclouds.gogrid.services.GridServerAsyncClient;
41import org.jclouds.gogrid.services.GridServerClient;
42import org.jclouds.http.HttpErrorHandler;
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.ConfiguresRestClient;
48import org.jclouds.rest.config.RestClientModule;
49 
50import com.google.common.base.Supplier;
51import com.google.common.base.Suppliers;
52import com.google.common.collect.ImmutableMap;
53import com.google.inject.Provides;
54 
55/**
56 * Configures the GoGrid connection.
57 * 
58 * @author Adrian Cole
59 * @author Oleksiy Yarmula
60 */
61@RequiresHttp
62@ConfiguresRestClient
63public class GoGridRestClientModule extends RestClientModule<GoGridClient, GoGridAsyncClient> {
64   public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
65         .put(GridServerClient.class, GridServerAsyncClient.class)//
66         .put(GridJobClient.class, GridJobAsyncClient.class)//
67         .put(GridIpClient.class, GridIpAsyncClient.class)//
68         .put(GridLoadBalancerClient.class, GridLoadBalancerAsyncClient.class)//
69         .put(GridImageClient.class, GridImageAsyncClient.class)//
70         .build();
71 
72   public GoGridRestClientModule() {
73      super(GoGridClient.class, GoGridAsyncClient.class, DELEGATE_MAP);
74   }
75 
76   @Provides
77   @TimeStamp
78   protected Long provideTimeStamp(@TimeStamp Supplier<Long> cache) {
79      return cache.get();
80   }
81 
82   /**
83    * borrowing concurrency code to ensure that caching takes place properly
84    */
85   @Provides
86   @TimeStamp
87   Supplier<Long> provideTimeStampCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds) {
88      return Suppliers.memoizeWithExpiration(new Supplier<Long>() {
89         public Long get() {
90            return System.currentTimeMillis() / 1000;
91         }
92      }, seconds, TimeUnit.SECONDS);
93   }
94 
95   @Override
96   protected void bindErrorHandlers() {
97      bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(GoGridErrorHandler.class);
98      bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(GoGridErrorHandler.class);
99      bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(GoGridErrorHandler.class);
100   }
101 
102   @Override
103   protected void configure() {
104      install(new GoGridParserModule());
105      super.configure();
106   }
107 
108}

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