J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package javax.management; |
| 27 | |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * Provides definitions of the attribute change notifications sent by MBeans. |
| 32 | * <P> |
| 33 | * It's up to the MBean owning the attribute of interest to create and send |
| 34 | * attribute change notifications when the attribute change occurs. |
| 35 | * So the <CODE>NotificationBroadcaster</CODE> interface has to be implemented |
| 36 | * by any MBean for which an attribute change is of interest. |
| 37 | * <P> |
| 38 | * Example: |
| 39 | * If an MBean called <CODE>myMbean</CODE> needs to notify registered listeners |
| 40 | * when its attribute: |
| 41 | * <BLOCKQUOTE><CODE> |
| 42 | * String myString |
| 43 | * </CODE></BLOCKQUOTE> |
| 44 | * is modified, <CODE>myMbean</CODE> creates and emits the following notification: |
| 45 | * <BLOCKQUOTE><CODE> |
| 46 | * new AttributeChangeNotification(myMbean, sequenceNumber, timeStamp, msg, |
| 47 | * "myString", "String", oldValue, newValue); |
| 48 | * </CODE></BLOCKQUOTE> |
| 49 | * |
| 50 | * @since 1.5 |
| 51 | */ |
| 52 | public class AttributeChangeNotification extends javax.management.Notification { |
| 53 | |
| 54 | /* Serial version */ |
| 55 | private static final long serialVersionUID = 535176054565814134L; |
| 56 | |
| 57 | /** |
| 58 | * Notification type which indicates that the observed MBean attribute value has changed. |
| 59 | * <BR>The value of this type string is <CODE>jmx.attribute.change</CODE>. |
| 60 | */ |
| 61 | public static final String ATTRIBUTE_CHANGE = "jmx.attribute.change"; |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * @serial The MBean attribute name. |
| 66 | */ |
| 67 | private String attributeName = null; |
| 68 | |
| 69 | /** |
| 70 | * @serial The MBean attribute type. |
| 71 | */ |
| 72 | private String attributeType = null; |
| 73 | |
| 74 | /** |
| 75 | * @serial The MBean attribute old value. |
| 76 | */ |
| 77 | private Object oldValue = null; |
| 78 | |
| 79 | /** |
| 80 | * @serial The MBean attribute new value. |
| 81 | */ |
| 82 | private Object newValue = null; |
| 83 | |
| 84 | |
| 85 | /** |
| 86 | * Constructs an attribute change notification object. |
| 87 | * In addition to the information common to all notification, the caller must supply the name and type |
| 88 | * of the attribute, as well as its old and new values. |
| 89 | * |
| 90 | * @param source The notification producer, that is, the MBean the attribute belongs to. |
| 91 | * @param sequenceNumber The notification sequence number within the source object. |
| 92 | * @param timeStamp The date at which the notification is being sent. |
| 93 | * @param msg A String containing the message of the notification. |
| 94 | * @param attributeName A String giving the name of the attribute. |
| 95 | * @param attributeType A String containing the type of the attribute. |
| 96 | * @param oldValue An object representing value of the attribute before the change. |
| 97 | * @param newValue An object representing value of the attribute after the change. |
| 98 | */ |
| 99 | public AttributeChangeNotification(Object source, long sequenceNumber, long timeStamp, String msg, |
| 100 | String attributeName, String attributeType, Object oldValue, Object newValue) { |
| 101 | |
| 102 | super(AttributeChangeNotification.ATTRIBUTE_CHANGE, source, sequenceNumber, timeStamp, msg); |
| 103 | this.attributeName = attributeName; |
| 104 | this.attributeType = attributeType; |
| 105 | this.oldValue = oldValue; |
| 106 | this.newValue = newValue; |
| 107 | } |
| 108 | |
| 109 | |
| 110 | /** |
| 111 | * Gets the name of the attribute which has changed. |
| 112 | * |
| 113 | * @return A String containing the name of the attribute. |
| 114 | */ |
| 115 | public String getAttributeName() { |
| 116 | return attributeName; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Gets the type of the attribute which has changed. |
| 121 | * |
| 122 | * @return A String containing the type of the attribute. |
| 123 | */ |
| 124 | public String getAttributeType() { |
| 125 | return attributeType; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Gets the old value of the attribute which has changed. |
| 130 | * |
| 131 | * @return An Object containing the old value of the attribute. |
| 132 | */ |
| 133 | public Object getOldValue() { |
| 134 | return oldValue; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Gets the new value of the attribute which has changed. |
| 139 | * |
| 140 | * @return An Object containing the new value of the attribute. |
| 141 | */ |
| 142 | public Object getNewValue() { |
| 143 | return newValue; |
| 144 | } |
| 145 | |
| 146 | } |