0N/A/*
2362N/A * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.management;
0N/A
0N/A
0N/A/**
699N/A * Represents a notification emitted by the MBean Server through the MBeanServerDelegate MBean.
0N/A * The MBean Server emits the following types of notifications: MBean registration, MBean
699N/A * unregistration.
0N/A * <P>
699N/A * To receive MBeanServerNotifications, you need to register a listener with
699N/A * the {@link MBeanServerDelegate MBeanServerDelegate} MBean
699N/A * that represents the MBeanServer. The ObjectName of the MBeanServerDelegate is
699N/A * {@link MBeanServerDelegate#DELEGATE_NAME}, which is
0N/A * <CODE>JMImplementation:type=MBeanServerDelegate</CODE>.
0N/A *
699N/A * <p>The following code prints a message every time an MBean is registered
699N/A * or unregistered in the MBean Server {@code mbeanServer}:</p>
699N/A *
699N/A * <pre>
699N/A * private static final NotificationListener printListener = new NotificationListener() {
699N/A * public void handleNotification(Notification n, Object handback) {
699N/A * if (!(n instanceof MBeanServerNotification)) {
699N/A * System.out.println("Ignored notification of class " + n.getClass().getName());
699N/A * return;
699N/A * }
699N/A * MBeanServerNotification mbsn = (MBeanServerNotification) n;
699N/A * String what;
699N/A * if (n.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
699N/A * what = "MBean registered";
699N/A * else if (n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION))
699N/A * what = "MBean unregistered";
699N/A * else
699N/A * what = "Unknown type " + n.getType();
699N/A * System.out.println("Received MBean Server notification: " + what + ": " +
699N/A * mbsn.getMBeanName());
729N/A * }
699N/A * };
699N/A *
699N/A * ...
699N/A * mbeanServer.addNotificationListener(
699N/A * MBeanServerDelegate.DELEGATE_NAME, printListener, null, null);
699N/A * </pre>
1790N/A *
729N/A * <p id="group">
729N/A * An MBean which is not an {@link MBeanServerDelegate} may also emit
1790N/A * MBeanServerNotifications. In particular, there is a convention for
1790N/A * MBeans to emit an MBeanServerNotification for a group of MBeans.</p>
1790N/A *
1790N/A * <p>An MBeanServerNotification emitted to denote the registration or
729N/A * unregistration of a group of MBeans has the following characteristics:
729N/A * <ul><li>Its {@linkplain Notification#getType() notification type} is
729N/A * {@code "JMX.mbean.registered.group"} or
729N/A * {@code "JMX.mbean.unregistered.group"}, which can also be written {@link
729N/A * MBeanServerNotification#REGISTRATION_NOTIFICATION}{@code + ".group"} or
729N/A * {@link
729N/A * MBeanServerNotification#UNREGISTRATION_NOTIFICATION}{@code + ".group"}.
729N/A * </li>
729N/A * <li>Its {@linkplain #getMBeanName() MBean name} is an ObjectName pattern
729N/A * that selects the set (or a superset) of the MBeans being registered
729N/A * or unregistered</li>
729N/A * <li>Its {@linkplain Notification#getUserData() user data} can optionally
729N/A * be set to an array of ObjectNames containing the names of all MBeans
729N/A * being registered or unregistered.</li>
729N/A * </ul>
729N/A * </p>
729N/A * <p>
729N/A * MBeans which emit these group registration/unregistration notifications will
729N/A * declare them in their {@link MBeanInfo#getNotifications()
729N/A * MBeanNotificationInfo}.
729N/A * </p>
700N/A *
0N/A * @since 1.5
0N/A */
468N/Apublic class MBeanServerNotification extends Notification {
0N/A
0N/A
468N/A /* Serial version */
468N/A private static final long serialVersionUID = 2876477500475969677L;
468N/A /**
468N/A * Notification type denoting that an MBean has been registered.
468N/A * Value is "JMX.mbean.registered".
468N/A */
468N/A public static final String REGISTRATION_NOTIFICATION =
468N/A "JMX.mbean.registered";
468N/A /**
468N/A * Notification type denoting that an MBean has been unregistered.
468N/A * Value is "JMX.mbean.unregistered".
468N/A */
468N/A public static final String UNREGISTRATION_NOTIFICATION =
468N/A "JMX.mbean.unregistered";
468N/A /**
468N/A * @serial The object names of the MBeans concerned by this notification
468N/A */
468N/A private final ObjectName objectName;
0N/A
468N/A /**
468N/A * Creates an MBeanServerNotification object specifying object names of
468N/A * the MBeans that caused the notification and the specified notification
468N/A * type.
468N/A *
468N/A * @param type A string denoting the type of the
468N/A * notification. Set it to one these values: {@link
468N/A * #REGISTRATION_NOTIFICATION}, {@link
468N/A * #UNREGISTRATION_NOTIFICATION}.
468N/A * @param source The MBeanServerNotification object responsible
468N/A * for forwarding MBean server notification.
468N/A * @param sequenceNumber A sequence number that can be used to order
468N/A * received notifications.
468N/A * @param objectName The object name of the MBean that caused the
468N/A * notification.
468N/A *
468N/A */
468N/A public MBeanServerNotification(String type, Object source,
468N/A long sequenceNumber, ObjectName objectName) {
468N/A super(type, source, sequenceNumber);
468N/A this.objectName = objectName;
468N/A }
468N/A
468N/A /**
468N/A * Returns the object name of the MBean that caused the notification.
468N/A *
468N/A * @return the object name of the MBean that caused the notification.
468N/A */
468N/A public ObjectName getMBeanName() {
468N/A return objectName;
468N/A }
468N/A
468N/A @Override
468N/A public String toString() {
468N/A return super.toString() + "[mbeanName=" + objectName + "]";
468N/A
468N/A }
0N/A
0N/A }