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