1 /*
   2  * Copyright (c) 2013, 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 border="1" cellpadding="5">
 110  *   <tr>
 111  *     <th>Name</th><th>Type</th><th>Description</th>
 112  *   </tr>
 113  *   <tr>
 114  *     <td>dcmd.name</td><td>String</td>
 115  *     <td>The original diagnostic command name (not the operation name)</td>
 116  *   </tr>
 117  *   <tr>
 118  *     <td>dcmd.description</td><td>String</td>
 119  *     <td>The diagnostic command description</td>
 120  *   </tr>
 121  *   <tr>
 122  *     <td>dcmd.help</td><td>String</td>
 123  *     <td>The full help message for this diagnostic command (same output as
 124  *          the one produced by the 'help' command)</td>
 125  *   </tr>
 126  *   <tr>
 127  *     <td>dcmd.vmImpact</td><td>String</td>
 128  *     <td>The impact of the diagnostic command,
 129  *      this value is the same as the one printed in the 'impact'
 130  *      section of the help message of the diagnostic command, and it
 131  *      is different from the getImpact() of the MBeanOperationInfo</td>
 132  *   </tr>
 133  *   <tr>
 134  *     <td>dcmd.enabled</td><td>boolean</td>
 135  *     <td>True if the diagnostic command is enabled, false otherwise</td>
 136  *   </tr>
 137  *   <tr>
 138  *     <td>dcmd.permissionClass</td><td>String</td>
 139  *     <td>Some diagnostic command might require a specific permission to be
 140  *          executed, in addition to the MBeanPermission to invoke their
 141  *          associated MBean operation. This field returns the fully qualified
 142  *          name of the permission class or null if no permission is required
 143  *   </td>
 144  *   </tr>
 145  *   <tr>
 146  *     <td>dcmd.permissionName</td><td>String</td>
 147  *     <td>The fist argument of the permission required to execute this
 148  *          diagnostic command or null if no permission is required</td>
 149  *   </tr>
 150  *   <tr>
 151  *     <td>dcmd.permissionAction</td><td>String</td>
 152  *     <td>The second argument of the permission required to execute this
 153  *          diagnostic command or null if the permission constructor has only
 154  *          one argument (like the ManagementPermission) or if no permission
 155  *          is required</td>
 156  *   </tr>
 157  *   <tr>
 158  *     <td>dcmd.arguments</td><td>Descriptor</td>
 159  *     <td>A Descriptor instance containing the descriptions of options and
 160  *          arguments supported by the diagnostic command (see below)</td>
 161  *   </tr>
 162  * </table>
 163  *
 164  * <p>The description of parameters (options or arguments) of a diagnostic
 165  * command is provided within a Descriptor instance. In this Descriptor,
 166  * each field name is a parameter name, and each field value is itself
 167  * a Descriptor instance. The fields provided in this second Descriptor
 168  * instance are described in the table below:
 169  *
 170  * <table border="1" cellpadding="5">
 171  *   <tr>
 172  *     <th>Name</th><th>Type</th><th>Description</th>
 173  *   </tr>
 174  *   <tr>
 175  *     <td>dcmd.arg.name</td><td>String</td>
 176  *     <td>The name of the parameter</td>
 177  *   </tr>
 178  *   <tr>
 179  *     <td>dcmd.arg.type</td><td>String</td>
 180  *     <td>The type of the parameter. The returned String is the name of a type
 181  *          recognized by the diagnostic command parser. These types are not
 182  *          Java types and are implementation dependent.
 183  *          </td>
 184  *   </tr>
 185  *   <tr>
 186  *     <td>dcmd.arg.description</td><td>String</td>
 187  *     <td>The parameter description</td>
 188  *   </tr>
 189  *   <tr>
 190  *     <td>dcmd.arg.isMandatory</td><td>boolean</td>
 191  *     <td>True if the parameter is mandatory, false otherwise</td>
 192  *   </tr>
 193  *   <tr>
 194  *     <td>dcmd.arg.isOption</td><td>boolean</td>
 195  *     <td>True if the parameter is an option, false if it is an argument</td>
 196  *   </tr>
 197  *   <tr>
 198  *     <td>dcmd.arg.isMultiple</td><td>boolean</td>
 199  *     <td>True if the parameter can be specified several times, false
 200  *          otherwise</td>
 201  *   </tr>
 202  * </table>
 203  *
 204  * <p>When the set of diagnostic commands currently supported by the Java
 205  * Virtual Machine is modified, the {@code DiagnosticCommandMBean} emits
 206  * a {@link javax.management.Notification} with a
 207  * {@linkplain javax.management.Notification#getType() type} of
 208  * <a href="{@docRoot}/../../../../api/javax/management/MBeanInfo.html#info-changed">
 209  * {@code "jmx.mbean.info.changed"}</a> and a
 210  * {@linkplain javax.management.Notification#getUserData() userData} that
 211  * is the new {@code MBeanInfo}.
 212  *
 213  * @since 1.8
 214  */
 215 public interface DiagnosticCommandMBean extends DynamicMBean
 216 {
 217 
 218 }