src/java.management/share/classes/javax/management/MBeanOperationInfo.java
author dholmes
Mon, 18 Nov 2019 23:41:06 -0500
changeset 59132 189f47d990b5
parent 47909 da4fb7d2f917
permissions -rw-r--r--
8215355: Object monitor deadlock with no threads holding the monitor (using jemalloc 5.1) Reviewed-by: rehn, stuefe, dcubed, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
47909
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2017, 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: 4156
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: 4156
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: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jmx.mbeanserver.Introspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.annotation.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Arrays;
19852
f8e5a6c5d379 8023669: MBean*Info.hashCode : NPE
sjiang
parents: 5506
diff changeset
    32
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Describes a management operation exposed by an MBean.  Instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * this class are immutable.  Subclasses may be mutable but this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class MBeanOperationInfo extends MBeanFeatureInfo implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static final long serialVersionUID = -6178860474881375330L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final MBeanOperationInfo[] NO_OPERATIONS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        new MBeanOperationInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    50
     * Indicates that the operation is read-like:
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    51
     * it returns information but does not change any state.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int INFO = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    56
     * Indicates that the operation is write-like: it has an effect but does
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    57
     * not return any information from the MBean.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static final int ACTION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    62
     * Indicates that the operation is both read-like and write-like:
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    63
     * it has an effect, and it also returns information from the MBean.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static final int ACTION_INFO = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    68
     * Indicates that the impact of the operation is unknown or cannot be
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    69
     * expressed using one of the other values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final int UNKNOWN = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @serial The method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @serial The signature of the method, that is, the class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * of the arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private final MBeanParameterInfo[] signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @serial The impact of the method, one of
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
    86
     *         {@code INFO, ACTION, ACTION_INFO, UNKNOWN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private final int impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /** @see MBeanInfo#arrayGettersSafe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private final transient boolean arrayGettersSafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
    95
     * Constructs an {@code MBeanOperationInfo} object.  The
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * {@link Descriptor} of the constructed object will include
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * fields contributed by any annotations on the {@code Method}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * object that contain the {@link DescriptorKey} meta-annotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   100
     * @param method The {@code java.lang.reflect.Method} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * describing the MBean operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public MBeanOperationInfo(String description, Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this(method.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
             description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
             methodSignature(method),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
             method.getReturnType().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
             UNKNOWN,
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   110
             Introspector.descriptorForElement(method));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   114
     * Constructs an {@code MBeanOperationInfo} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param name The name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param description A human readable description of the operation.
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   118
     * @param signature {@code MBeanParameterInfo} objects
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * describing the parameters(arguments) of the method.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param type The type of the method's return value.
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   122
     * @param impact The impact of the method, one of
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   123
     * {@link #INFO}, {@link #ACTION}, {@link #ACTION_INFO},
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   124
     * {@link #UNKNOWN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public MBeanOperationInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                              MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                              String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                              int impact) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this(name, description, signature, type, impact, (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   135
     * Constructs an {@code MBeanOperationInfo} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param name The name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param description A human readable description of the operation.
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   139
     * @param signature {@code MBeanParameterInfo} objects
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * describing the parameters(arguments) of the method.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param type The type of the method's return value.
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   143
     * @param impact The impact of the method, one of
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   144
     * {@link #INFO}, {@link #ACTION}, {@link #ACTION_INFO},
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   145
     * {@link #UNKNOWN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param descriptor The descriptor for the operation.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
47909
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   149
     * @throws IllegalArgumentException if {@code impact} is not one of
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   150
     * {@linkplain #ACTION}, {@linkplain #ACTION_INFO}, {@linkplain #INFO} or {@linkplain #UNKNOWN}.
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   151
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public MBeanOperationInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                              MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                              String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                              int impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                              Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        super(name, description, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
47909
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   163
        if (impact < INFO || impact > UNKNOWN) {
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   164
            throw new IllegalArgumentException("Argument impact can only be "
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   165
                    + "one of ACTION, ACTION_INFO, "
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   166
                    + "INFO, or UNKNOWN" + " given value is :" + impact);
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   167
        }
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   168
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (signature == null || signature.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            signature = MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            signature = signature.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        this.signature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        this.impact = impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this.arrayGettersSafe =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            MBeanInfo.arrayGettersSafe(this.getClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                       MBeanOperationInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <p>Returns a shallow clone of this instance.
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   183
     * The clone is obtained by simply calling {@code super.clone()},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * thus calling the default native shallow cloning mechanism
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   185
     * implemented by {@code Object.clone()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * No deeper cloning of any internal field is made.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <p>Since this class is immutable, cloning is chiefly of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * to subclasses.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   191
     @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     public Object clone () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
             return super.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
             // should not happen as this class is cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns the type of the method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return the return type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public String getReturnType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <p>Returns the list of parameters for this operation.  Each
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   212
     * parameter is described by an {@code MBeanParameterInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <p>The returned array is a shallow copy of the internal array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * which means that it is a copy of the internal array of
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   217
     * references to the {@code MBeanParameterInfo} objects but
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   218
     * that each referenced {@code MBeanParameterInfo} object is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * not copied.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   221
     * @return  An array of {@code MBeanParameterInfo} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public MBeanParameterInfo[] getSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // If MBeanOperationInfo was created in our implementation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        // signature cannot be null - because our constructors replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // null with MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        // However, signature could be null if an  MBeanOperationInfo is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // deserialized from a byte array produced by another implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // This is not very likely but possible, since the serial form says
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        // nothing against it. (see 6373150)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (signature == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // if signature is null simply return an empty array .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        else if (signature.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return signature.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    private MBeanParameterInfo[] fastGetSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (arrayGettersSafe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            // if signature is null simply return an empty array .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            // see getSignature() above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (signature == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                return MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            else return signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } else return getSignature();
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
     * Returns the impact of the method, one of
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   256
     * {@code INFO, ACTION, ACTION_INFO, UNKNOWN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return the impact code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public int getImpact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   264
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        String impactString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        switch (getImpact()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        case ACTION: impactString = "action"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        case ACTION_INFO: impactString = "action/info"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        case INFO: impactString = "info"; break;
47909
da4fb7d2f917 8024352: MBeanOperationInfo accepts any int value as "impact"
uvangapally
parents: 47216
diff changeset
   271
        default: impactString = "unknown";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return getClass().getName() + "[" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            "description=" + getDescription() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            "name=" + getName() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            "returnType=" + getReturnType() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            "signature=" + Arrays.asList(fastGetSignature()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            "impact=" + impactString + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            "descriptor=" + getDescriptor() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Compare this MBeanOperationInfo to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param o the object to compare to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   288
     * @return true if and only if {@code o} is an MBeanOperationInfo such
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * that its {@link #getName()}, {@link #getReturnType()}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * #getDescription()}, {@link #getImpact()}, {@link #getDescriptor()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * and {@link #getSignature()} values are equal (not necessarily identical)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * to those of this MBeanConstructorInfo.  Two signature arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * are equal if their elements are pairwise equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   295
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if (o == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (!(o instanceof MBeanOperationInfo))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        MBeanOperationInfo p = (MBeanOperationInfo) o;
20174
360791181f66 8023954: MBean*Info.equals: throw NPE
sjiang
parents: 19852
diff changeset
   302
        return (Objects.equals(p.getName(), getName()) &&
360791181f66 8023954: MBean*Info.equals: throw NPE
sjiang
parents: 19852
diff changeset
   303
                Objects.equals(p.getReturnType(), getReturnType()) &&
360791181f66 8023954: MBean*Info.equals: throw NPE
sjiang
parents: 19852
diff changeset
   304
                Objects.equals(p.getDescription(), getDescription()) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                p.getImpact() == getImpact() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                Arrays.equals(p.fastGetSignature(), fastGetSignature()) &&
20174
360791181f66 8023954: MBean*Info.equals: throw NPE
sjiang
parents: 19852
diff changeset
   307
                Objects.equals(p.getDescriptor(), getDescriptor()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /* We do not include everything in the hashcode.  We assume that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
       if two operations are different they'll probably have different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
       names or types.  The penalty we pay when this assumption is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
       wrong should be less than the penalty we would pay if it were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
       right and we needlessly hashed in the description and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
       parameter array.  */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   316
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public int hashCode() {
19852
f8e5a6c5d379 8023669: MBean*Info.hashCode : NPE
sjiang
parents: 5506
diff changeset
   318
        return Objects.hash(getName(), getReturnType());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    private static MBeanParameterInfo[] methodSignature(Method method) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   322
        final Class<?>[] classes = method.getParameterTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        final Annotation[][] annots = method.getParameterAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return parameters(classes, annots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   327
    static MBeanParameterInfo[] parameters(Class<?>[] classes,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                           Annotation[][] annots) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        final MBeanParameterInfo[] params =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            new MBeanParameterInfo[classes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        assert(classes.length == annots.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            Descriptor d = Introspector.descriptorForAnnotations(annots[i]);
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   335
            final String pn = "p" + (i + 1);
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   336
            params[i] =
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1699
diff changeset
   337
                new MBeanParameterInfo(pn, classes[i].getName(), "", d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
}