1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl.internal.notifications; |
12 | |
|
13 | |
import org.mule.impl.MuleMessage; |
14 | |
import org.mule.umo.UMOMessage; |
15 | |
import org.mule.umo.endpoint.UMOImmutableEndpoint; |
16 | |
import org.mule.umo.manager.UMOServerNotification; |
17 | |
import org.mule.umo.provider.UMOConnectable; |
18 | |
|
19 | |
import org.apache.commons.logging.Log; |
20 | |
import org.apache.commons.logging.LogFactory; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class MessageNotification extends UMOServerNotification |
27 | |
{ |
28 | |
|
29 | |
|
30 | |
|
31 | |
private static final long serialVersionUID = -5118299601117624094L; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | protected static final Log logger = LogFactory.getLog(MessageNotification.class); |
37 | |
|
38 | |
public static final int MESSAGE_RECEIVED = MESSAGE_EVENT_ACTION_START_RANGE + 1; |
39 | |
public static final int MESSAGE_DISPATCHED = MESSAGE_EVENT_ACTION_START_RANGE + 2; |
40 | |
public static final int MESSAGE_SENT = MESSAGE_EVENT_ACTION_START_RANGE + 3; |
41 | |
public static final int MESSAGE_REQUESTED = MESSAGE_EVENT_ACTION_START_RANGE + 4; |
42 | |
|
43 | 0 | private static final transient String[] ACTIONS = new String[]{"received", "dispatched", "sent", |
44 | |
"requested"}; |
45 | |
|
46 | |
private UMOImmutableEndpoint endpoint; |
47 | |
|
48 | |
public MessageNotification(UMOMessage resource, |
49 | |
UMOImmutableEndpoint endpoint, |
50 | |
String identifier, |
51 | |
int action) |
52 | |
{ |
53 | 0 | super(cloneMessage(resource), action); |
54 | 0 | resourceIdentifier = identifier; |
55 | 0 | this.endpoint = endpoint; |
56 | |
|
57 | 0 | } |
58 | |
|
59 | |
protected static UMOMessage cloneMessage(UMOMessage message) |
60 | |
{ |
61 | |
|
62 | 0 | synchronized (message) |
63 | |
{ |
64 | 0 | return new MuleMessage(message.getPayload(), message); |
65 | 0 | } |
66 | |
} |
67 | |
|
68 | |
protected String getPayloadToString() |
69 | |
{ |
70 | 0 | if (source instanceof UMOConnectable) |
71 | |
{ |
72 | 0 | return ((UMOConnectable) source).getConnectionDescription(); |
73 | |
} |
74 | 0 | return source.toString(); |
75 | |
} |
76 | |
|
77 | |
protected String getActionName(int action) |
78 | |
{ |
79 | 0 | int i = action - MESSAGE_EVENT_ACTION_START_RANGE; |
80 | 0 | if (i - 1 > ACTIONS.length) |
81 | |
{ |
82 | 0 | return String.valueOf(action); |
83 | |
} |
84 | 0 | return ACTIONS[i - 1]; |
85 | |
} |
86 | |
|
87 | |
public String toString() |
88 | |
{ |
89 | 0 | return EVENT_NAME + "{action=" + getActionName(action) + ", endpoint: " + endpoint.getEndpointURI() |
90 | |
+ ", resourceId=" + resourceIdentifier + ", timestamp=" + timestamp + ", serverId=" |
91 | |
+ serverId + ", message: " + source + "}"; |
92 | |
} |
93 | |
|
94 | |
public UMOImmutableEndpoint getEndpoint() |
95 | |
{ |
96 | 0 | return endpoint; |
97 | |
} |
98 | |
|
99 | |
} |