1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.context.notification; |
12 | |
|
13 | |
import org.mule.DefaultMuleMessage; |
14 | |
import org.mule.api.MuleMessage; |
15 | |
import org.mule.api.component.Component; |
16 | |
import org.mule.api.context.notification.ServerNotification; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class ComponentMessageNotification extends ServerNotification |
23 | |
{ |
24 | |
|
25 | |
private static final long serialVersionUID = -6369685122731797646L; |
26 | |
|
27 | |
public static final int COMPONENT_PRE_INVOKE = COMPONENT_EVENT_ACTION_START_RANGE + 1; |
28 | |
public static final int COMPONENT_POST_INVOKE = COMPONENT_EVENT_ACTION_START_RANGE + 2; |
29 | |
|
30 | |
static |
31 | |
{ |
32 | 0 | registerAction("component pre invoke", COMPONENT_PRE_INVOKE); |
33 | 0 | registerAction("component post invoke", COMPONENT_POST_INVOKE); |
34 | 0 | } |
35 | |
|
36 | |
protected transient Component component; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public ComponentMessageNotification(MuleMessage message, Component component, int action) |
43 | |
{ |
44 | 0 | super(cloneMessage(message), action); |
45 | 0 | this.component = component; |
46 | 0 | resourceIdentifier = component.getService().getName(); |
47 | |
|
48 | 0 | } |
49 | |
|
50 | |
protected static MuleMessage cloneMessage(MuleMessage message) |
51 | |
{ |
52 | |
|
53 | 0 | synchronized (message) |
54 | |
{ |
55 | 0 | return new DefaultMuleMessage(message.getPayload(), message); |
56 | 0 | } |
57 | |
} |
58 | |
|
59 | |
protected String getPayloadToString() |
60 | |
{ |
61 | |
try |
62 | |
{ |
63 | 0 | return ((MuleMessage) source).getPayloadAsString(); |
64 | |
} |
65 | 0 | catch (Exception e) |
66 | |
{ |
67 | 0 | return source.toString(); |
68 | |
} |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public Component getComponent() |
75 | |
{ |
76 | 0 | return component; |
77 | |
} |
78 | |
|
79 | |
public String toString() |
80 | |
{ |
81 | 0 | return EVENT_NAME + "{action=" + getActionName(action) + ", message: " + source + ", resourceId=" |
82 | |
+ resourceIdentifier + ", timestamp=" + timestamp + ", serverId=" + serverId + ", component: " |
83 | |
+ component + "}"; |
84 | |
} |
85 | |
|
86 | |
} |