Manuel L. Santillan | 295c199 | 2006-09-09 17:48:36 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * This script demonstrates "getMBeanAttribute" |
| 3 | * and "setMBeanAttribute" functions. Instead of using |
| 4 | * MXBean proxy or script wrapper object returned by |
| 5 | * 'mbean' function, this file uses direct get/set MBean |
| 6 | * attribute functions. |
| 7 | * |
| 8 | * To use this particular script, load this script file in |
| 9 | * script console prompt and call verboseGC or verboseClass |
| 10 | * functions. These functions based on events such as |
| 11 | * heap threshold crossing a given limit. i.e., A timer thread |
| 12 | * can keep checking for threshold event and then turn on |
| 13 | * verbose:gc or verbose:class based on expected event. |
| 14 | |
| 15 | */ |
| 16 | |
| 17 | /** |
| 18 | * Get or set verbose GC flag. |
| 19 | * |
| 20 | * @param flag verbose mode flag [optional] |
| 21 | * |
| 22 | * If flag is not passed verboseGC returns current |
| 23 | * flag value. |
| 24 | */ |
| 25 | function verboseGC(flag) { |
| 26 | if (flag == undefined) { |
| 27 | // no argument passed. interpret this as 'get' |
| 28 | return getMBeanAttribute("java.lang:type=Memory", "Verbose"); |
| 29 | } else { |
| 30 | return setMBeanAttribute("java.lang:type=Memory", "Verbose", flag); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get or set verbose class flag. |
| 36 | * |
| 37 | * @param flag verbose mode flag [optional] |
| 38 | * |
| 39 | * If flag is not passed verboseClass returns current |
| 40 | * flag value. |
| 41 | */ |
| 42 | function verboseClass(flag) { |
| 43 | if (flag == undefined) { |
| 44 | // no argument passed. interpret this as 'get' |
| 45 | return getMBeanAttribute("java.lang:type=ClassLoading", "Verbose"); |
| 46 | } else { |
| 47 | return setMBeanAttribute("java.lang:type=ClassLoading", "Verbose", flag); |
| 48 | } |
| 49 | } |