1
2
3
4
5
6
7 package org.mule.context.notification;
8
9 import org.mule.api.context.notification.ServerNotification;
10 import org.mule.api.context.notification.ServerNotificationHandler;
11 import org.mule.api.context.notification.ServerNotificationListener;
12
13
14
15
16 public class OptimisedNotificationHandler implements ServerNotificationHandler
17 {
18
19 private ServerNotificationHandler delegate;
20 private Class type;
21 private boolean dynamic = false;
22 private volatile Boolean enabled = null;
23
24 public OptimisedNotificationHandler(ServerNotificationHandler delegate, Class type)
25 {
26 this.delegate = delegate;
27 this.type = type;
28 dynamic = delegate.isNotificationDynamic();
29 }
30
31 public boolean isNotificationDynamic()
32 {
33 return dynamic;
34 }
35
36 public boolean isListenerRegistered(ServerNotificationListener listener)
37 {
38 return delegate.isListenerRegistered(listener);
39 }
40
41
42
43
44
45
46
47
48
49
50 public boolean isNotificationEnabled(Class notfnClass)
51 {
52 if ((!dynamic) && type.isAssignableFrom(notfnClass))
53 {
54 if (enabled == null)
55 {
56 enabled = delegate.isNotificationEnabled(notfnClass);
57 }
58
59 return enabled;
60 }
61 else
62 {
63 return delegate.isNotificationEnabled(notfnClass);
64 }
65 }
66
67 public void fireNotification(ServerNotification notification)
68 {
69 if (isNotificationEnabled(notification.getClass()))
70 {
71 delegate.fireNotification(notification);
72 }
73 }
74
75 }