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 |
|
package info.magnolia.module.cache.mbean; |
35 |
|
|
36 |
|
import info.magnolia.cms.util.MBeanUtil; |
37 |
|
import info.magnolia.commands.CommandsManager; |
38 |
|
import info.magnolia.commands.chain.Command; |
39 |
|
import info.magnolia.context.Context; |
40 |
|
import info.magnolia.context.SimpleContext; |
41 |
|
import info.magnolia.context.SystemContext; |
42 |
|
import info.magnolia.module.cache.Cache; |
43 |
|
import info.magnolia.module.cache.CacheFactory; |
44 |
|
import info.magnolia.module.cache.CacheModule; |
45 |
|
import info.magnolia.module.cache.cachekey.DefaultCacheKey; |
46 |
|
import info.magnolia.module.cache.cachepolicy.Default; |
47 |
|
import info.magnolia.module.cache.inject.CacheFactoryProvider; |
48 |
|
import info.magnolia.objectfactory.Components; |
49 |
|
|
50 |
|
import java.util.HashMap; |
51 |
|
import java.util.Map; |
52 |
|
|
53 |
|
import javax.inject.Inject; |
54 |
|
import javax.inject.Provider; |
55 |
|
import javax.inject.Singleton; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@Singleton |
|
|
| 31.3% |
Uncovered Elements: 46 (67) |
Complexity: 20 |
Complexity Density: 0.49 |
|
61 |
|
public class CacheMonitor implements CacheMonitorMBean { |
62 |
|
|
63 |
|
private final CommandsManager commandsManager; |
64 |
|
private final CacheFactoryProvider cacheFactoryProvider; |
65 |
|
private final SystemContext systemContext; |
66 |
|
|
67 |
|
private int start; |
68 |
|
private int stop; |
69 |
|
private Map<String, Integer> calls = new HashMap<String, Integer>(); |
70 |
|
private Map<String, Integer> caches = new HashMap<String, Integer>(); |
71 |
|
private Map<String, Integer> domains = new HashMap<String, Integer>(); |
72 |
|
|
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
74 |
39 |
@Inject... |
75 |
|
public CacheMonitor(CommandsManager commandsManager, CacheFactoryProvider cacheFactoryProvider, SystemContext systemContext) { |
76 |
39 |
MBeanUtil.registerMBean("CacheMonitor", this); |
77 |
39 |
this.commandsManager = commandsManager; |
78 |
39 |
this.cacheFactoryProvider = cacheFactoryProvider; |
79 |
39 |
this.systemContext = systemContext; |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
@deprecated@link |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
85 |
0 |
@Deprecated... |
86 |
|
public CacheMonitor(CommandsManager commandsManager, Provider<CacheModule> cacheModuleProvider, SystemContext systemContext) { |
87 |
0 |
MBeanUtil.registerMBean("CacheMonitor", this); |
88 |
0 |
this.commandsManager = commandsManager; |
89 |
0 |
this.systemContext = systemContext; |
90 |
0 |
this.cacheFactoryProvider = Components.getComponent(CacheFactoryProvider.class); |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
93 |
0 |
private Command getCommand(String commandName) {... |
94 |
0 |
Command flush = commandsManager.getCommand("cache", commandName); |
95 |
0 |
if (flush == null) { |
96 |
|
|
97 |
0 |
commandsManager.reload(); |
98 |
0 |
flush = commandsManager.getCommand("cache", commandName); |
99 |
|
} |
100 |
0 |
if (flush == null) { |
101 |
0 |
throw new RuntimeException("Failed to invoke cache " + commandName + " command"); |
102 |
|
} |
103 |
0 |
return flush; |
104 |
|
} |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
0 |
public void countStart() {... |
107 |
0 |
start++; |
108 |
|
} |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
0 |
public void stop() {... |
111 |
0 |
stop++; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
117 |
17 |
public void logBehavior(String name) {... |
118 |
17 |
Integer count = calls.get(name); |
119 |
17 |
calls.put(name, count == null ? 1 : ++count); |
120 |
|
} |
121 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
122 |
1 |
public void countFlush(String name) {... |
123 |
1 |
caches.put(name, caches.get(name) == null ? 1 : caches.get(name) + 1); |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0 |
public void addCache(String name) {... |
127 |
0 |
caches.put(name, 0); |
128 |
|
} |
129 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
130 |
17 |
public void logAccess(Object cacheKey) {... |
131 |
17 |
if (cacheKey == null || !(cacheKey instanceof DefaultCacheKey)) { |
132 |
16 |
return; |
133 |
|
} |
134 |
1 |
DefaultCacheKey key = (DefaultCacheKey) cacheKey; |
135 |
1 |
Integer count = this.domains.get(key.getDomain()); |
136 |
1 |
this.domains.put(key.getDomain(), count == null ? 1 : ++count); |
137 |
|
} |
138 |
|
|
139 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
140 |
0 |
@Override... |
141 |
|
public void flushAll() throws Exception { |
142 |
0 |
Command flush = getCommand("flushAll"); |
143 |
0 |
flush.execute(systemContext); |
144 |
|
} |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
146 |
0 |
@Override... |
147 |
|
public void flushByUUID(String repository, String uuid) throws Exception { |
148 |
0 |
Command flush = getCommand("flushByUUID"); |
149 |
0 |
Context ctx = new SimpleContext(systemContext); |
150 |
0 |
ctx.put("repository", repository); |
151 |
0 |
ctx.put("uuid", uuid); |
152 |
0 |
flush.execute(ctx); |
153 |
|
} |
154 |
|
|
155 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
156 |
|
@Override... |
157 |
|
public Map<String, Integer> getAll() { |
158 |
|
return calls; |
159 |
|
} |
160 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
161 |
|
@Override... |
162 |
|
public int getHits() { |
163 |
|
return calls.get("useCache"); |
164 |
|
} |
165 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
166 |
|
@Override... |
167 |
|
public int getBypasses() { |
168 |
|
return calls.get("bypass"); |
169 |
|
} |
170 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
171 |
|
@Override... |
172 |
|
public int getPuts() { |
173 |
|
return calls.get("store"); |
174 |
|
} |
175 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
176 |
|
@Override... |
177 |
|
public int getStopCalls() { |
178 |
|
return stop; |
179 |
|
} |
180 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
181 |
|
@Override... |
182 |
|
public int getStartCalls() { |
183 |
|
return start; |
184 |
|
} |
185 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
186 |
|
@Override... |
187 |
|
public Map<String, Integer> getFlushes() { |
188 |
|
return caches; |
189 |
|
} |
190 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
191 |
|
@Override... |
192 |
|
public Map<String, Integer> getDomainAccesses() { |
193 |
|
return domains; |
194 |
|
} |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
196 |
0 |
@Override... |
197 |
|
public int getCachedKeysCount() { |
198 |
0 |
int count = 0; |
199 |
|
|
200 |
0 |
CacheFactory factory = cacheFactoryProvider.get(); |
201 |
0 |
for (String name : caches.keySet()) { |
202 |
|
|
203 |
0 |
if (Default.UUID_KEY_MAP_KEY.equals(name)) { |
204 |
0 |
continue; |
205 |
|
} |
206 |
0 |
Cache cache = factory.getCache(name); |
207 |
0 |
count += cache.getSize(); |
208 |
|
} |
209 |
0 |
return count; |
210 |
|
} |
211 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
212 |
|
@Override... |
213 |
|
public int getCachedUUIDsCount() { |
214 |
|
CacheFactory factory = cacheFactoryProvider.get(); |
215 |
|
Cache cache = factory.getCache(Default.UUID_KEY_MAP_KEY); |
216 |
|
return cache.getSize(); |
217 |
|
} |
218 |
|
} |