1 4 package com.tc.stats; 5 6 import com.tc.management.AbstractTerracottaMBean; 7 8 import javax.management.AttributeChangeNotification ; 9 import javax.management.MBeanNotificationInfo ; 10 import javax.management.NotCompliantMBeanException ; 11 import javax.management.Notification ; 12 13 public abstract class AbstractNotifyingMBean extends AbstractTerracottaMBean { 14 15 private static final MBeanNotificationInfo [] NOTIFICATION_INFO; 16 static { 17 final String [] types = new String [] { AttributeChangeNotification.ATTRIBUTE_CHANGE }; 18 final String noticeType = AttributeChangeNotification .class.getName(); 19 final String description = "An attribute of this MBean has changed"; 20 NOTIFICATION_INFO = new MBeanNotificationInfo [] { new MBeanNotificationInfo (types, noticeType, description) }; 21 22 } 23 24 private long nextSequenceNumber = 1; 25 26 protected AbstractNotifyingMBean(final Class mBeanInterface) throws NotCompliantMBeanException { 27 super(mBeanInterface, true); 28 } 29 30 public MBeanNotificationInfo [] getNotificationInfo() { 31 return NOTIFICATION_INFO; 32 } 33 34 protected synchronized void sendNotification(final String type, final Object source) { 35 sendNotification(new Notification (type, source, nextSequenceNumber++)); 36 } 37 38 protected synchronized void sendNotification(final String msg, final String attr, final String type, 39 final Object oldVal, final Object newVal) { 40 sendNotification(new AttributeChangeNotification (this, nextSequenceNumber++, System.currentTimeMillis(), msg, attr, 41 type, oldVal, newVal)); 42 } 43 44 } 45 | Popular Tags |