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

COVERAGE SUMMARY FOR SOURCE FILE [YamlNodeStoreModule.java]

nameclass, %method, %block, %line, %
YamlNodeStoreModule.java100% (12/12)100% (17/17)100% (191/191)100% (22/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class YamlNodeStoreModule100% (1/1)100% (6/6)100% (126/126)100% (19/19)
<static initializer> 100% (1/1)100% (5/5)100% (1/1)
YamlNodeStoreModule (): void 100% (1/1)100% (4/4)100% (2/2)
YamlNodeStoreModule (Map): void 100% (1/1)100% (6/6)100% (3/3)
configure (): void 100% (1/1)100% (93/93)100% (11/11)
provideNodeStore (Map, Function, Function): Cache 100% (1/1)100% (11/11)100% (1/1)
provideYamlStore (Map, Function, Function): Map 100% (1/1)100% (7/7)100% (1/1)
     
class YamlNodeStoreModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$1 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$10100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$10 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$2 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$3100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$3 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$4100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$4 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$5100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$5 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$6100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$6 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$7100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$7 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$8100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$8 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$9100% (1/1)100% (1/1)100% (6/6)100% (1/1)
YamlNodeStoreModule$9 (YamlNodeStoreModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class YamlNodeStoreModule$YAMLCopyInputStreamInputSupplierMap100% (1/1)100% (1/1)100% (5/5)100% (2/2)
YamlNodeStoreModule$YAMLCopyInputStreamInputSupplierMap (Map, CopyInputStream... 100% (1/1)100% (5/5)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.byon.config;
20 
21import java.io.InputStream;
22import java.util.Map;
23import java.util.concurrent.ConcurrentHashMap;
24 
25import javax.inject.Inject;
26import javax.inject.Named;
27import javax.inject.Singleton;
28 
29import org.jclouds.byon.Node;
30import org.jclouds.byon.domain.YamlNode;
31import org.jclouds.byon.functions.NodesFromYamlStream;
32import org.jclouds.byon.suppliers.NodesParsedFromSupplier;
33import org.jclouds.collect.TransformingMap;
34import org.jclouds.io.CopyInputStreamInputSupplierMap;
35import org.jclouds.io.CopyInputStreamIntoSupplier;
36 
37import com.google.common.annotations.Beta;
38import com.google.common.base.Function;
39import com.google.common.base.Functions;
40import com.google.common.base.Supplier;
41import com.google.common.cache.Cache;
42import com.google.common.cache.CacheBuilder;
43import com.google.common.cache.CacheLoader;
44import com.google.common.io.InputSupplier;
45import com.google.inject.AbstractModule;
46import com.google.inject.Provides;
47import com.google.inject.TypeLiteral;
48import com.google.inject.name.Names;
49 
50/**
51 * 
52 * @author Adrian Cole
53 */
54@ConfiguresNodeStore
55@Beta
56public class YamlNodeStoreModule extends AbstractModule {
57   private static final Map<String, InputSupplier<InputStream>> BACKING = new ConcurrentHashMap<String, InputSupplier<InputStream>>();
58   private final Map<String, InputStream> backing;
59 
60   public YamlNodeStoreModule(Map<String, InputStream> backing) {
61      this.backing = backing;
62   }
63 
64   public YamlNodeStoreModule() {
65      this(null);
66   }
67 
68   @Override
69   protected void configure() {
70      bind(new TypeLiteral<Supplier<Cache<String, Node>>>() {
71      }).to(NodesParsedFromSupplier.class);
72      bind(new TypeLiteral<Function<InputStream, Cache<String, Node>>>() {
73      }).to(NodesFromYamlStream.class);
74      bind(new TypeLiteral<Function<YamlNode, InputStream>>() {
75      }).toInstance(org.jclouds.byon.domain.YamlNode.yamlNodeToInputStream);
76      bind(new TypeLiteral<Function<InputStream, YamlNode>>() {
77      }).toInstance(org.jclouds.byon.domain.YamlNode.inputStreamToYamlNode);
78      bind(new TypeLiteral<Function<Node, YamlNode>>() {
79      }).toInstance(org.jclouds.byon.domain.YamlNode.nodeToYamlNode);
80      bind(new TypeLiteral<Function<YamlNode, Node>>() {
81      }).toInstance(org.jclouds.byon.domain.YamlNode.toNode);
82      if (backing != null) {
83         bind(new TypeLiteral<Map<String, InputStream>>() {
84         }).annotatedWith(Names.named("yaml")).toInstance(backing);
85      } else {
86         bind(new TypeLiteral<Map<String, InputSupplier<InputStream>>>() {
87         }).annotatedWith(Names.named("yaml")).toInstance(BACKING);
88         bind(new TypeLiteral<Map<String, InputStream>>() {
89         }).annotatedWith(Names.named("yaml")).to(new TypeLiteral<YAMLCopyInputStreamInputSupplierMap>() {
90         });
91      }
92 
93   }
94 
95   @Singleton
96   public static class YAMLCopyInputStreamInputSupplierMap extends CopyInputStreamInputSupplierMap {
97      @Inject
98      public YAMLCopyInputStreamInputSupplierMap(@Named("yaml") Map<String, InputSupplier<InputStream>> toMap,
99            CopyInputStreamIntoSupplier putFunction) {
100         super(toMap, putFunction);
101      }
102   }
103 
104   @Provides
105   @Singleton
106   protected Cache<String, Node> provideNodeStore(Map<String, YamlNode> backing, Function<Node, YamlNode> yamlSerializer,
107         Function<YamlNode, Node> yamlDeserializer) {
108      return CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(new TransformingMap<String, YamlNode, Node>(backing, yamlDeserializer, yamlSerializer))));
109   }
110 
111   @Provides
112   @Singleton
113   protected Map<String, YamlNode> provideYamlStore(@Named("yaml") Map<String, InputStream> backing,
114         Function<YamlNode, InputStream> yamlSerializer, Function<InputStream, YamlNode> yamlDeserializer) {
115      return new TransformingMap<String, InputStream, YamlNode>(backing, yamlDeserializer, yamlSerializer);
116   }
117}

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