src/java.management/share/classes/javax/management/MXBean.java
author prr
Mon, 04 Nov 2019 10:01:55 -0800
changeset 59176 f5adbf111424
parent 55120 b0513c833960
permissions -rw-r--r--
8233097: Fontmetrics for large Fonts has zero width Reviewed-by: jdv, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2019, 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 java.lang.annotation.Documented;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.annotation.ElementType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.annotation.Retention;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.annotation.RetentionPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.annotation.Target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
// remaining imports are for Javadoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.management.MemoryUsage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.reflect.UndeclaredThrowableException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.openmbean.ArrayType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.openmbean.CompositeDataInvocationHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.openmbean.CompositeDataSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.openmbean.CompositeDataView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.openmbean.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.openmbean.OpenDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.openmbean.OpenMBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.openmbean.OpenType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.openmbean.SimpleType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.openmbean.TabularData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.management.openmbean.TabularDataSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.management.openmbean.TabularType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
/**
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1153
diff changeset
    55
    <p>Annotation to mark an interface explicitly as being an MXBean
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1153
diff changeset
    56
    interface, or as not being an MXBean interface.  By default, an
18805
b359f8adc8ad 8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents: 15300
diff changeset
    57
    interface is an MXBean interface if it is public and its name ends
b359f8adc8ad 8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents: 15300
diff changeset
    58
    with {@code MXBean}, as in {@code SomethingMXBean}.  The following
b359f8adc8ad 8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents: 15300
diff changeset
    59
    interfaces are MXBean interfaces:</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public interface WhatsitMXBean {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    &#64;MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public interface Whatsit1Interface {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    &#64;MXBean(true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public interface Whatsit2Interface {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    <p>The following interfaces are not MXBean interfaces:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    <pre>
18805
b359f8adc8ad 8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents: 15300
diff changeset
    74
    interface NonPublicInterfaceNotMXBean{}
b359f8adc8ad 8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents: 15300
diff changeset
    75
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public interface Whatsit3Interface{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    &#64;MXBean(false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public interface MisleadingMXBean {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
    82
    <h2 id="MXBean-spec">MXBean specification</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    <p>The MXBean concept provides a simple way to code an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      that only references a predefined set of types, the ones defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      by {@link javax.management.openmbean}.  In this way, you can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
      sure that your MBean will be usable by any client, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      remote clients, without any requirement that the client have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      access to <em>model-specific classes</em> representing the types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      of your MBeans.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    <p>The concepts are easier to understand by comparison with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      Standard MBean concept.  Here is how a managed object might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      represented as a Standard MBean, and as an MXBean:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
    96
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
    97
        <h3>Standard MBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
    98
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
public interface MemoryPool<b>MBean</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    MemoryUsage getUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   104
          </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   105
    </div>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   106
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   107
        <h3>MXBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   108
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
public interface MemoryPool<b>MXBean</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    MemoryUsage getUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    // ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   114
          </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   115
    </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    <p>As you can see, the definitions are very similar.  The only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      difference is that the convention for naming the interface is to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      <code><em>Something</em>MXBean</code> for MXBeans, rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      <code><em>Something</em>MBean</code> for Standard MBeans.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    <p>In this managed object, there is an attribute called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      <code>Usage</code> of type {@link MemoryUsage}.  The point of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      attribute like this is that it gives a coherent snapshot of a set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      of data items.  For example, it might include the current amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      of used memory in the memory pool, and the current maximum of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
      memory pool.  If these were separate items, obtained with separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      {@link MBeanServer#getAttribute getAttribute} calls, then we could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      get values seen at different times that were not consistent.  We
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      might get a <code>used</code> value that was greater than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      <code>max</code> value.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    <p>So, we might define <code>MemoryUsage</code> like this:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   135
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   136
        <h3>Standard MBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   137
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
public class MemoryUsage <b>implements Serializable</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // standard JavaBean conventions with getters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public MemoryUsage(long init, long used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                       long committed, long max) {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    long getInit() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    long getUsed() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    long getCommitted() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    long getMax() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   148
        </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   149
    </div>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   150
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   151
        <h3>MXBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   152
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
public class MemoryUsage {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    // standard JavaBean conventions with getters
33499
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   155
    <b>&#64;ConstructorParameters({"init", "used", "committed", "max"})</b>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public MemoryUsage(long init, long used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                       long committed, long max) {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    long getInit() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    long getUsed() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    long getCommitted() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    long getMax() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   163
        </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   164
    </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    <p>The definitions are the same in the two cases, except
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      that with the MXBean, <code>MemoryUsage</code> no longer needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      be marked <code>Serializable</code> (though it can be).  On
33499
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   169
      the other hand, we have added a {@link ConstructorParameters &#64;ConstructorParameters}
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   170
      annotation to link the constructor parameters to the corresponding getters.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      We will see more about this below.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    <p><code>MemoryUsage</code> is a <em>model-specific class</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      With Standard MBeans, a client of the MBean Server cannot access the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      <code>Usage</code> attribute if it does not know the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      <code>MemoryUsage</code>.  Suppose the client is a generic console
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      based on JMX technology.  Then the console would have to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      configured with the model-specific classes of every application it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
      might connect to.  The problem is even worse for clients that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
      not written in the Java language.  Then there may not be any way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
      to tell the client what a <code>MemoryUsage</code> looks like.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    <p>This is where MXBeans differ from Standard MBeans.  Although we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
      define the management interface in almost exactly the same way,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      the MXBean framework <em>converts</em> model-specific classes into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      standard classes from the Java platform.  Using arrays and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
      {@link javax.management.openmbean.CompositeData CompositeData} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      {@link javax.management.openmbean.TabularData TabularData} classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      from the standard {@link javax.management.openmbean} package, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      is possible to build data structures of arbitrary complexity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      using only standard classes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    <p>This becomes clearer if we compare what the clients of the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      models might look like:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   196
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   197
        <h3>Standard MBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   198
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
String name = (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    mbeanServer.{@link MBeanServer#getAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    getAttribute}(objectName, "Name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
<b>MemoryUsage</b> usage = (<b>MemoryUsage</b>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    mbeanServer.getAttribute(objectName, "Usage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
<b>long used = usage.getUsed();</b>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   205
        </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   206
    </div>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   207
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   208
        <h3>MXBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   209
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
String name = (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    mbeanServer.{@link MBeanServer#getAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    getAttribute}(objectName, "Name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
<b>{@link CompositeData}</b> usage = (<b>CompositeData</b>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    mbeanServer.getAttribute(objectName, "Usage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
<b>long used = (Long) usage.{@link CompositeData#get get}("used");</b>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   216
        </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   217
    </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    <p>For attributes with simple types like <code>String</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      code is the same.  But for attributes with complex types, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
      Standard MBean code requires the client to know the model-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      class <code>MemoryUsage</code>, while the MXBean code requires no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
      non-standard classes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    <p>The client code shown here is slightly more complicated for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
      MXBean client.  But, if the client does in fact know the model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      here the interface <code>MemoryPoolMXBean</code> and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      class <code>MemoryUsage</code>, then it can construct a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
      <em>proxy</em>.  This is the recommended way to interact with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      managed objects when you know the model beforehand, regardless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      of whether you are using Standard MBeans or MXBeans:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   233
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   234
        <h3>Standard MBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   235
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
MemoryPool<b>MBean</b> proxy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    JMX.<b>{@link JMX#newMBeanProxy(MBeanServerConnection, ObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
              Class) newMBeanProxy}</b>(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        mbeanServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        MemoryPool<b>MBean</b>.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
String name = proxy.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
MemoryUsage usage = proxy.getUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
long used = usage.getUsed();
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   245
          </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   246
    </div>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   247
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   248
        <h3>MXBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   249
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
MemoryPool<b>MXBean</b> proxy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    JMX.<b>{@link JMX#newMXBeanProxy(MBeanServerConnection, ObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
              Class) newMXBeanProxy}</b>(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        mbeanServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        MemoryPool<b>MXBean</b>.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
String name = proxy.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
MemoryUsage usage = proxy.getUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
long used = usage.getUsed();
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   259
          </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   260
    </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    <p>Implementing the MemoryPool object works similarly for both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      Standard MBeans and MXBeans.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   265
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   266
        <h3>Standard MBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   267
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
public class MemoryPool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        implements MemoryPool<b>MBean</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public String getName() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public MemoryUsage getUsage() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    // ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   274
        </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   275
    </div>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   276
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   277
        <h3>MXBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   278
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
public class MemoryPool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        implements MemoryPool<b>MXBean</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public String getName() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public MemoryUsage getUsage() {...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    // ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
}
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   285
        </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   286
    </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    <p>Registering the MBean in the MBean Server works in the same way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      in both cases:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   291
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   292
        <h3>Standard MBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   293
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    MemoryPool<b>MBean</b> pool = new MemoryPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    mbeanServer.{@link MBeanServer#registerMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    registerMBean}(pool, objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
}
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   299
        </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   300
    </div>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   301
    <div style="display:inline-block; margin: 0 3em">
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
   302
        <h3>MXBean</h3>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   303
        <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    MemoryPool<b>MXBean</b> pool = new MemoryPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    mbeanServer.{@link MBeanServer#registerMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    registerMBean}(pool, objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
}
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   309
        </pre>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   310
    </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   313
    <h2 id="mxbean-def">Definition of an MXBean</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    <p>An MXBean is a kind of MBean.  An MXBean object can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
      registered directly in the MBean Server, or it can be used as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      argument to {@link StandardMBean} and the resultant MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      registered in the MBean Server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    <p>When an object is registered in the MBean Server using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      {@code registerMBean} or {@code createMBean} methods of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      {@link MBeanServer} interface, the object's class is examined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
      to determine what type of MBean it is:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      <li>If the class implements the interface {@link DynamicMBean}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        then the MBean is a Dynamic MBean.  Note that the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        {@code StandardMBean} implements this interface, so this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        case applies to a Standard MBean or MXBean created using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        the class {@code StandardMBean}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      <li>Otherwise, if the class matches the Standard MBean naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        conventions, then the MBean is a Standard MBean.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
      <li>Otherwise, it may be an MXBean.  The set of interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        implemented by the object is examined for interfaces that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
          <li>have a class name <code><em>S</em>MXBean</code> where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            <code><em>S</em></code> is any non-empty string, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            do not have an annotation {@code @MXBean(false)}; and/or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
          <li>have an annotation {@code @MXBean(true)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            or just {@code @MXBean}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        If there is exactly one such interface, or if there is one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        such interface that is a subinterface of all the others, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        the object is an MXBean.  The interface in question is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        <em>MXBean interface</em>.  In the example above, the MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        interface is {@code MemoryPoolMXBean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      <li>If none of these conditions is met, the MBean is invalid and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        the attempt to register it will generate {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        NotCompliantMBeanException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    <p>Every Java type that appears as the parameter or return type of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
      method in an MXBean interface must be <em>convertible</em> using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
      the rules below.  Additionally, parameters must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
      <em>reconstructible</em> as defined below.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    <p>An attempt to construct an MXBean that does not conform to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
      above rules will produce an exception.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   366
    <h2 id="naming-conv">Naming conventions</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    <p>The same naming conventions are applied to the methods in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
      MXBean as in a Standard MBean:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
      <li>A method <code><em>T</em> get<em>N</em>()</code>, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        <code><em>T</em></code> is a Java type (not <code>void</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        and <code><em>N</em></code> is a non-empty string, specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        that there is a readable attribute called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        <code><em>N</em></code>.  The Java type and Open type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        attribute are determined by the mapping rules below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        The method {@code final Class getClass()} inherited from {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        Object} is ignored when looking for getters.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
      <li>A method <code>boolean is<em>N</em>()</code> specifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        there is a readable attribute called <code><em>N</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        with Java type <code>boolean</code> and Open type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        <code>SimpleType.Boolean</code>.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
      <li>A method <code>void set<em>N</em>(<em>T</em> x)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        specifies that there is a writeable attribute called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        <code><em>N</em></code>.  The Java type and Open type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        attribute are determined by the mapping rules below.  (Of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        course, the name <code>x</code> of the parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        irrelevant.)</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
      <li>Every other method specifies that there is an operation with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        the same name as the method.  The Java type and Open type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return value and of each parameter are determined by the mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        rules below.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    <p>The rules for <code>get<em>N</em></code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
      <code>is<em>N</em></code> collectively define the notion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
      <em>getter</em>.  The rule for <code>set<em>N</em></code> defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
      the notion of a <em>setter</em>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    <p>It is an error for there to be two getters with the same name, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
      two setters with the same name.  If there is a getter and a setter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
      for the same name, then the type <code><em>T</em></code> in both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
      must be the same.  In this case the attribute is read/write.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
      there is only a getter or only a setter, the attribute is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
      read-only or write-only respectively.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   412
    <h2 id="mapping-rules">Type mapping rules</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    <p>An MXBean is a kind of Open MBean, as defined by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
      javax.management.openmbean} package.  This means that the types of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
      attributes, operation parameters, and operation return values must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
      all be describable using <em>Open Types</em>, that is the four
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
      standard subclasses of {@link javax.management.openmbean.OpenType}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
      MXBeans achieve this by mapping Java types into Open Types.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    <p>For every Java type <em>J</em>, the MXBean mapping is described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
      by the following information:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
      <li>The corresponding Open Type, <em>opentype(J)</em>.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        an instance of a subclass of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        javax.management.openmbean.OpenType}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
      <li>The <em>mapped</em> Java type, <em>opendata(J)</em>, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        always the same for any given <em>opentype(J)</em>.  This is a Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        class.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
      <li>How a value is converted from type <em>J</em> to type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        <em>opendata(J)</em>.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
      <li>How a value is converted from type <em>opendata(J)</em> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        type <em>J</em>, if it can be.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    <p>For example, for the Java type {@code List<String>}:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
      <li>The Open Type, <em>opentype(</em>{@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        List<String>}<em>)</em>, is {@link ArrayType}<code>(1, </code>{@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
          SimpleType#STRING}<code>)</code>, representing a 1-dimensional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
          array of <code>String</code>s.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
      <li>The mapped Java type, <em>opendata(</em>{@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        List<String>}<em>)</em>, is {@code String[]}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      <li>A {@code List<String>} can be converted to a {@code String[]}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
          using {@link List#toArray(Object[]) List.toArray(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
          String[0])}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      <li>A {@code String[]} can be converted to a {@code List<String>}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
          using {@link Arrays#asList Arrays.asList}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    <p>If no mapping rules exist to derive <em>opentype(J)</em> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
      <em>J</em>, then <em>J</em> cannot be the type of a method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
      parameter or return value in an MXBean interface.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
1153
6b88c071a015 6731410: JMXServiceURL cannot use @ConstructorProperties for compatibility reasons
emcmanus
parents: 1011
diff changeset
   457
    <p id="reconstructible-def">If there is a way to convert
6b88c071a015 6731410: JMXServiceURL cannot use @ConstructorProperties for compatibility reasons
emcmanus
parents: 1011
diff changeset
   458
      <em>opendata(J)</em> back to <em>J</em> then we say that <em>J</em> is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
      <em>reconstructible</em>.  All method parameters in an MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
      interface must be reconstructible, because when the MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
      framework is invoking a method it will need to convert those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
      parameters from <em>opendata(J)</em> to <em>J</em>.  In a proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
      generated by {@link JMX#newMXBeanProxy(MBeanServerConnection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
      ObjectName, Class) JMX.newMXBeanProxy}, it is the return values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      of the methods in the MXBean interface that must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
      reconstructible.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    <p>Null values are allowed for all Java types and Open Types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
      except primitive Java types where they are not possible.  When
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      converting from type <em>J</em> to type <em>opendata(J)</em> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      from type <em>opendata(J)</em> to type <em>J</em>, a null value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
      mapped to a null value.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1153
diff changeset
   474
    <p>The following table summarizes the type mapping rules.</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
45130
469dceb426cc 8179631: Fix Html5 errors in java.management, jdk.management, jdk.jdi and jdk.attach
ksrini
parents: 44858
diff changeset
   476
    <table class="striped">
44858
7183899b064b 8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents: 42095
diff changeset
   477
    <caption style="display:none">Type Mapping Rules</caption>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   478
      <thead>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
      <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   480
        <th scope="col">Java type <em>J</em></th>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   481
        <th scope="col"><em>opentype(J)</em></th>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   482
        <th scope="col"><em>opendata(J)</em></th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
      </tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   484
      </thead>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   485
      <tbody style="text-align:left; vertical-align:top">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   487
          <th scope="row">{@code int}, {@code boolean}, etc<br>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   488
            (the 8 primitive Java types)</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
          <td>{@code SimpleType.INTEGER},<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            {@code SimpleType.BOOLEAN}, etc</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
          <td>{@code Integer}, {@code Boolean}, etc<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            (the corresponding boxed types)</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   495
          <th scope="row">{@code Integer}, {@code ObjectName}, etc<br>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   496
            (the types covered by {@link SimpleType})</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
          <td>the corresponding {@code SimpleType}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
          <td><em>J</em>, the same type</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   501
          <th scope="row">{@code int[]} etc<br>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   502
            (a one-dimensional array with primitive element type)</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
          <td>{@code ArrayType.getPrimitiveArrayType(int[].class)} etc</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
          <td><em>J</em>, the same type</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   506
          <th scope="row"><em>E</em>{@code []}<br>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            (an array with non-primitive element type <em>E</em>;
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   508
              this includes {@code int[][]}, where <em>E</em> is {@code int[]})</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
          <td>{@code ArrayType.getArrayType(}<em>opentype(E)</em>{@code )}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
          <td><em>opendata(E)</em>{@code []}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   513
          <th scope="row">{@code List<}<em>E</em>{@code >}<br>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            {@code Set<}<em>E</em>{@code >}<br>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   515
            {@code SortedSet<}<em>E</em>{@code >} (see below)</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
          <td>same as for <em>E</em>{@code []}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
          <td>same as for <em>E</em>{@code []}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   520
          <th scope="row">An enumeration <em>E</em><br>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            (declared in Java as {@code enum }<em>E</em>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   522
            {@code {...}})</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
          <td>{@code SimpleType.STRING}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
          <td>{@code String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   527
          <th scope="row">{@code Map<}<em>K</em>,<em>V</em>{@code >}<br>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   528
            {@code SortedMap<}<em>K</em>,<em>V</em>{@code >}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
          <td>{@link TabularType}<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            (see below)</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
          <td>{@link TabularData}<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            (see below)</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   535
          <th scope="row">An MXBean interface</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
          <td>{@code SimpleType.OBJECTNAME}<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            (see below)</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
          <td>{@link ObjectName}<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            (see below)</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 45130
diff changeset
   542
          <th scope="row">Any other type</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
          <td>{@link CompositeType},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            if possible<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            (see below)</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
          <td>{@link CompositeData}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
      </tbody>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    <p>The following sections give further details of these rules.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    <h3>Mappings for primitive types</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    <p>The 8 primitive Java types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
      ({@code boolean}, {@code byte}, {@code short}, {@code int}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
      long}, {@code float}, {@code double}, {@code char}) are mapped to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
      corresponding boxed types from {@code java.lang}, namely {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
      Boolean}, {@code Byte}, etc.  The Open Type is the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
      {@code SimpleType}.  Thus, <em>opentype(</em>{@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
      long}<em>)</em> is {@code SimpleType.LONG}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
      <em>opendata(</em>{@code long}<em>)</em> is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
      java.lang.Long}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    <p>An array of primitive type such as {@code long[]} can be represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
      directly as an Open Type.  Thus, <em>openType(</em>{@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
      long[]}<em>)</em> is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
      ArrayType.getPrimitiveArrayType(long[].class)}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
      <em>opendata(</em>{@code long[]}<em>)</em> is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
      long[]}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    <p>In practice, the difference between a plain {@code int} and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
      Integer}, etc, does not show up because operations in the JMX API
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
      are always on Java objects, not primitives.  However, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
      difference <em>does</em> show up with arrays.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    <h3>Mappings for collections ({@code List<}<em>E</em>{@code >} etc)</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    <p>A {@code List<}<em>E</em>{@code >} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
      Set<}<em>E</em>{@code >}, such as {@code List<String>} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        Set<ObjectName>}, is mapped in the same way as an array of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
          same element type, such as {@code String[]} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
          ObjectName[]}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    <p>A {@code SortedSet<}<em>E</em>{@code >} is also mapped in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
      same way as an <em>E</em>{@code []}, but it is only convertible if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
      <em>E</em> is a class or interface that implements {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
      java.lang.Comparable}.  Thus, a {@code SortedSet<String>} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        {@code SortedSet<Integer>} is convertible, but a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
          SortedSet<int[]>} or {@code SortedSet<List<String>>} is not.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                conversion of a {@code SortedSet} instance will fail with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                {@code IllegalArgumentException} if it has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                non-null {@link java.util.SortedSet#comparator()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                comparator()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    <p>A {@code List<}<em>E</em>{@code >} is reconstructed as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
      {@code java.util.ArrayList<}<em>E</em>{@code >};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
      a {@code Set<}<em>E</em>{@code >} as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
      {@code java.util.HashSet<}<em>E</em>{@code >};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
      a {@code SortedSet<}<em>E</em>{@code >} as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
      {@code java.util.TreeSet<}<em>E</em>{@code >}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    <h3>Mappings for maps ({@code Map<}<em>K</em>,<em>V</em>{@code >} etc)</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    <p>A {@code Map<}<em>K</em>,<em>V</em>{@code >} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
      SortedMap<}<em>K</em>,<em>V</em>{@code >}, for example {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
      Map<String,ObjectName>}, has Open Type {@link TabularType} and is mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        to a {@link TabularData}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        The {@code TabularType} has two items called {@code key} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        {@code value}.  The Open Type of {@code key} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        <em>opentype(K)</em>, and the Open Type of {@code value} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        <em>opentype(V)</em>.  The index of the {@code TabularType} is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        single item {@code key}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    <p>For example, the {@code TabularType} for a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
      Map<String,ObjectName>} might be constructed with code like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        this:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
String typeName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    "java.util.Map&lt;java.lang.String, javax.management.ObjectName&gt;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
String[] keyValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    new String[] {"key", "value"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
OpenType[] openTypes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    new OpenType[] {SimpleType.STRING, SimpleType.OBJECTNAME};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
CompositeType rowType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    new CompositeType(typeName, typeName, keyValue, keyValue, openTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
TabularType tabularType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    new TabularType(typeName, typeName, rowType, new String[] {"key"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    <p>The {@code typeName} here is determined by the <a href="#type-names">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
      type name rules</a> detailed below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    <p>A {@code SortedMap<}<em>K</em>,<em>V</em>{@code >} is mapped in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
      same way, but it is only convertible if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
      <em>K</em> is a class or interface that implements {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
      java.lang.Comparable}.  Thus, a {@code SortedMap<String,int[]>}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        is convertible, but a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        {@code SortedMap<int[],String>} is not.  The conversion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
          {@code SortedMap} instance will fail with an {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
          IllegalArgumentException} if it has a non-null {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
          java.util.SortedMap#comparator() comparator()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    <p>A {@code Map<}<em>K</em>,<em>V</em>{@code >} is reconstructed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
      a {@code java.util.HashMap<}<em>K</em>,<em>V</em>{@code >};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
      a {@code SortedMap<}<em>K</em>,<em>V</em>{@code >} as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
      a {@code java.util.TreeMap<}<em>K</em>,<em>V</em>{@code >}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    <p>{@code TabularData} is an interface.  The concrete class that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
      used to represent a {@code Map<}<em>K</em>,<em>V</em>{@code >} as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
      Open Data is {@link TabularDataSupport},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
      or another class implementing {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
      TabularData} that serializes as {@code TabularDataSupport}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   659
    <h3 id="mxbean-map">Mappings for MXBean interfaces</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    <p>An MXBean interface, or a type referenced within an MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
      interface, can reference another MXBean interface, <em>J</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
      Then <em>opentype(J)</em> is {@code SimpleType.OBJECTNAME} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
      <em>opendata(J)</em> is {@code ObjectName}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    <p>For example, suppose you have two MXBean interfaces like this:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
public interface ProductMXBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public ModuleMXBean[] getModules();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
public interface ModuleMXBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public ProductMXBean getProduct();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    <p>The object implementing the {@code ModuleMXBean} interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
      returns from its {@code getProduct} method an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
      implementing the {@code ProductMXBean} interface.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
      {@code ModuleMXBean} object and the returned {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
      ProductMXBean} objects must both be registered as MXBeans in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
      same MBean Server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    <p>The method {@code ModuleMXBean.getProduct()} defines an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
      attribute called {@code Product}.  The Open Type for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
      attribute is {@code SimpleType.OBJECTNAME}, and the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
      {@code ObjectName} value will be the name under which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
      referenced {@code ProductMXBean} is registered in the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
      Server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    <p>If you make an MXBean proxy for a {@code ModuleMXBean} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
      call its {@code getProduct()} method, the proxy will map the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
      {@code ObjectName} back into a {@code ProductMXBean} by making
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
      another MXBean proxy.  More formally, when a proxy made with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
      {@link JMX#newMXBeanProxy(MBeanServerConnection, ObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
       Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
      JMX.newMXBeanProxy(mbeanServerConnection, objectNameX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
      interfaceX)} needs to map {@code objectNameY} back into {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
      interfaceY}, another MXBean interface, it does so with {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
      JMX.newMXBeanProxy(mbeanServerConnection, objectNameY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
      interfaceY)}.  The implementation may return a proxy that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
      previously created by a call to {@code JMX.newMXBeanProxy}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
      with the same parameters, or it may create a new proxy.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    <p>The reverse mapping is illustrated by the following change to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
      {@code ModuleMXBean} interface:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
public interface ModuleMXBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    public ProductMXBean getProduct();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    public void setProduct(ProductMXBean c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    <p>The presence of the {@code setProduct} method now means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
      {@code Product} attribute is read/write.  As before, the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
      of this attribute is an {@code ObjectName}.  When the attribute is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
      set, the {@code ObjectName} must be converted into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
      {@code ProductMXBean} object that the {@code setProduct} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
      expects.  This object will be an MXBean proxy for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
      {@code ObjectName} in the same MBean Server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    <p>If you make an MXBean proxy for a {@code ModuleMXBean} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
      call its {@code setProduct} method, the proxy will map its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
      {@code ProductMXBean} argument back into an {@code ObjectName}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
      This will only work if the argument is in fact another proxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
      for a {@code ProductMXBean} in the same {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
      MBeanServerConnection}.  The proxy can have been returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
      another proxy (like {@code ModuleMXBean.getProduct()} which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
      returns a proxy for a {@code ProductMXBean}); or it can have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
      been created by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
      JMX#newMXBeanProxy(MBeanServerConnection, ObjectName, Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
      JMX.newMXBeanProxy}; or it can have been created using {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
      java.lang.reflect.Proxy Proxy} with an invocation handler that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
      is {@link MBeanServerInvocationHandler} or a subclass.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    <p>If the same MXBean were registered under two different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
      {@code ObjectName}s, a reference to that MXBean from another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
      MXBean would be ambiguous.  Therefore, if an MXBean object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
      already registered in an MBean Server and an attempt is made to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
      register it in the same MBean Server under another name, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
      result is an {@link InstanceAlreadyExistsException}.  Registering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
      the same MBean object under more than one name is discouraged in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
      general, notably because it does not work well for MBeans that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
      {@link NotificationBroadcaster}s.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   748
    <h3 id="composite-map">Mappings for other types</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    <p>Given a Java class or interface <em>J</em> that does not match the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
      rules in the table above, the MXBean framework will attempt to map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
      it to a {@link CompositeType} as follows.  The type name of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
      {@code CompositeType} is determined by the <a href="#type-names">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
      type name rules</a> below.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    <p>The class is examined for getters using the conventions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
      <a href="#naming-conv">above</a>.  (Getters must be public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
      instance methods.)  If there are no getters, or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
      any getter has a type that is not convertible, then <em>J</em> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
      not convertible.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    <p>If there is at least one getter and every getter has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
      convertible type, then <em>opentype(J)</em> is a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
      CompositeType} with one item for every getter.  If the getter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
      <code><em>T</em> get<em>Name</em>()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    then the item in the {@code CompositeType} is called {@code name}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    and has type <em>opentype(T)</em>.  For example, if the item is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
      <code>String getOwner()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    then the item is called {@code owner} and has Open Type {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    SimpleType.STRING}.  If the getter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
      <code>boolean is<em>Name</em>()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    then the item in the {@code CompositeType} is called {@code name}
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 18805
diff changeset
   785
    and has type {@code SimpleType.BOOLEAN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    <p>Notice that the first character (or code point) is converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
      lower case.  This follows the Java Beans convention, which for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
      historical reasons is different from the Standard MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
      convention.  In a Standard MBean or MXBean interface, a method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
      {@code getOwner} defines an attribute called {@code Owner}, while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
      in a Java Bean or mapped {@code CompositeType}, a method {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
      getOwner} defines a property or item called {@code owner}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    <p>If two methods produce the same item name (for example, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
      getOwner} and {@code isOwner}, or {@code getOwner} and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
      getowner}) then the type is not convertible.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    <p>When the Open Type is {@code CompositeType}, the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
      mapped Java type (<em>opendata(J)</em>) is {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
      CompositeData}.  The mapping from an instance of <em>J</em> to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
      {@code CompositeData} corresponding to the {@code CompositeType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
      just described is done as follows.  First, if <em>J</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
      implements the interface {@link CompositeDataView}, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
      interface's {@link CompositeDataView#toCompositeData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
      toCompositeData} method is called to do the conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
      Otherwise, the {@code CompositeData} is constructed by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
      the getter for each item and converting it to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
      Open Data type.  Thus, a getter such as</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
      {@code List<String> getNames()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    <p>will have been mapped to an item with name "{@code names}" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
      Open Type {@code ArrayType(1, SimpleType.STRING)}.  The conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
      to {@code CompositeData} will call {@code getNames()} and convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
      the resultant {@code List<String>} into a {@code String[]} for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        item "{@code names}".</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    <p>{@code CompositeData} is an interface.  The concrete class that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
      used to represent a type as Open Data is {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
      CompositeDataSupport}, or another class implementing {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
      CompositeData} that serializes as {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
      CompositeDataSupport}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    <h4>Reconstructing an instance of Java type <em>J</em> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
      a {@code CompositeData}</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    <p>If <em>opendata(J)</em> is {@code CompositeData} for a Java type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
      <em>J</em>, then either an instance of <em>J</em> can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
      reconstructed from a {@code CompositeData}, or <em>J</em> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
      reconstructible.  If any item in the {@code CompositeData} is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
      reconstructible, then <em>J</em> is not reconstructible either.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    <p>For any given <em>J</em>, the following rules are consulted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
      determine how to reconstruct instances of <em>J</em> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
      {@code CompositeData}.  The first applicable rule in the list is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
      the one that will be used.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
      <li><p>If <em>J</em> has a method<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        {@code public static }<em>J </em>{@code from(CompositeData cd)}<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        then that method is called to reconstruct an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        <em>J</em>.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
      <li><p>Otherwise, if <em>J</em> has at least one public
33499
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   850
        constructor with either {@link javax.management.ConstructorParameters
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   851
        &#64;javax.management.ConstructorParameters} or
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   852
        {@code @java.beans.ConstructoProperties} annotation, then one of those
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   853
        constructors (not necessarily always the same one) will be called to
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   854
        reconstruct an instance of <em>J</em>.
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   855
        If a constructor is annotated with both
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   856
        {@code @javax.management.ConstructorParameters} and
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   857
        {@code @java.beans.ConstructorProperties},
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   858
        {@code @javax.management.ConstructorParameters} will be used and
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   859
        {@code @java.beans.ConstructorProperties} will be ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        Every such annotation must list as many strings as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        constructor has parameters; each string must name a property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        corresponding to a getter of <em>J</em>; and the type of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        getter must be the same as the corresponding constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        parameter.  It is not an error for there to be getters that
33499
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   865
        are not mentioned in the {@code @ConstructorParameters} or
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   866
        {@code @ConstructorProperties} annotations (these may correspond to
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   867
        information that is not needed to reconstruct the object).</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        <p>An instance of <em>J</em> is reconstructed by calling a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        constructor with the appropriate reconstructed items from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        {@code CompositeData}.  The constructor to be called will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        determined at runtime based on the items actually present in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        the {@code CompositeData}, given that this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        CompositeData} might come from an earlier version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        <em>J</em> where not all the items were present.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        constructor is <em>applicable</em> if all the properties named
33499
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   877
        in its {@code @ConstructorParameters} or {@code @ConstructorProperties}
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   878
        annotation are present as items in the {@code CompositeData}.
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   879
        If no constructor is applicable, then the attempt to reconstruct
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   880
        <em>J</em> fails.</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        <p>For any possible combination of properties, it must be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        case that either (a) there are no applicable constructors, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        (b) there is exactly one applicable constructor, or (c) one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        the applicable constructors names a proper superset of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        properties named by each other applicable constructor.  (In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        other words, there should never be ambiguity over which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        constructor to choose.)  If this condition is not true, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        <em>J</em> is not reconstructible.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
      <li><p>Otherwise, if <em>J</em> has a public no-arg constructor, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        for every getter in <em>J</em> with type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        <em>T</em> and name <em>N</em> there is a corresponding setter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        with the same name and type, then an instance of <em>J</em> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        constructed with the no-arg constructor and the setters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        called with the reconstructed items from the {@code CompositeData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        to restore the values.  For example, if there is a method<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        {@code public List<String> getNames()}<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
          then there must also be a method<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
          {@code public void setNames(List<String> names)}<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            for this rule to apply.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        <p>If the {@code CompositeData} came from an earlier version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        <em>J</em>, some items might not be present.  In this case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        the corresponding setters will not be called.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
      <li><p>Otherwise, if <em>J</em> is an interface that has no methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        other than getters, an instance of <em>J</em> is constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        using a {@link java.lang.reflect.Proxy} with a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        CompositeDataInvocationHandler} backed by the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        CompositeData} being converted.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
      <li><p>Otherwise, <em>J</em> is not reconstructible.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
42095
a0f1353b4c06 8167294: MXBean javadoc should be updated to take modules into account
vtewari
parents: 33499
diff changeset
   916
    <p>Rule 2 is not applicable when {@code java.beans.ConstructorProperties}
a0f1353b4c06 8167294: MXBean javadoc should be updated to take modules into account
vtewari
parents: 33499
diff changeset
   917
    is not visible (e.g. when the java.desktop module is not readable or when
a0f1353b4c06 8167294: MXBean javadoc should be updated to take modules into account
vtewari
parents: 33499
diff changeset
   918
    the runtime image does not contain the java.desktop module). When
a0f1353b4c06 8167294: MXBean javadoc should be updated to take modules into account
vtewari
parents: 33499
diff changeset
   919
    targeting a runtime that does not include the {@code java.beans} package,
a0f1353b4c06 8167294: MXBean javadoc should be updated to take modules into account
vtewari
parents: 33499
diff changeset
   920
    and where there is a mismatch between the compile-time and runtime
a0f1353b4c06 8167294: MXBean javadoc should be updated to take modules into account
vtewari
parents: 33499
diff changeset
   921
    environment whereby <em>J</em> is compiled with a public constructor
a0f1353b4c06 8167294: MXBean javadoc should be updated to take modules into account
vtewari
parents: 33499
diff changeset
   922
    and the {@code ConstructorProperties} annotation, then <em>J</em> is
a0f1353b4c06 8167294: MXBean javadoc should be updated to take modules into account
vtewari
parents: 33499
diff changeset
   923
    not reconstructible unless another rule applies.</p>
15300
ffec14ad2f94 8006524: JSR-3: Allows java.beans to be optional
alanb
parents: 5506
diff changeset
   924
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    <p>Here are examples showing different ways to code a type {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
      NamedNumber} that consists of an {@code int} and a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
      String}.  In each case, the {@code CompositeType} looks like this:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
      <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
{@link CompositeType}(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    "NamedNumber",                      // typeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    "NamedNumber",                      // description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    new String[] {"number", "name"},    // itemNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    new String[] {"number", "name"},    // itemDescriptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    new OpenType[] {SimpleType.INTEGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                    SimpleType.STRING}  // itemTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
      </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
      <li>Static {@code from} method:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
          <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
public class NamedNumber {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    public int getNumber() {return number;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    public String getName() {return name;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    private NamedNumber(int number, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        this.number = number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    <b>public static NamedNumber from(CompositeData cd)</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        return new NamedNumber((Integer) cd.get("number"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                               (String) cd.get("name"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    private final int number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    private final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
          </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
      </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
33499
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   965
      <li>Public constructor with <code>&#64;ConstructorParameters</code> annotation:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
          <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
public class NamedNumber {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    public int getNumber() {return number;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    public String getName() {return name;}
33499
d4f084ec39eb 8139727: Define ConstructorParameters annotation type for MXBeans
jbachorik
parents: 33316
diff changeset
   972
    <b>&#64;ConstructorParameters({"number", "name"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    public NamedNumber(int number, String name)</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        this.number = number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    private final int number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    private final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
          </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
      </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
      <li>Setter for every getter:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
          <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
public class NamedNumber {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    public int getNumber() {return number;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    public void <b>setNumber</b>(int number) {this.number = number;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    public String getName() {return name;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    public void <b>setName</b>(String name) {this.name = name;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    <b>public NamedNumber()</b> {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    private int number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
          </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
      </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
      <li>Interface with only getters:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
          <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
public interface NamedNumber {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    public int getNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    public String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
          </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
      </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    <p>It is usually better for classes that simply represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
      collection of data to be <em>immutable</em>.  An instance of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
      immutable class cannot be changed after it has been constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
      Notice that {@code CompositeData} itself is immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
      Immutability has many advantages, notably with regard to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
      thread-safety and security.  So the approach using setters should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
      generally be avoided if possible.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    <h3>Recursive types</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    <p>Recursive (self-referential) types cannot be used in MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
      interfaces.  This is a consequence of the immutability of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
      CompositeType}.  For example, the following type could not be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
      type of an attribute, because it refers to itself:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
public interface <b>Node</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    public String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    public int getPriority();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    public <b>Node</b> getNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    <p>It is always possible to rewrite recursive types like this so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
      they are no longer recursive.  Doing so may require introducing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
      new types.  For example:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
public interface <b>NodeList</b> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    public List&lt;Node&gt; getNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
public interface Node {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    public String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    public int getPriority();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    <h3>MBeanInfo contents for an MXBean</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    <p>An MXBean is a type of Open MBean.  However, for compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
      reasons, its {@link MBeanInfo} is not an {@link OpenMBeanInfo}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
      In particular, when the type of an attribute, parameter, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
      operation return value is a primitive type such as {@code int},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
      or is {@code void} (for a return type), then the attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
      parameter, or operation will be represented respectively by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
      {@link MBeanAttributeInfo}, {@link MBeanParameterInfo}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
      {@link MBeanOperationInfo} whose {@code getType()} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
      getReturnType()} returns the primitive name ("{@code int}" etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
      This is so even though the mapping rules above specify that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
      <em>opendata</em> mapping is the wrapped type ({@code Integer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
      etc).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    <p>The array of public constructors returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
      MBeanInfo#getConstructors()} for an MXBean that is directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
      registered in the MBean Server will contain all of the public
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
      constructors of that MXBean.  If the class of the MXBean is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
      public then its constructors are not considered public either.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
      The list returned for an MXBean that is constructed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
      {@link StandardMBean} class is derived in the same way as for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
      Standard MBeans.  Regardless of how the MXBean was constructed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
      its constructor parameters are not subject to MXBean mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
      rules and do not have a corresponding {@code OpenType}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    <p>The array of notification types returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
      MBeanInfo#getNotifications()} for an MXBean that is directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
      registered in the MBean Server will be empty if the MXBean does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
      not implement the {@link NotificationBroadcaster} interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
      Otherwise, it will be the result of calling {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
      NotificationBroadcaster#getNotificationInfo()} at the time the MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
      was registered.  Even if the result of this method changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
      subsequently, the result of {@code MBeanInfo.getNotifications()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
      will not.  The list returned for an MXBean that is constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
      using the {@link StandardMBean} or {@link StandardEmitterMBean}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
      class is derived in the same way as for Standard MBeans.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    <p>The {@link Descriptor} for all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
      {@code MBeanAttributeInfo}, {@code MBeanParameterInfo}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
      {@code MBeanOperationInfo} objects contained in the {@code MBeanInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
      will have a field {@code openType} whose value is the {@link OpenType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
      specified by the mapping rules above.  So even when {@code getType()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
      is "{@code int}", {@code getDescriptor().getField("openType")} will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
      be {@link SimpleType#INTEGER}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    <p>The {@code Descriptor} for each of these objects will also have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
      field {@code originalType} that is a string representing the Java type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
      that appeared in the MXBean interface.  The format of this string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
      is described in the section <a href="#type-names">Type Names</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
      below.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    <p>The {@code Descriptor} for the {@code MBeanInfo} will have a field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
      {@code mxbean} whose value is the string "{@code true}".</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
  1109
    <h3 id="type-names">Type Names</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    <p>Sometimes the unmapped type <em>T</em> of a method parameter or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    return value in an MXBean must be represented as a string.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    <em>T</em> is a non-generic type, this string is the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    returned by {@link Class#getName()}.  Otherwise it is the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    <em>genericstring(T)</em>, defined as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
      <li>If <em>T</em> is a non-generic non-array type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
      <em>genericstring(T)</em> is the value returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
      Class#getName()}, for example {@code "int"} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
      "java.lang.String"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
      <li>If <em>T</em> is an array <em>E[]</em>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
      <em>genericstring(T)</em> is <em>genericstring(E)</em> followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
      by {@code "[]"}.  For example, <em>genericstring({@code int[]})</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
      is {@code "int[]"}, and <em>genericstring({@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
      List<String>[][]})</em> is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
      "java.util.List<java.lang.String>[][]"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    <li>Otherwise, <em>T</em> is a parameterized type such as {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    List<String>} and <em>genericstring(T)</em> consists of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    following: the fully-qualified name of the parameterized type as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    returned by {@code Class.getName()}; a left angle bracket ({@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    "<"}); <em>genericstring(A)</em> where <em>A</em> is the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    type parameter; if there is a second type parameter <em>B</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    then {@code ", "} (a comma and a single space) followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    <em>genericstring(B)</em>; a right angle bracket ({@code ">"}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    <p>Note that if a method returns {@code int[]}, this will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
      represented by the string {@code "[I"} returned by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
      Class.getName()}, but if a method returns {@code List<int[]>},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
      this will be represented by the string {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
      "java.util.List<int[]>"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    <h3>Exceptions</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    <p>A problem with mapping <em>from</em> Java types <em>to</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
      Open types is signaled with an {@link OpenDataException}.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
      can happen when an MXBean interface is being analyzed, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
      example if it references a type like {@link java.util.Random
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
      java.util.Random} that has no getters.  Or it can happen when an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
      instance is being converted (a return value from a method in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
      MXBean or a parameter to a method in an MXBean proxy), for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
      example when converting from {@code SortedSet<String>} to {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
      String[]} if the {@code SortedSet} has a non-null {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
      Comparator}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    <p>A problem with mapping <em>to</em> Java types <em>from</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
      Open types is signaled with an {@link InvalidObjectException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
      This can happen when an MXBean interface is being analyzed, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
      example if it references a type that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
      <em>reconstructible</em> according to the rules above, in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
      context where a reconstructible type is required.  Or it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
      happen when an instance is being converted (a parameter to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
      method in an MXBean or a return value from a method in an MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
      proxy), for example from a String to an Enum if there is no Enum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
      constant with that name.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    <p>Depending on the context, the {@code OpenDataException} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
      {@code InvalidObjectException} may be wrapped in another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
      exception such as {@link RuntimeMBeanException} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
      UndeclaredThrowableException}.  For every thrown exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
      the condition <em>C</em> will be true: "<em>e</em> is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
      OpenDataException} or {@code InvalidObjectException} (as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
      appropriate), or <em>C</em> is true of <em>e</em>.{@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
      Throwable#getCause() getCause()}".</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
   @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
@Documented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
@Retention(RetentionPolicy.RUNTIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
@Target(ElementType.TYPE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
public @interface MXBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
       True if the annotated interface is an MXBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
       @return true if the annotated interface is an MXBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    boolean value() default true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
}