Path: blob/master/src/java.management/share/classes/javax/management/AttributeChangeNotification.java
41155 views
/*1* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.management;26272829/**30* Provides definitions of the attribute change notifications sent by MBeans.31* <P>32* It's up to the MBean owning the attribute of interest to create and send33* attribute change notifications when the attribute change occurs.34* So the <CODE>NotificationBroadcaster</CODE> interface has to be implemented35* by any MBean for which an attribute change is of interest.36* <P>37* Example:38* If an MBean called <CODE>myMbean</CODE> needs to notify registered listeners39* when its attribute:40* <BLOCKQUOTE><CODE>41* String myString42* </CODE></BLOCKQUOTE>43* is modified, <CODE>myMbean</CODE> creates and emits the following notification:44* <BLOCKQUOTE><CODE>45* new AttributeChangeNotification(myMbean, sequenceNumber, timeStamp, msg,46* "myString", "String", oldValue, newValue);47* </CODE></BLOCKQUOTE>48*49* @since 1.550*/51public class AttributeChangeNotification extends javax.management.Notification {5253/* Serial version */54private static final long serialVersionUID = 535176054565814134L;5556/**57* Notification type which indicates that the observed MBean attribute value has changed.58* <BR>The value of this type string is <CODE>jmx.attribute.change</CODE>.59*/60public static final String ATTRIBUTE_CHANGE = "jmx.attribute.change";616263/**64* @serial The MBean attribute name.65*/66private String attributeName = null;6768/**69* @serial The MBean attribute type.70*/71private String attributeType = null;7273/**74* @serial The MBean attribute old value.75*/76@SuppressWarnings("serial") // Conditionally serializable77private Object oldValue = null;7879/**80* @serial The MBean attribute new value.81*/82@SuppressWarnings("serial") // Conditionally serializable83private Object newValue = null;848586/**87* Constructs an attribute change notification object.88* In addition to the information common to all notification, the caller must supply the name and type89* of the attribute, as well as its old and new values.90*91* @param source The notification producer, that is, the MBean the attribute belongs to.92* @param sequenceNumber The notification sequence number within the source object.93* @param timeStamp The date at which the notification is being sent.94* @param msg A String containing the message of the notification.95* @param attributeName A String giving the name of the attribute.96* @param attributeType A String containing the type of the attribute.97* @param oldValue An object representing value of the attribute before the change.98* @param newValue An object representing value of the attribute after the change.99*/100public AttributeChangeNotification(Object source, long sequenceNumber, long timeStamp, String msg,101String attributeName, String attributeType, Object oldValue, Object newValue) {102103super(AttributeChangeNotification.ATTRIBUTE_CHANGE, source, sequenceNumber, timeStamp, msg);104this.attributeName = attributeName;105this.attributeType = attributeType;106this.oldValue = oldValue;107this.newValue = newValue;108}109110111/**112* Gets the name of the attribute which has changed.113*114* @return A String containing the name of the attribute.115*/116public String getAttributeName() {117return attributeName;118}119120/**121* Gets the type of the attribute which has changed.122*123* @return A String containing the type of the attribute.124*/125public String getAttributeType() {126return attributeType;127}128129/**130* Gets the old value of the attribute which has changed.131*132* @return An Object containing the old value of the attribute.133*/134public Object getOldValue() {135return oldValue;136}137138/**139* Gets the new value of the attribute which has changed.140*141* @return An Object containing the new value of the attribute.142*/143public Object getNewValue() {144return newValue;145}146147}148149150