1
2
3
4
5
6
7
8
9
10
11 package org.mule.context.notification;
12
13 import org.mule.api.context.notification.ServerNotification;
14 import org.mule.api.context.notification.ServerNotificationHandler;
15 import org.mule.api.context.notification.ServerNotificationListener;
16
17
18
19
20 public class OptimisedNotificationHandler implements ServerNotificationHandler
21 {
22
23 private ServerNotificationHandler delegate;
24 private Class type;
25 private boolean dynamic = false;
26 private boolean enabled = false;
27
28 public OptimisedNotificationHandler(ServerNotificationHandler delegate, Class type)
29 {
30 this.delegate = delegate;
31 this.type = type;
32 dynamic = delegate.isNotificationDynamic();
33 enabled = delegate.isNotificationEnabled(type);
34 }
35
36 public boolean isNotificationDynamic()
37 {
38 return dynamic;
39 }
40
41 public boolean isListenerRegistered(ServerNotificationListener listener)
42 {
43 return delegate.isListenerRegistered(listener);
44 }
45
46
47
48
49
50
51
52
53
54
55 public boolean isNotificationEnabled(Class notfnClass)
56 {
57 if ((!dynamic) && type.isAssignableFrom(notfnClass))
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 }