01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.stats;
05:
06: import com.tc.management.AbstractTerracottaMBean;
07:
08: import javax.management.AttributeChangeNotification;
09: import javax.management.MBeanNotificationInfo;
10: import javax.management.NotCompliantMBeanException;
11: import javax.management.Notification;
12:
13: public abstract class AbstractNotifyingMBean extends
14: AbstractTerracottaMBean {
15:
16: private static final MBeanNotificationInfo[] NOTIFICATION_INFO;
17: static {
18: final String[] types = new String[] { AttributeChangeNotification.ATTRIBUTE_CHANGE };
19: final String noticeType = AttributeChangeNotification.class
20: .getName();
21: final String description = "An attribute of this MBean has changed";
22: NOTIFICATION_INFO = new MBeanNotificationInfo[] { new MBeanNotificationInfo(
23: types, noticeType, description) };
24:
25: }
26:
27: private long nextSequenceNumber = 1;
28:
29: protected AbstractNotifyingMBean(final Class mBeanInterface)
30: throws NotCompliantMBeanException {
31: super (mBeanInterface, true);
32: }
33:
34: public MBeanNotificationInfo[] getNotificationInfo() {
35: return NOTIFICATION_INFO;
36: }
37:
38: protected synchronized void sendNotification(final String type,
39: final Object source) {
40: sendNotification(new Notification(type, source,
41: nextSequenceNumber++));
42: }
43:
44: protected synchronized void sendNotification(final String msg,
45: final String attr, final String type, final Object oldVal,
46: final Object newVal) {
47: sendNotification(new AttributeChangeNotification(this,
48: nextSequenceNumber++, System.currentTimeMillis(), msg,
49: attr, type, oldVal, newVal));
50: }
51:
52: }
|