jdk/src/share/classes/javax/management/MBeanNotificationInfo.java
author sjiang
Thu, 31 Jul 2008 15:31:13 +0200
changeset 1004 5ba8217eb504
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
5108776: Add reliable event handling to the JMX API 6218920: API bug - impossible to delete last MBeanServerForwarder on a connector Reviewed-by: emcmanus
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <p>The <CODE>MBeanNotificationInfo</CODE> class is used to describe the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * characteristics of the different notification instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * emitted by an MBean, for a given Java class of notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * If an MBean emits notifications that can be instances of different Java classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * then the metadata for that MBean should provide an <CODE>MBeanNotificationInfo</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * object for each of these notification Java classes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>Instances of this class are immutable.  Subclasses may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * mutable but this is not recommended.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>This class extends <CODE>javax.management.MBeanFeatureInfo</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and thus provides <CODE>name</CODE> and <CODE>description</CODE> fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The <CODE>name</CODE> field should be the fully qualified Java class name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the notification objects described by this class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>The <CODE>getNotifTypes</CODE> method returns an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * strings containing the notification types that the MBean may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * emit. The notification type is a dot-notation string which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * describes what the emitted notification is about, not the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * class of the notification.  A single generic notification class can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * be used to send notifications of several types.  All of these types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * are returned in the string array result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <CODE>getNotifTypes</CODE> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class MBeanNotificationInfo extends MBeanFeatureInfo implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static final long serialVersionUID = -3888371564530107064L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final String[] NO_TYPES = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static final MBeanNotificationInfo[] NO_NOTIFICATIONS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        new MBeanNotificationInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @serial The different types of the notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private final String[] types;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /** @see MBeanInfo#arrayGettersSafe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private final transient boolean arrayGettersSafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Constructs an <CODE>MBeanNotificationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param notifTypes The array of strings (in dot notation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * containing the notification types that the MBean may emit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * This may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param name The fully qualified Java class name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * described notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param description A human readable description of the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public MBeanNotificationInfo(String[] notifTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                 String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                 String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        this(notifTypes, name, description, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Constructs an <CODE>MBeanNotificationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param notifTypes The array of strings (in dot notation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * containing the notification types that the MBean may emit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * This may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param name The fully qualified Java class name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * described notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param description A human readable description of the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param descriptor The descriptor for the notifications.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public MBeanNotificationInfo(String[] notifTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                 String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                 String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                 Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        super(name, description, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        /* We do not validate the notifTypes, since the spec just says
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
           they are dot-separated, not that they must look like Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
           classes.  E.g. the spec doesn't forbid "sun.prob.25" as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
           notifType, though it doesn't explicitly allow it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
           either.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (notifTypes == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            notifTypes = NO_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.types = notifTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.arrayGettersSafe =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            MBeanInfo.arrayGettersSafe(this.getClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                       MBeanNotificationInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Returns a shallow clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * The clone is obtained by simply calling <tt>super.clone()</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * thus calling the default native shallow cloning mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * implemented by <tt>Object.clone()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * No deeper cloning of any internal field is made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     public Object clone () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
             return super.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
             // should not happen as this class is cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns the array of strings (in dot notation) containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * notification types that the MBean may emit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @return the array of strings.  Changing the returned array has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * effect on this MBeanNotificationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public String[] getNotifTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (types.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return NO_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return types.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private String[] fastGetNotifTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (arrayGettersSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return types;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return getNotifTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            getClass().getName() + "[" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            "description=" + getDescription() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            "name=" + getName() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            "notifTypes=" + Arrays.asList(fastGetNotifTypes()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            "descriptor=" + getDescriptor() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Compare this MBeanNotificationInfo to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param o the object to compare to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @return true if and only if <code>o</code> is an MBeanNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * such that its {@link #getName()}, {@link #getDescription()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * {@link #getDescriptor()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * and {@link #getNotifTypes()} values are equal (not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * identical) to those of this MBeanNotificationInfo.  Two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * notification type arrays are equal if their corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * elements are equal.  They are not equal if they have the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * elements but in a different order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (o == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (!(o instanceof MBeanNotificationInfo))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        MBeanNotificationInfo p = (MBeanNotificationInfo) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return (p.getName().equals(getName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                p.getDescription().equals(getDescription()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                p.getDescriptor().equals(getDescriptor()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                Arrays.equals(p.fastGetNotifTypes(), fastGetNotifTypes()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        int hash = getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        for (int i = 0; i < types.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            hash ^= types[i].hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
}