J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | package sun.management.snmp.jvminstr; |
| 26 | |
| 27 | // java imports |
| 28 | // |
| 29 | import java.io.Serializable; |
| 30 | |
| 31 | import java.lang.management.ClassLoadingMXBean; |
| 32 | import java.lang.management.ManagementFactory; |
| 33 | // jmx imports |
| 34 | // |
| 35 | import javax.management.MBeanServer; |
| 36 | import com.sun.jmx.snmp.SnmpString; |
| 37 | import com.sun.jmx.snmp.SnmpStatusException; |
| 38 | |
| 39 | // jdmk imports |
| 40 | // |
| 41 | import com.sun.jmx.snmp.agent.SnmpMib; |
| 42 | |
| 43 | import sun.management.snmp.jvmmib.JvmClassLoadingMBean; |
| 44 | import sun.management.snmp.jvmmib.EnumJvmClassesVerboseLevel; |
| 45 | import sun.management.snmp.util.MibLogger; |
| 46 | |
| 47 | /** |
| 48 | * The class is used for implementing the "JvmClassLoading" group. |
| 49 | */ |
| 50 | public class JvmClassLoadingImpl implements JvmClassLoadingMBean { |
| 51 | |
| 52 | /** |
| 53 | * Variable for storing the value of "JvmClassesVerboseLevel". |
| 54 | * |
| 55 | * "verbose: if the -verbose:class flag is set. |
| 56 | * silent: otherwise. |
| 57 | * |
| 58 | * See java.management.ClassLoadingMXBean.isVerbose(), |
| 59 | * java.management.ClassLoadingMXBean.setVerbose() |
| 60 | * " |
| 61 | * |
| 62 | */ |
| 63 | static final EnumJvmClassesVerboseLevel JvmClassesVerboseLevelVerbose = |
| 64 | new EnumJvmClassesVerboseLevel("verbose"); |
| 65 | static final EnumJvmClassesVerboseLevel JvmClassesVerboseLevelSilent = |
| 66 | new EnumJvmClassesVerboseLevel("silent"); |
| 67 | |
| 68 | /** |
| 69 | * Constructor for the "JvmClassLoading" group. |
| 70 | * If the group contains a table, the entries created through an |
| 71 | * SNMP SET will not be registered in Java DMK. |
| 72 | */ |
| 73 | public JvmClassLoadingImpl(SnmpMib myMib) { |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Constructor for the "JvmClassLoading" group. |
| 78 | * If the group contains a table, the entries created through an SNMP SET |
| 79 | * will be AUTOMATICALLY REGISTERED in Java DMK. |
| 80 | */ |
| 81 | public JvmClassLoadingImpl(SnmpMib myMib, MBeanServer server) { |
| 82 | } |
| 83 | |
| 84 | static ClassLoadingMXBean getClassLoadingMXBean() { |
| 85 | return ManagementFactory.getClassLoadingMXBean(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Getter for the "JvmClassesVerboseLevel" variable. |
| 90 | */ |
| 91 | public EnumJvmClassesVerboseLevel getJvmClassesVerboseLevel() |
| 92 | throws SnmpStatusException { |
| 93 | if(getClassLoadingMXBean().isVerbose()) |
| 94 | return JvmClassesVerboseLevelVerbose; |
| 95 | else |
| 96 | return JvmClassesVerboseLevelSilent; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Setter for the "JvmClassesVerboseLevel" variable. |
| 101 | */ |
| 102 | public void setJvmClassesVerboseLevel(EnumJvmClassesVerboseLevel x) |
| 103 | throws SnmpStatusException { |
| 104 | final boolean verbose; |
| 105 | if (JvmClassesVerboseLevelVerbose.equals(x)) verbose=true; |
| 106 | else if (JvmClassesVerboseLevelSilent.equals(x)) verbose=false; |
| 107 | // Should never happen, this case is handled by |
| 108 | // checkJvmClassesVerboseLevel(); |
| 109 | else throw new |
| 110 | SnmpStatusException(SnmpStatusException.snmpRspWrongValue); |
| 111 | getClassLoadingMXBean().setVerbose(verbose); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Checker for the "JvmClassesVerboseLevel" variable. |
| 116 | */ |
| 117 | public void checkJvmClassesVerboseLevel(EnumJvmClassesVerboseLevel x) |
| 118 | throws SnmpStatusException { |
| 119 | // |
| 120 | // Add your own checking policy. |
| 121 | // |
| 122 | if (JvmClassesVerboseLevelVerbose.equals(x)) return; |
| 123 | if (JvmClassesVerboseLevelSilent.equals(x)) return; |
| 124 | throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue); |
| 125 | |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Getter for the "JvmClassesUnloadedCount" variable. |
| 130 | */ |
| 131 | public Long getJvmClassesUnloadedCount() throws SnmpStatusException { |
| 132 | return new Long(getClassLoadingMXBean().getUnloadedClassCount()); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Getter for the "JvmClassesTotalLoadedCount" variable. |
| 137 | */ |
| 138 | public Long getJvmClassesTotalLoadedCount() throws SnmpStatusException { |
| 139 | return new Long(getClassLoadingMXBean().getTotalLoadedClassCount()); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Getter for the "JvmClassesLoadedCount" variable. |
| 144 | */ |
| 145 | public Long getJvmClassesLoadedCount() throws SnmpStatusException { |
| 146 | return new Long(getClassLoadingMXBean().getLoadedClassCount()); |
| 147 | } |
| 148 | |
| 149 | } |