1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.hcc.util;
24
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27
28 import javax.management.MBeanServerNotification;
29 import javax.management.Notification;
30 import javax.management.NotificationListener;
31
32
33 public class NotificationDelegator
34 extends Delegator implements NotificationListener {
35
36 private static Logger log =
37 Logger.getLogger(NotificationDelegator.class.getName());
38
39 public NotificationDelegator() {
40 super(DelegatorPolicy.ACCEPT_ALL);
41 }
42
43 public NotificationDelegator(DelegatorPolicy p) {
44 super(p);
45 }
46
47 public void handleNotification(Notification notification, Object handback) {
48 if (log.isLoggable(Level.FINER)) {
49 log.finer("notification.type=" + notification.getType());
50 log.finer("notification.message=" + notification.getMessage());
51 log.finer("notification.userData=" + notification.getUserData());
52
53 if (notification instanceof MBeanServerNotification) {
54 log.finer("notification.mbeanName="
55 + ((MBeanServerNotification) notification)
56 .getMBeanName());
57 }
58 }
59
60 delegate(notification, handback);
61 }
62
63 protected boolean delegate(Notification n, Object handback) {
64 boolean consumedAtLeastOne = false;
65 for (Delegatable h : handlers) {
66 boolean accepted = ((NotificationDelegatableBase) h).delegate(
67 n,
68 handback);
69 if (accepted) {
70 consumedAtLeastOne = true;
71 }
72
73 if (accepted && policy == DelegatorPolicy.ACCEPT_FIRST) {
74 return true;
75 }
76 }
77
78 return consumedAtLeastOne;
79 }
80
81 public void addDelegatable(Delegatable d) {
82 super.addDelegatable((NotificationDelegatableBase) d);
83 }
84 }