1. /*
  2. * @(#)AttributeChangeNotification.java 4.20 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management;
  8. /**
  9. * Provides definitions of the attribute change notifications sent by MBeans.
  10. * <P>
  11. * It's up to the MBean owning the attribute of interest to create and send
  12. * attribute change notifications when the attribute change occurs.
  13. * So the <CODE>NotificationBroadcaster</CODE> interface has to be implemented
  14. * by any MBean for which an attribute change is of interest.
  15. * <P>
  16. * Example:
  17. * If an MBean called <CODE>myMbean</CODE> needs to notify registered listeners
  18. * when its attribute:
  19. * <BLOCKQUOTE><CODE>
  20. * String myString
  21. * </CODE></BLOCKQUOTE>
  22. * is modified, <CODE>myMbean</CODE> creates and emits the following notification:
  23. * <BLOCKQUOTE><CODE>
  24. * new AttributeChangeNotification(myMbean, sequenceNumber, timeStamp, msg,
  25. * "myString", "String", oldValue, newValue);
  26. * </CODE></BLOCKQUOTE>
  27. *
  28. * @since 1.5
  29. */
  30. public class AttributeChangeNotification extends javax.management.Notification {
  31. /* Serial version */
  32. private static final long serialVersionUID = 535176054565814134L;
  33. /**
  34. * Notification type which indicates that the observed MBean attribute value has changed.
  35. * <BR>The value of this type string is <CODE>jmx.attribute.change</CODE>.
  36. */
  37. public static final String ATTRIBUTE_CHANGE = "jmx.attribute.change";
  38. /**
  39. * @serial The MBean attribute name.
  40. */
  41. private String attributeName = null;
  42. /**
  43. * @serial The MBean attribute type.
  44. */
  45. private String attributeType = null;
  46. /**
  47. * @serial The MBean attribute old value.
  48. */
  49. private Object oldValue = null;
  50. /**
  51. * @serial The MBean attribute new value.
  52. */
  53. private Object newValue = null;
  54. /**
  55. * Constructs an attribute change notification object.
  56. * In addition to the information common to all notification, the caller must supply the name and type
  57. * of the attribute, as well as its old and new values.
  58. *
  59. * @param source The notification producer, that is, the MBean the attribute belongs to.
  60. * @param sequenceNumber The notification sequence number within the source object.
  61. * @param timeStamp The date at which the notification is being sent.
  62. * @param msg A String containing the message of the notification.
  63. * @param attributeName A String giving the name of the attribute.
  64. * @param attributeType A String containing the type of the attribute.
  65. * @param oldValue An object representing value of the attribute before the change.
  66. * @param newValue An object representing value of the attribute after the change.
  67. */
  68. public AttributeChangeNotification(Object source, long sequenceNumber, long timeStamp, String msg,
  69. String attributeName, String attributeType, Object oldValue, Object newValue) {
  70. super(AttributeChangeNotification.ATTRIBUTE_CHANGE, source, sequenceNumber, timeStamp, msg);
  71. this.attributeName = attributeName;
  72. this.attributeType = attributeType;
  73. this.oldValue = oldValue;
  74. this.newValue = newValue;
  75. }
  76. /**
  77. * Gets the name of the attribute which has changed.
  78. *
  79. * @return A String containing the name of the attribute.
  80. */
  81. public String getAttributeName() {
  82. return attributeName;
  83. }
  84. /**
  85. * Gets the type of the attribute which has changed.
  86. *
  87. * @return A String containing the type of the attribute.
  88. */
  89. public String getAttributeType() {
  90. return attributeType;
  91. }
  92. /**
  93. * Gets the old value of the attribute which has changed.
  94. *
  95. * @return An Object containing the old value of the attribute.
  96. */
  97. public Object getOldValue() {
  98. return oldValue;
  99. }
  100. /**
  101. * Gets the new value of the attribute which has changed.
  102. *
  103. * @return An Object containing the new value of the attribute.
  104. */
  105. public Object getNewValue() {
  106. return newValue;
  107. }
  108. }