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
16
17
18
19 public class OptimisedNotificationHandler implements ServerNotificationHandler
20 {
21
22 private ServerNotificationHandler delegate;
23 private Class type;
24 private boolean dynamic = false;
25 private boolean enabled = false;
26
27 public OptimisedNotificationHandler(ServerNotificationHandler delegate, Class type)
28 {
29 this.delegate = delegate;
30 this.type = type;
31 dynamic = delegate.isNotificationDynamic();
32 enabled = delegate.isNotificationEnabled(type);
33 }
34
35 public boolean isNotificationDynamic()
36 {
37 return dynamic;
38 }
39
40
41
42
43
44
45
46
47
48
49 public boolean isNotificationEnabled(Class notfnClass)
50 {
51 if ((!dynamic) && type.isAssignableFrom(notfnClass))
52 {
53 return enabled;
54 }
55 else
56 {
57 return delegate.isNotificationEnabled(notfnClass);
58 }
59 }
60
61 public void fireNotification(ServerNotification notification)
62 {
63 if (isNotificationEnabled(notification.getClass()))
64 {
65 delegate.fireNotification(notification);
66 }
67 }
68
69 }