CacheManager.java
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
*/
package com.adobe.aemds.guide.cache;
import com.adobe.aemds.guide.cache.Cache;
import com.adobe.aemds.guide.cache.api.CacheConfig;
import com.adobe.aemds.guide.cache.api.CacheStore;
import com.adobe.aemds.guide.cache.api.CacheStoreProvider;
import com.adobe.aemds.guide.service.AdaptiveFormConfigurationService;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
@Component(immediate=1, metatype=1, label="Adaptive Form Cache Manager", description="Adaptive Form Cache Manager Service")
@Service(value={CacheManager.class})
public class CacheManager {
private Map<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
private static float LOAD_FACTOR = 0.75f;
@Reference
private CacheStoreProvider provider;
@Reference
private AdaptiveFormConfigurationService configuration;
private CacheConfig existingCacheConfig;
protected void activate() {
int maximumEntries = this.configuration.maximumCacheEntries();
CacheConfig cacheConfig = new CacheConfig((int)((float)maximumEntries * LOAD_FACTOR), maximumEntries);
if (this.existingCacheConfig != null && this.existingCacheConfig.getMaximumEntries() != cacheConfig.getMaximumEntries()) {
Set<String> cacheNames = this.caches.keySet();
this.caches.clear();
for (String cacheName : cacheNames) {
this.caches.put(cacheName, this.getNewCache(this.existingCacheConfig));
}
}
this.existingCacheConfig = cacheConfig;
}
private Cache getNewCache(CacheConfig cacheConfig) {
CacheStore cacheStore = this.provider.newCacheStore(cacheConfig);
return new Cache(cacheStore);
}
public void dumpCacheInfo() {
}
public Cache getOrCreateCache(String cacheName) {
if (!this.caches.containsKey(cacheName)) {
int maximumEntries = this.configuration.maximumCacheEntries();
CacheConfig cacheConfig = new CacheConfig((int)((float)maximumEntries * LOAD_FACTOR), maximumEntries);
this.caches.put(cacheName, this.getNewCache(cacheConfig));
}
return this.caches.get(cacheName);
}
protected void bindProvider(CacheStoreProvider cacheStoreProvider) {
this.provider = cacheStoreProvider;
}
protected void unbindProvider(CacheStoreProvider cacheStoreProvider) {
if (this.provider == cacheStoreProvider) {
this.provider = null;
}
}
protected void bindConfiguration(AdaptiveFormConfigurationService adaptiveFormConfigurationService) {
this.configuration = adaptiveFormConfigurationService;
}
protected void unbindConfiguration(AdaptiveFormConfigurationService adaptiveFormConfigurationService) {
if (this.configuration == adaptiveFormConfigurationService) {
this.configuration = null;
}
}
}