KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > stats > AbstractNotifyingMBean


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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