1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.trendmicro.grid.acl.ds.cache;
18
19 import net.sf.tinyjee.cache.CacheContext;
20 import org.infinispan.manager.EmbeddedCacheManager;
21 import org.springframework.jmx.export.annotation.ManagedAttribute;
22 import org.springframework.jmx.export.annotation.ManagedResource;
23 import org.springframework.stereotype.Component;
24
25 import java.util.concurrent.atomic.AtomicLong;
26
27
28
29
30
31
32 @Component
33 @ManagedResource(objectName = ThirdLevelCacheStatisticsSummary.OBJECT_NAME, description = "" +
34 "Implements a summary on the 3rd level cache (memcached) efficiency.")
35 public class ThirdLevelCacheStatisticsSummary {
36
37 static final String JMX_NAME = "ThirdLevelCacheStatisticsSummary";
38 static final String JMX_DOMAIN = "com.trendmicro.grid.acl:";
39 static final String OBJECT_NAME = JMX_DOMAIN + "type=" + JMX_NAME + ",name=Context";
40
41 protected final AtomicLong fetchedKeyCount = new AtomicLong();
42
43
44
45
46
47
48 public AtomicLong getFetchedKeyCount() {
49 return fetchedKeyCount;
50 }
51
52
53
54
55
56
57
58
59 @ManagedAttribute(description = "The number of times that the 3rd level cache was bypassed.")
60 public long getCacheMisses() {
61 return fetchedKeyCount.get();
62 }
63
64
65
66
67
68
69 @ManagedAttribute(description = "The number of times that the 3rd level cache provided a normal result.")
70 public long getCacheHits() {
71 return collectHits("3rdLevel.Cache");
72 }
73
74
75
76
77
78
79 @ManagedAttribute(description = "The number of times that the 3rd level cache provided a result a cached 'null' result.")
80 public long getNegativeCacheHits() {
81 return collectHits("Internal.3rdLevel.Cache.Unknown");
82 }
83
84 private static long collectHits(String prefix) {
85 long hits = 0;
86 final CacheContext context = CacheContext.getInstance();
87 for (EmbeddedCacheManager cacheManager : context.getCacheManagers().values()) {
88 for (String name : cacheManager.getCacheNames()) {
89 if (name.startsWith(prefix))
90 hits += cacheManager.getCache(name).getAdvancedCache().getStats().getHits();
91 }
92 }
93 return hits;
94 }
95 }