From version 17.1
edited by Vincent Massol
on 2016/07/22 15:00
To version 18.1
edited by Denis Gervalle
on 2018/06/20 11:35
Change comment: Add a snippet sample for switching the collection of statistics for a cache

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.VincentMassol
1 +xwiki:XWiki.dgervalle
EXOExtensionCode.ExtensionClass[0]
compatibility
... ... @@ -1,0 +1,1 @@
1 +XE >= 3.0
ExtensionCode.ExtensionClass[0]
Description
... ... @@ -210,3 +210,24 @@
210 210  }
211 211  {{/groovy}}
212 212  {{/code}}
213 +
214 += Example 7: Switch statistics collection states (enabled/disabled) on a cache =
215 +
216 +Example to switch the current state of statistics collection for the page cache ("xwiki.store.pagecache(local)"):
217 +
218 +{{code}}
219 +{{groovy}}
220 +import java.lang.management.ManagementFactory;
221 +import javax.management.MBeanServer;
222 +import javax.management.ObjectName;
223 +import javax.management.Attribute;
224 +
225 +MBeanServer server = ManagementFactory.getPlatformMBeanServer();
226 +def objectName = new ObjectName('org.xwiki.infinispan:type=Cache,name="xwiki.store.pagecache(local)",manager="xwiki",component=Statistics')
227 +def statsState = server.getAttribute(objectName,'statisticsEnabled')
228 +println "Statistics were ${statsState ? 'enabled' : 'disabled'}";
229 +def enableStats = new Attribute("statisticsEnabled", !statsState);
230 +server.setAttribute(objectName,enableStats);
231 +println "Statistics are now ${server.getAttribute(objectName,'statisticsEnabled') ? 'enabled' : 'disabled'}";
232 +{{/groovy}}
233 +{{/code}}

Get Connected