EMMA Coverage Report (generated Tue Apr 17 08:51:20 BST 2007)
[all classes][org.jtoolkit.essence.data]

COVERAGE SUMMARY FOR SOURCE FILE [CacheComponentBuilder.java]

nameclass, %method, %block, %line, %
CacheComponentBuilder.java100% (2/2)100% (7/7)67%  (101/150)81%  (21.9/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CacheComponentBuilder100% (1/1)100% (6/6)64%  (89/138)77%  (16.9/22)
resolveComponent (String, Class): Object 100% (1/1)18%  (10/57)29%  (2/7)
CacheComponentBuilder (String, Container): void 100% (1/1)97%  (58/60)99%  (8.9/9)
close (): void 100% (1/1)100% (16/16)100% (3/3)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
start (): void 100% (1/1)100% (1/1)100% (1/1)
stop (): void 100% (1/1)100% (1/1)100% (1/1)
     
class CacheComponentBuilder$CacheData100% (1/1)100% (1/1)100% (12/12)100% (5/5)
CacheComponentBuilder$CacheData (String, EvictionStrategy, Integer): void 100% (1/1)100% (12/12)100% (5/5)

1package org.jtoolkit.essence.data;
2 
3import org.jetbrains.annotations.NotNull;
4import org.jetbrains.annotations.Nullable;
5import org.jtoolkit.essence.app.ComponentBuilder;
6import org.jtoolkit.essence.app.Container;
7import org.jtoolkit.essence.app.Runs;
8import org.jtoolkit.essence.app.pojo.impl.DataValueClass;
9import org.jtoolkit.essence.data.impl.CacheStore;
10 
11import javax.cache.Cache;
12import java.io.Closeable;
13import java.io.IOException;
14import java.util.LinkedHashMap;
15import java.util.Map;
16import java.util.concurrent.ConcurrentMap;
17 
18public class CacheComponentBuilder implements ComponentBuilder, Runs, Closeable {
19    private final String name;
20    private final Container container;
21    private final Map<String, CacheStore> cacheDataMap = new LinkedHashMap<String, CacheStore>();
22 
23    public CacheComponentBuilder(String name, Container container) throws InstantiationException {
24        this.name = name;
25        this.container = container;
26        Integer size = DataValueClass.cast(Integer.class, container.getProperties().getValue("caches.defaultMaxSize"));
27        int defaultCacheSize = size == null ? 1000 : size;
28        for (CacheData cd : container.removeConfigAs("Caches", CacheData.class))
29            cacheDataMap.put(cd.name, new CacheStore(defaultCacheSize, cd));
30    }
31 
32    // must define a constructor which takes a Container
33    // public ComponentBuilder(Container container)
34    @Nullable
35    public <T> T resolveComponent(@NotNull String componentName, @Nullable Class<T> type) throws IllegalStateException, IllegalArgumentException {
36        if (type == Store.class || type == null)
37            return (T) cacheDataMap.get(componentName);
38        if (type == Map.class || type == ConcurrentMap.class)
39            return (T) cacheDataMap.get(componentName).getMapView();
40        if (type == Cache.class)
41            return (T) cacheDataMap.get(componentName).getCacheView();
42 
43        throw new IllegalArgumentException(container.getName() + ": " + "Attempted to get component " + componentName +
44                " as " + type + " however CacheComponentBuilder only supports Store, Map, ConcurrentMap and Cache");
45    }
46 
47    @NotNull public String getName() {
48        return name;
49    }
50 
51    public void start() throws IllegalStateException, IllegalArgumentException {
52    }
53 
54    public void stop() {
55    }
56 
57    public void close() throws IOException {
58        for (Store s : cacheDataMap.values())
59            s.close();
60    }
61 
62    public static class CacheData {
63        public final String name;
64        public final EvictionStrategy evictionStrategy;
65        public final Integer cacheSize;
66 
67        CacheData(@NotNull String name, @NotNull EvictionStrategy evictionStrategy, Integer cacheSize) {
68            this.name = name;
69            this.evictionStrategy = evictionStrategy;
70            this.cacheSize = cacheSize;
71        }
72    }
73}

[all classes][org.jtoolkit.essence.data]
EMMA 2.0.5312 (C) Vladimir Roubtsov