62 * The class is used for implementing the "JvmMemMgrPoolRelTable" group. |
62 * The class is used for implementing the "JvmMemMgrPoolRelTable" group. |
63 */ |
63 */ |
64 public class JvmMemMgrPoolRelTableMetaImpl extends JvmMemMgrPoolRelTableMeta |
64 public class JvmMemMgrPoolRelTableMetaImpl extends JvmMemMgrPoolRelTableMeta |
65 implements Serializable { |
65 implements Serializable { |
66 |
66 |
|
67 static final long serialVersionUID = 1896509775012355443L; |
|
68 |
67 /** |
69 /** |
68 * A concrete implementation of {@link SnmpTableCache}, for the |
70 * A concrete implementation of {@link SnmpTableCache}, for the |
69 * jvmMemMgrPoolRelTable. |
71 * jvmMemMgrPoolRelTable. |
70 **/ |
72 **/ |
|
73 |
71 private static class JvmMemMgrPoolRelTableCache |
74 private static class JvmMemMgrPoolRelTableCache |
72 extends SnmpTableCache { |
75 extends SnmpTableCache { |
73 |
76 |
|
77 static final long serialVersionUID = 6059937161990659184L; |
74 final private JvmMemMgrPoolRelTableMetaImpl meta; |
78 final private JvmMemMgrPoolRelTableMetaImpl meta; |
75 |
79 |
76 /** |
80 /** |
77 * Create a weak cache for the jvmMemMgrPoolRelTable. |
81 * Create a weak cache for the jvmMemMgrPoolRelTable. |
78 * @param validity validity of the cached data, in ms. |
82 * @param validity validity of the cached data, in ms. |
85 |
89 |
86 /** |
90 /** |
87 * Call <code>getTableDatas(JvmContextFactory.getUserData())</code>. |
91 * Call <code>getTableDatas(JvmContextFactory.getUserData())</code>. |
88 **/ |
92 **/ |
89 public SnmpTableHandler getTableHandler() { |
93 public SnmpTableHandler getTableHandler() { |
90 final Map userData = JvmContextFactory.getUserData(); |
94 final Map<Object,Object> userData = JvmContextFactory.getUserData(); |
91 return getTableDatas(userData); |
95 return getTableDatas(userData); |
92 } |
96 } |
93 |
97 |
94 /** |
98 /** |
95 * Builds a map pool-name => pool-index from the SnmpTableHandler |
99 * Builds a map pool-name => pool-index from the SnmpTableHandler |
99 // optimization... |
103 // optimization... |
100 if (handler instanceof SnmpCachedData) |
104 if (handler instanceof SnmpCachedData) |
101 return buildPoolIndexMap((SnmpCachedData)handler); |
105 return buildPoolIndexMap((SnmpCachedData)handler); |
102 |
106 |
103 // not optimizable... too bad. |
107 // not optimizable... too bad. |
104 final Map<String, SnmpOid> m = new HashMap<String, SnmpOid>(); |
108 final Map<String, SnmpOid> m = new HashMap<>(); |
105 SnmpOid index=null; |
109 SnmpOid index=null; |
106 while ((index = handler.getNext(index))!=null) { |
110 while ((index = handler.getNext(index))!=null) { |
107 final MemoryPoolMXBean mpm = |
111 final MemoryPoolMXBean mpm = |
108 (MemoryPoolMXBean)handler.getData(index); |
112 (MemoryPoolMXBean)handler.getData(index); |
109 if (mpm == null) continue; |
113 if (mpm == null) continue; |
122 private static Map<String, SnmpOid> buildPoolIndexMap(SnmpCachedData cached) { |
126 private static Map<String, SnmpOid> buildPoolIndexMap(SnmpCachedData cached) { |
123 if (cached == null) return Collections.emptyMap(); |
127 if (cached == null) return Collections.emptyMap(); |
124 final SnmpOid[] indexes = cached.indexes; |
128 final SnmpOid[] indexes = cached.indexes; |
125 final Object[] datas = cached.datas; |
129 final Object[] datas = cached.datas; |
126 final int len = indexes.length; |
130 final int len = indexes.length; |
127 final Map<String, SnmpOid> m = new HashMap<String, SnmpOid>(len); |
131 final Map<String, SnmpOid> m = new HashMap<>(len); |
128 for (int i=0; i<len; i++) { |
132 for (int i=0; i<len; i++) { |
129 final SnmpOid index = indexes[i]; |
133 final SnmpOid index = indexes[i]; |
130 if (index == null) continue; |
134 if (index == null) continue; |
131 final MemoryPoolMXBean mpm = |
135 final MemoryPoolMXBean mpm = |
132 (MemoryPoolMXBean)datas[i]; |
136 (MemoryPoolMXBean)datas[i]; |
163 |
167 |
164 // Time stamp for the cache |
168 // Time stamp for the cache |
165 final long time = System.currentTimeMillis(); |
169 final long time = System.currentTimeMillis(); |
166 |
170 |
167 // Build a Map poolname -> index |
171 // Build a Map poolname -> index |
168 final Map poolIndexMap = buildPoolIndexMap(mpHandler); |
172 final Map<String,SnmpOid> poolIndexMap = buildPoolIndexMap(mpHandler); |
169 |
173 |
170 // For each memory manager, get the list of memory pools |
174 // For each memory manager, get the list of memory pools |
171 // For each memory pool, find its index in the memory pool table |
175 // For each memory pool, find its index in the memory pool table |
172 // Create a row in the relation table. |
176 // Create a row in the relation table. |
173 final TreeMap<SnmpOid, Object> table = |
177 final TreeMap<SnmpOid, Object> table = |
174 new TreeMap<SnmpOid, Object>(SnmpCachedData.oidComparator); |
178 new TreeMap<>(SnmpCachedData.oidComparator); |
175 updateTreeMap(table,userData,mmHandler,mpHandler,poolIndexMap); |
179 updateTreeMap(table,userData,mmHandler,mpHandler,poolIndexMap); |
176 |
180 |
177 return new SnmpCachedData(time,table); |
181 return new SnmpCachedData(time,table); |
178 } |
182 } |
179 |
183 |
205 } |
209 } |
206 |
210 |
207 protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, |
211 protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, |
208 MemoryManagerMXBean mmm, |
212 MemoryManagerMXBean mmm, |
209 SnmpOid mmIndex, |
213 SnmpOid mmIndex, |
210 Map poolIndexMap) { |
214 Map<String, SnmpOid> poolIndexMap) { |
211 |
215 |
212 // The MemoryManager index is an int, so it's the first |
216 // The MemoryManager index is an int, so it's the first |
213 // and only subidentifier. |
217 // and only subidentifier. |
214 final long mmarc; |
218 final long mmarc; |
215 try { |
219 try { |
228 |
232 |
229 final String mmmName = mmm.getName(); |
233 final String mmmName = mmm.getName(); |
230 for (int i = 0; i < mpList.length; i++) { |
234 for (int i = 0; i < mpList.length; i++) { |
231 final String mpmName = mpList[i]; |
235 final String mpmName = mpList[i]; |
232 if (mpmName == null) continue; |
236 if (mpmName == null) continue; |
233 final SnmpOid mpIndex = (SnmpOid)poolIndexMap.get(mpmName); |
237 final SnmpOid mpIndex = poolIndexMap.get(mpmName); |
234 if (mpIndex == null) continue; |
238 if (mpIndex == null) continue; |
235 |
239 |
236 // The MemoryPool index is an int, so it's the first |
240 // The MemoryPool index is an int, so it's the first |
237 // and only subidentifier. |
241 // and only subidentifier. |
238 final long mparc; |
242 final long mparc; |
259 } |
263 } |
260 |
264 |
261 protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, |
265 protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, |
262 SnmpTableHandler mmHandler, |
266 SnmpTableHandler mmHandler, |
263 SnmpTableHandler mpHandler, |
267 SnmpTableHandler mpHandler, |
264 Map poolIndexMap) { |
268 Map<String, SnmpOid> poolIndexMap) { |
265 if (mmHandler instanceof SnmpCachedData) { |
269 if (mmHandler instanceof SnmpCachedData) { |
266 updateTreeMap(table,userData,(SnmpCachedData)mmHandler, |
270 updateTreeMap(table,userData,(SnmpCachedData)mmHandler, |
267 mpHandler,poolIndexMap); |
271 mpHandler,poolIndexMap); |
268 return; |
272 return; |
269 } |
273 } |
278 } |
282 } |
279 |
283 |
280 protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, |
284 protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, |
281 SnmpCachedData mmHandler, |
285 SnmpCachedData mmHandler, |
282 SnmpTableHandler mpHandler, |
286 SnmpTableHandler mpHandler, |
283 Map poolIndexMap) { |
287 Map<String, SnmpOid> poolIndexMap) { |
284 |
288 |
285 final SnmpOid[] indexes = mmHandler.indexes; |
289 final SnmpOid[] indexes = mmHandler.indexes; |
286 final Object[] datas = mmHandler.datas; |
290 final Object[] datas = mmHandler.datas; |
287 final int size = indexes.length; |
291 final int size = indexes.length; |
288 for (int i=size-1; i>-1; i--) { |
292 for (int i=size-1; i>-1; i--) { |