jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadingImpl.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.ThreadMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.management.ManagementFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
// jmx imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jmx.snmp.SnmpString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
// jdmk imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.jmx.snmp.agent.SnmpMib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.jmx.snmp.SnmpDefinitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.management.snmp.jvmmib.JvmThreadingMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.management.snmp.jvmmib.EnumJvmThreadCpuTimeMonitoring;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.management.snmp.jvmmib.EnumJvmThreadContentionMonitoring;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.management.snmp.util.MibLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The class is used for implementing the "JvmThreading" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class JvmThreadingImpl implements JvmThreadingMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Variable for storing the value of "JvmThreadCpuTimeMonitoring".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * "The state of the Thread CPU Time Monitoring feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * This feature can be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * unsupported: The JVM does not support Thread CPU Time Monitoring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * enabled    : The JVM supports Thread CPU Time Monitoring, and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * disabled   : The JVM supports Thread CPU Time Monitoring, and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Only enabled(3) and disabled(4) may be supplied as values to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * SET request. unsupported(1) can only be set internally by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * See java.lang.management.ThreadMXBean.isThreadCpuTimeSupported(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * java.lang.management.ThreadMXBean.isThreadCpuTimeEnabled(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * java.lang.management.ThreadMXBean.setThreadCpuTimeEnabled()
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
    final static EnumJvmThreadCpuTimeMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        JvmThreadCpuTimeMonitoringUnsupported =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        new EnumJvmThreadCpuTimeMonitoring("unsupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    final static EnumJvmThreadCpuTimeMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        JvmThreadCpuTimeMonitoringEnabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        new EnumJvmThreadCpuTimeMonitoring("enabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    final static EnumJvmThreadCpuTimeMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        JvmThreadCpuTimeMonitoringDisabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        new EnumJvmThreadCpuTimeMonitoring("disabled");
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
     * Variable for storing the value of "JvmThreadContentionMonitoring".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * "The state of the Thread Contention Monitoring feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * This feature can be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * unsupported: The JVM does not support Thread Contention Monitoring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * enabled    : The JVM supports Thread Contention Monitoring, and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * disabled   : The JVM supports Thread Contention Monitoring, and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Only enabled(3) and disabled(4) may be supplied as values to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * SET request. unsupported(1) can only be set internally by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * See java.lang.management.ThreadMXBean.isThreadContentionMonitoringSupported(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * java.lang.management.ThreadMXBean.isThreadContentionMonitoringEnabled(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * java.lang.management.ThreadMXBean.setThreadContentionMonitoringEnabled()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    static final EnumJvmThreadContentionMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        JvmThreadContentionMonitoringUnsupported =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        new EnumJvmThreadContentionMonitoring("unsupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    static final EnumJvmThreadContentionMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        JvmThreadContentionMonitoringEnabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        new EnumJvmThreadContentionMonitoring("enabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    static final EnumJvmThreadContentionMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        JvmThreadContentionMonitoringDisabled =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        new EnumJvmThreadContentionMonitoring("disabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Constructor for the "JvmThreading" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * If the group contains a table, the entries created through an SNMP SET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * will not be registered in Java DMK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public JvmThreadingImpl(SnmpMib myMib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        log.debug("JvmThreadingImpl","Constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Constructor for the "JvmThreading" group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * If the group contains a table, the entries created through an SNMP SET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * will be AUTOMATICALLY REGISTERED in Java DMK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public JvmThreadingImpl(SnmpMib myMib, MBeanServer server) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        log.debug("JvmThreadingImpl","Constructor with server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * ThreadMXBean accessor. It is acquired from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * java.lang.management.ManagementFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @return The local ThreadMXBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    static ThreadMXBean getThreadMXBean() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return ManagementFactory.getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Getter for the "JvmThreadCpuTimeMonitoring" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public EnumJvmThreadCpuTimeMonitoring getJvmThreadCpuTimeMonitoring()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        ThreadMXBean mbean = getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if(!mbean.isThreadCpuTimeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            log.debug("getJvmThreadCpuTimeMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                      "Unsupported ThreadCpuTimeMonitoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return JvmThreadCpuTimeMonitoringUnsupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            if(mbean.isThreadCpuTimeEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                log.debug("getJvmThreadCpuTimeMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                      "Enabled ThreadCpuTimeMonitoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                return JvmThreadCpuTimeMonitoringEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                log.debug("getJvmThreadCpuTimeMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                          "Disabled ThreadCpuTimeMonitoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                return JvmThreadCpuTimeMonitoringDisabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }catch(UnsupportedOperationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            log.debug("getJvmThreadCpuTimeMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                      "Newly unsupported ThreadCpuTimeMonitoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return JvmThreadCpuTimeMonitoringUnsupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Setter for the "JvmThreadCpuTimeMonitoring" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public void setJvmThreadCpuTimeMonitoring(EnumJvmThreadCpuTimeMonitoring x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        ThreadMXBean mbean = getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // We can trust the received value, it has been checked in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // checkJvmThreadCpuTimeMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if(JvmThreadCpuTimeMonitoringEnabled.intValue() == x.intValue())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            mbean.setThreadCpuTimeEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            mbean.setThreadCpuTimeEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Checker for the "JvmThreadCpuTimeMonitoring" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public void checkJvmThreadCpuTimeMonitoring(EnumJvmThreadCpuTimeMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                                x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        //Can't be set externaly to unsupported state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if(JvmThreadCpuTimeMonitoringUnsupported.intValue() == x.intValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
             log.debug("checkJvmThreadCpuTimeMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                      "Try to set to illegal unsupported value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if ((JvmThreadCpuTimeMonitoringEnabled.intValue() == x.intValue()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            (JvmThreadCpuTimeMonitoringDisabled.intValue() == x.intValue())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            // The value is a valid value. But is the feature supported?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            ThreadMXBean mbean = getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if(mbean.isThreadCpuTimeSupported()) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            // Not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            log.debug("checkJvmThreadCpuTimeMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                      "Unsupported operation, can't set state");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // Unknown value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        log.debug("checkJvmThreadCpuTimeMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                  "unknown enum value ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Getter for the "JvmThreadContentionMonitoring" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public EnumJvmThreadContentionMonitoring getJvmThreadContentionMonitoring()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        ThreadMXBean mbean = getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if(!mbean.isThreadContentionMonitoringSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            log.debug("getJvmThreadContentionMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                      "Unsupported ThreadContentionMonitoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return JvmThreadContentionMonitoringUnsupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if(mbean.isThreadContentionMonitoringEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            log.debug("getJvmThreadContentionMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                      "Enabled ThreadContentionMonitoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return JvmThreadContentionMonitoringEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            log.debug("getJvmThreadContentionMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                      "Disabled ThreadContentionMonitoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return JvmThreadContentionMonitoringDisabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Setter for the "JvmThreadContentionMonitoring" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public void setJvmThreadContentionMonitoring(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                            EnumJvmThreadContentionMonitoring x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        ThreadMXBean mbean = getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // We can trust the received value, it has been checked in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // checkJvmThreadContentionMonitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if(JvmThreadContentionMonitoringEnabled.intValue() == x.intValue())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            mbean.setThreadContentionMonitoringEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            mbean.setThreadContentionMonitoringEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Checker for the "JvmThreadContentionMonitoring" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public void checkJvmThreadContentionMonitoring(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                              EnumJvmThreadContentionMonitoring x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        //Can't be set externaly to unsupported state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if(JvmThreadContentionMonitoringUnsupported.intValue()==x.intValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            log.debug("checkJvmThreadContentionMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                      "Try to set to illegal unsupported value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if ((JvmThreadContentionMonitoringEnabled.intValue()==x.intValue()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            (JvmThreadContentionMonitoringDisabled.intValue()==x.intValue())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            // The value is valid, but is the feature supported ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            ThreadMXBean mbean = getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            if(mbean.isThreadContentionMonitoringSupported()) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            log.debug("checkJvmThreadContentionMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                      "Unsupported operation, can't set state");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        log.debug("checkJvmThreadContentionMonitoring",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                  "Try to set to unknown value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Getter for the "JvmThreadTotalStartedCount" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public Long getJvmThreadTotalStartedCount() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return new Long(getThreadMXBean().getTotalStartedThreadCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Getter for the "JvmThreadPeakCount" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public Long getJvmThreadPeakCount() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return  new Long(getThreadMXBean().getPeakThreadCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Getter for the "JvmThreadDaemonCount" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public Long getJvmThreadDaemonCount() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return new Long(getThreadMXBean().getDaemonThreadCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Getter for the "JvmThreadCount" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public Long getJvmThreadCount() throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return new Long(getThreadMXBean().getThreadCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Getter for the "JvmThreadPeakCountReset" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public synchronized Long getJvmThreadPeakCountReset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return new Long(jvmThreadPeakCountReset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Setter for the "JvmThreadPeakCountReset" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public synchronized void setJvmThreadPeakCountReset(Long x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        final long l = x.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (l > jvmThreadPeakCountReset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            final long stamp = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            getThreadMXBean().resetPeakThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            jvmThreadPeakCountReset = stamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            log.debug("setJvmThreadPeakCountReset",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                      "jvmThreadPeakCountReset="+stamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Checker for the "JvmThreadPeakCountReset" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public void checkJvmThreadPeakCountReset(Long x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /* Last time thread peak count was reset */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    private long jvmThreadPeakCountReset=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    static final MibLogger log = new MibLogger(JvmThreadingImpl.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
}