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