jdk/src/share/classes/javax/management/MBeanServerDelegate.java
author dfuchs
Thu, 04 Sep 2008 14:46:36 +0200
changeset 1156 bbc2d15aaf7a
parent 2 90ce3da70b43
child 1225 6ef6227d36eb
permissions -rw-r--r--
5072476: RFE: support cascaded (federated) MBean Servers 6299231: Add support for named MBean Servers Summary: New javax.management.namespace package. 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
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    28
import com.sun.jmx.defaults.JmxProperties;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.defaults.ServiceName;
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    30
import com.sun.jmx.mbeanserver.Util;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Represents  the MBean server from the management point of view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * The MBeanServerDelegate MBean emits the MBeanServerNotifications when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * an MBean is registered/unregistered in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class MBeanServerDelegate implements MBeanServerDelegateMBean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                                            NotificationEmitter   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /** The MBean server agent identification.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private String mbeanServerId ;
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    44
    private String mbeanServerName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /** The NotificationBroadcasterSupport object that sends the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        notifications */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private final NotificationBroadcasterSupport broadcaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static long oldStamp = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final long stamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private long sequenceNumber = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final MBeanNotificationInfo[] notifsInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        final String[] types  = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            MBeanServerNotification.REGISTRATION_NOTIFICATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        notifsInfo = new MBeanNotificationInfo[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        notifsInfo[0] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            new MBeanNotificationInfo(types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                    "javax.management.MBeanServerNotification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                    "Notifications sent by the MBeanServerDelegate MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Create a MBeanServerDelegate object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public MBeanServerDelegate () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        stamp = getStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        broadcaster = new NotificationBroadcasterSupport() ;
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    74
        mbeanServerName=null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Returns the MBean server agent identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @return the identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public synchronized String getMBeanServerId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (mbeanServerId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            String localHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                localHost = java.net.InetAddress.getLocalHost().getHostName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            } catch (java.net.UnknownHostException e) {
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    89
                JmxProperties.MISC_LOGGER.finest("Can't get local host name, " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    90
                        "using \"localhost\" instead. Cause is: "+e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                localHost = "localhost";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    93
            mbeanServerId =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    94
                    Util.insertMBeanServerName(localHost + "_" + stamp,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
    95
                    mbeanServerName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return mbeanServerId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   101
     * The name of the MBeanServer.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   102
     * @return The name of the MBeanServer, or {@value
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   103
     * javax.management.MBeanServerFactory#DEFAULT_MBEANSERVER_NAME} if no
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   104
     * name was specified.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   105
     *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   106
     * @since 1.7
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   107
     * @see #setMBeanServerName
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   108
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   109
    public synchronized String getMBeanServerName() {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   110
        if (Util.isMBeanServerNameUndefined(mbeanServerName))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   111
            return MBeanServerFactory.DEFAULT_MBEANSERVER_NAME;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   112
        return mbeanServerName;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   113
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   114
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   115
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   116
     * Sets the name of the MBeanServer. The name will be embedded into the
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   117
     * {@link #getMBeanServerId MBeanServerId} using the following format:<br>
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   118
     * {@code mbeanServerId: <mbeanServerId>;mbeanServerName=<mbeanServerName>}
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   119
     * <p>The characters {@code ':'} (colon), {@code ';'} (semicolon ),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   120
     * {@code '*'} (star) and {@code '?'} (question mark) are not legal in an
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   121
     * MBean Server name.</p>
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   122
     * <p>For instance, if the {@code mbeanServerName} provided is
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   123
     * {@code "com.mycompany.myapp.server1"}, and the original
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   124
     * {@code MBeanServerId} was {@code "myhost_1213353064145"},
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   125
     * then {@code mbeanServerName} will be
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   126
     * embedded in the {@code MBeanServerId} - and the new value of the
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   127
     * {@code MBeanServerId} will be:
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   128
     * </p>
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   129
     * <pre>
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   130
     *       "myhost_1213353064145;mbeanServerName=com.mycompany.myapp.server1"
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   131
     * </pre>
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   132
     * <p>Note: The {@code mbeanServerName} is usually set by the
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   133
     *   {@code MBeanServerFactory}. It is set only once, before the
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   134
     *   MBean Server is returned by the factory. Once the MBean Server name is
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   135
     *   set, it is not possible to change it.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   136
     * </p>
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   137
     * @param mbeanServerName The MBeanServer name.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   138
     * @throws IllegalArgumentException if the MBeanServerName is already set
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   139
     *         to a different value, or if the provided name contains
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   140
     *         illegal characters, or if the provided name is {@code ""}
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   141
     *         (the empty string) or "-" (dash).
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   142
     * @throws UnsupportedOperationException if this object is of a legacy
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   143
     *         subclass of MBeanServerDelegate which overrides {@link
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   144
     *         #getMBeanServerId()}
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   145
     *         in a way that doesn't support setting an MBeanServer name.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   146
     * @see MBeanServerFactory#getMBeanServerName
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   147
     * @since 1.7
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   148
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   149
    public synchronized void setMBeanServerName(String mbeanServerName) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   150
        // Sets the name on the delegate. For complex backward
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   151
        // compatibility reasons it is not possible to give the
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   152
        // name to the MBeanServerDelegate constructor.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   153
        //
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   154
        // The method setMBeanServerName() will call getMBeanServerId()
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   155
        // to check that the name is accurately set in the MBeanServerId.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   156
        // If not (which could happen if a custom MBeanServerDelegate
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   157
        // implementation overrides getMBeanServerId() and was not updated
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   158
        // with respect to JMX 2.0 spec), this method will throw an
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   159
        // IllegalStateException...
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   160
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   161
        // will fail if mbeanServerName is illegal
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   162
        final String name = Util.checkServerName(mbeanServerName);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   163
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   164
        // can only set mbeanServerDelegate once.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   165
        if (this.mbeanServerName != null && !this.mbeanServerName.equals(name))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   166
            throw new IllegalArgumentException(
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   167
                    "MBeanServerName already set to a different value");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   168
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   169
        this.mbeanServerName = name;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   170
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   171
        // will fail if mbeanServerId already has a different mbeanServerName
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   172
        mbeanServerId =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   173
           Util.insertMBeanServerName(getMBeanServerId(),name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   174
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   175
        // check that we don't have a subclass which overrides
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   176
        // getMBeanServerId() without setting mbeanServerName
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   177
        if (!name.equals(
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   178
                Util.extractMBeanServerName(getMBeanServerId())))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   179
            throw new UnsupportedOperationException(
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   180
                    "Can't set MBeanServerName in MBeanServerId - " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   181
                    "unsupported by "+this.getClass().getName()+"?");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   182
        // OK: at this point we know that we have correctly set mbeanServerName.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   183
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   184
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   185
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Returns the full name of the JMX specification implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * by this product.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return the specification name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public String getSpecificationName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return ServiceName.JMX_SPEC_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Returns the version of the JMX specification implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * by this product.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return the specification version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public String getSpecificationVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return ServiceName.JMX_SPEC_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Returns the vendor of the JMX specification implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * by this product.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @return the specification vendor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public String getSpecificationVendor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return ServiceName.JMX_SPEC_VENDOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns the JMX implementation name (the name of this product).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @return the implementation name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public String getImplementationName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return ServiceName.JMX_IMPL_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Returns the JMX implementation version (the version of this product).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return the implementation version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public String getImplementationVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return System.getProperty("java.runtime.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Returns the JMX implementation vendor (the vendor of this product).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return the implementation vendor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public String getImplementationVendor()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return ServiceName.JMX_IMPL_VENDOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    // From NotificationEmitter extends NotificationBroacaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public MBeanNotificationInfo[] getNotificationInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        final int len = MBeanServerDelegate.notifsInfo.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        final MBeanNotificationInfo[] infos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        new MBeanNotificationInfo[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        System.arraycopy(MBeanServerDelegate.notifsInfo,0,infos,0,len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return infos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    // From NotificationEmitter extends NotificationBroacaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        void addNotificationListener(NotificationListener listener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                     NotificationFilter filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                     Object handback)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        broadcaster.addNotificationListener(listener,filter,handback) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    // From NotificationEmitter extends NotificationBroacaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        void removeNotificationListener(NotificationListener listener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                        NotificationFilter filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                        Object handback)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        throws ListenerNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        broadcaster.removeNotificationListener(listener,filter,handback) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    // From NotificationEmitter extends NotificationBroacaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        void removeNotificationListener(NotificationListener listener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        throws ListenerNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        broadcaster.removeNotificationListener(listener) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Enables the MBean server to send a notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * If the passed <var>notification</var> has a sequence number lesser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * or equal to 0, then replace it with the delegate's own sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param notification The notification to send.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void sendNotification(Notification notification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (notification.getSequenceNumber() < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                notification.setSequenceNumber(this.sequenceNumber++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        broadcaster.sendNotification(notification);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Defines the default ObjectName of the MBeanServerDelegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   306
    public static final ObjectName DELEGATE_NAME =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 2
diff changeset
   307
            Util.newObjectName("JMImplementation:type=MBeanServerDelegate");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /* Return a timestamp that is monotonically increasing even if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
       System.currentTimeMillis() isn't (for example, if you call this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
       constructor more than once in the same millisecond, or if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
       clock always returns the same value).  This means that the ids
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
       for a given JVM will always be distinact, though there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
       such guarantee for two different JVMs.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private static synchronized long getStamp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        long s = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (oldStamp >= s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            s = oldStamp + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        oldStamp = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
}