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 | 0 | private boolean dynamic = false; |
26 | 0 | private boolean enabled = false; |
27 | |
|
28 | |
public OptimisedNotificationHandler(ServerNotificationHandler delegate, Class type) |
29 | 0 | { |
30 | 0 | this.delegate = delegate; |
31 | 0 | this.type = type; |
32 | 0 | dynamic = delegate.isNotificationDynamic(); |
33 | 0 | enabled = delegate.isNotificationEnabled(type); |
34 | 0 | } |
35 | |
|
36 | |
public boolean isNotificationDynamic() |
37 | |
{ |
38 | 0 | return dynamic; |
39 | |
} |
40 | |
|
41 | |
public boolean isListenerRegistered(ServerNotificationListener listener) |
42 | |
{ |
43 | 0 | return delegate.isListenerRegistered(listener); |
44 | |
} |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public boolean isNotificationEnabled(Class notfnClass) |
56 | |
{ |
57 | 0 | if ((!dynamic) && type.isAssignableFrom(notfnClass)) |
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 | |
} |