1 /*
   2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.management;
  27 
  28 import java.lang.management.PlatformManagedObject;
  29 import javax.management.DynamicMBean;
  30 
  31 /**
  32  * Management interface for the diagnostic commands for the HotSpot Virtual Machine.
  33  *
  34  * <p>The {@code DiagnosticCommandMBean} is registered to the
  35  * {@linkplain java.lang.management.ManagementFactory#getPlatformMBeanServer
  36  * platform MBeanServer} as are other platform MBeans.
  37  *
  38  * <p>The {@link javax.management.ObjectName ObjectName} for uniquely identifying
  39  * the diagnostic MBean within an MBeanServer is:
  40  * <blockquote>
  41  *    {@code com.sun.management:type=DiagnosticCommand}
  42  * </blockquote>
  43  *
  44  * <p>This MBean is a {@link javax.management.DynamicMBean DynamicMBean}
  45  * and also a {@link javax.management.NotificationEmitter}.
  46  * The {@code DiagnosticCommandMBean} is generated at runtime and is subject to
  47  * modifications during the lifetime of the Java virtual machine.
  48  *
  49  * A <em>diagnostic command</em> is represented as an operation of
  50  * the {@code DiagnosticCommandMBean} interface. Each diagnostic command has:
  51  * <ul>
  52  * <li>the diagnostic command name which is the name being referenced in
  53  *     the HotSpot Virtual Machine</li>
  54  * <li>the MBean operation name which is the
  55  *     {@linkplain javax.management.MBeanOperationInfo#getName() name}
  56  *     generated for the diagnostic command operation invocation.
  57  *     The MBean operation name is implementation dependent</li>
  58  * </ul>
  59  *
  60  * The recommended way to transform a diagnostic command name into a MBean
  61  * operation name is as follows:
  62  * <ul>
  63  * <li>All characters from the first one to the first dot are set to be
  64  *      lower-case characters</li>
  65  * <li>Every dot or underline character is removed and the following
  66  *   character is set to be an upper-case character</li>
  67  * <li>All other characters are copied without modification</li>
  68  * </ul>
  69  *
  70  * <p>The diagnostic command name is always provided with the meta-data on the
  71  * operation in a field named {@code dcmd.name} (see below).
  72  *
  73  * <p>A diagnostic command may or may not support options or arguments.
  74  * All the operations return {@code String} and either take
  75  * no parameter for operations that do not support any option or argument,
  76  * or take a {@code String[]} parameter for operations that support at least
  77  * one option or argument.
  78  * Each option or argument must be stored in a single String.
  79  * Options or arguments split across several String instances are not supported.
  80  *
  81  * <p>The distinction between options and arguments: options are identified by
  82  * the option name while arguments are identified by their position in the
  83  * command line. Options and arguments are processed in the order of the array
  84  * passed to the invocation method.
  85  *
  86  * <p>Like any operation of a dynamic MBean, each of these operations is
  87  * described by {@link javax.management.MBeanOperationInfo MBeanOperationInfo}
  88  * instance. Here's the values returned by this object:
  89  * <ul>
  90  *  <li>{@link javax.management.MBeanOperationInfo#getName() getName()}
  91  *      returns the operation name generated from the diagnostic command name</li>
  92  *  <li>{@link javax.management.MBeanOperationInfo#getDescription() getDescription()}
  93  *      returns the diagnostic command description
  94  *      (the same as the one return in the 'help' command)</li>
  95  *  <li>{@link javax.management.MBeanOperationInfo#getImpact() getImpact()}
  96  *      returns {@code ACTION_INFO}</li>
  97  *  <li>{@link javax.management.MBeanOperationInfo#getReturnType() getReturnType()}
  98  *      returns {@code java.lang.String}</li>
  99  *  <li>{@link javax.management.MBeanOperationInfo#getDescriptor() getDescriptor()}
 100  *      returns a Descriptor instance (see below)</li>
 101  * </ul>
 102  *
 103  * <p>The {@link javax.management.Descriptor Descriptor}
 104  * is a collection of fields containing additional
 105  * meta-data for a JMX element. A field is a name and an associated value.
 106  * The additional meta-data provided for an operation associated with a
 107  * diagnostic command are described in the table below:
 108  *
 109  * <table class="striped"><caption style="display:none">description</caption>
 110  *   <thead>
 111  *   <tr>
 112  *     <th scope="col">Name</th><th scope="col">Type</th><th scope="col">Description</th>
 113  *   </tr>
 114  *   </thead>
 115  *   <tbody>
 116  *   <tr>
 117  *     <th scope="row">dcmd.name</th><td>String</td>
 118  *     <td>The original diagnostic command name (not the operation name)</td>
 119  *   </tr>
 120  *   <tr>
 121  *     <th scope="row">dcmd.description</th><td>String</td>
 122  *     <td>The diagnostic command description</td>
 123  *   </tr>
 124  *   <tr>
 125  *     <th scope="row">dcmd.help</th><td>String</td>
 126  *     <td>The full help message for this diagnostic command (same output as
 127  *          the one produced by the 'help' command)</td>
 128  *   </tr>
 129  *   <tr>
 130  *     <th scope="row">dcmd.vmImpact</th><td>String</td>
 131  *     <td>The impact of the diagnostic command,
 132  *      this value is the same as the one printed in the 'impact'
 133  *      section of the help message of the diagnostic command, and it
 134  *      is different from the getImpact() of the MBeanOperationInfo</td>
 135  *   </tr>
 136  *   <tr>
 137  *     <th scope="row">dcmd.enabled</th><td>boolean</td>
 138  *     <td>True if the diagnostic command is enabled, false otherwise</td>
 139  *   </tr>
 140  *   <tr>
 141  *     <th scope="row">dcmd.permissionClass</th><td>String</td>
 142  *     <td>Some diagnostic command might require a specific permission to be
 143  *          executed, in addition to the MBeanPermission to invoke their
 144  *          associated MBean operation. This field returns the fully qualified
 145  *          name of the permission class or null if no permission is required
 146  *   </td>
 147  *   </tr>
 148  *   <tr>
 149  *     <th scope="row">dcmd.permissionName</th><td>String</td>
 150  *     <td>The fist argument of the permission required to execute this
 151  *          diagnostic command or null if no permission is required</td>
 152  *   </tr>
 153  *   <tr>
 154  *     <th scope="row">dcmd.permissionAction</th><td>String</td>
 155  *     <td>The second argument of the permission required to execute this
 156  *          diagnostic command or null if the permission constructor has only
 157  *          one argument (like the ManagementPermission) or if no permission
 158  *          is required</td>
 159  *   </tr>
 160  *   <tr>
 161  *     <th scope="row">dcmd.arguments</th><td>Descriptor</td>
 162  *     <td>A Descriptor instance containing the descriptions of options and
 163  *          arguments supported by the diagnostic command (see below)</td>
 164  *   </tr>
 165  *   </tbody>
 166  * </table>
 167  *
 168  * <p>The description of parameters (options or arguments) of a diagnostic
 169  * command is provided within a Descriptor instance. In this Descriptor,
 170  * each field name is a parameter name, and each field value is itself
 171  * a Descriptor instance. The fields provided in this second Descriptor
 172  * instance are described in the table below:
 173  *
 174  * <table class="striped"><caption style="display:none">description</caption>
 175  *   <thead>
 176  *   <tr>
 177  *     <th scope="col">Name</th><th scope="col">Type</th><th scope="col">Description</th>
 178  *   </tr>
 179  *   </thead>
 180  *   <tbody>
 181  *   <tr>
 182  *     <th scope="row">dcmd.arg.name</th><td>String</td>
 183  *     <td>The name of the parameter</td>
 184  *   </tr>
 185  *   <tr>
 186  *     <th scope="row">dcmd.arg.type</th><td>String</td>
 187  *     <td>The type of the parameter. The returned String is the name of a type
 188  *          recognized by the diagnostic command parser. These types are not
 189  *          Java types and are implementation dependent.
 190  *          </td>
 191  *   </tr>
 192  *   <tr>
 193  *     <th scope="row">dcmd.arg.description</th><td>String</td>
 194  *     <td>The parameter description</td>
 195  *   </tr>
 196  *   <tr>
 197  *     <th scope="row">dcmd.arg.isMandatory</th><td>boolean</td>
 198  *     <td>True if the parameter is mandatory, false otherwise</td>
 199  *   </tr>
 200  *   <tr>
 201  *     <th scope="row">dcmd.arg.isOption</th><td>boolean</td>
 202  *     <td>True if the parameter is an option, false if it is an argument</td>
 203  *   </tr>
 204  *   <tr>
 205  *     <th scope="row">dcmd.arg.isMultiple</th><td>boolean</td>
 206  *     <td>True if the parameter can be specified several times, false
 207  *          otherwise</td>
 208  *   </tr>
 209  *   </tbody>
 210  * </table>
 211  *
 212  * <p>When the set of diagnostic commands currently supported by the Java
 213  * Virtual Machine is modified, the {@code DiagnosticCommandMBean} emits
 214  * a {@link javax.management.Notification} with a
 215  * {@linkplain javax.management.Notification#getType() type} of
 216  * <a href="{@docRoot}/java.management/javax/management/MBeanInfo.html#info-changed">
 217  * {@code "jmx.mbean.info.changed"}</a> and a
 218  * {@linkplain javax.management.Notification#getUserData() userData} that
 219  * is the new {@code MBeanInfo}.
 220  *
 221  * @since 1.8
 222  */
 223 public interface DiagnosticCommandMBean extends DynamicMBean
 224 {
 225 
 226 }