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 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 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 super(cloneMessage(resource), action);
54 resourceIdentifier = identifier;
55 this.endpoint = endpoint;
56
57 }
58
59 protected static UMOMessage cloneMessage(UMOMessage message)
60 {
61
62 synchronized (message)
63 {
64 return new MuleMessage(message.getPayload(), message);
65 }
66 }
67
68 protected String getPayloadToString()
69 {
70 if (source instanceof UMOConnectable)
71 {
72 return ((UMOConnectable) source).getConnectionDescription();
73 }
74 return source.toString();
75 }
76
77 protected String getActionName(int action)
78 {
79 int i = action - MESSAGE_EVENT_ACTION_START_RANGE;
80 if (i - 1 > ACTIONS.length)
81 {
82 return String.valueOf(action);
83 }
84 return ACTIONS[i - 1];
85 }
86
87 public String toString()
88 {
89 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 return endpoint;
97 }
98
99 }