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.context.notification.ServerNotification;
16 import org.mule.api.endpoint.ImmutableEndpoint;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21
22
23
24
25 public class EndpointMessageNotification extends ServerNotification
26 {
27
28
29
30 private static final long serialVersionUID = -5118299601117624094L;
31
32
33
34
35 protected static final Log logger = LogFactory.getLog(EndpointMessageNotification.class);
36
37 public static final int MESSAGE_RECEIVED = MESSAGE_EVENT_ACTION_START_RANGE + 1;
38 public static final int MESSAGE_DISPATCHED = MESSAGE_EVENT_ACTION_START_RANGE + 2;
39 public static final int MESSAGE_SENT = MESSAGE_EVENT_ACTION_START_RANGE + 3;
40 public static final int MESSAGE_REQUESTED = MESSAGE_EVENT_ACTION_START_RANGE + 4;
41
42 static {
43 registerAction("received", MESSAGE_RECEIVED);
44 registerAction("dispatched", MESSAGE_DISPATCHED);
45 registerAction("sent", MESSAGE_SENT);
46 registerAction("requested", MESSAGE_REQUESTED);
47 }
48
49 private ImmutableEndpoint endpoint;
50
51 public EndpointMessageNotification(MuleMessage resource,
52 ImmutableEndpoint endpoint,
53 String identifier,
54 int action)
55 {
56 super(cloneMessage(resource), action);
57 resourceIdentifier = identifier;
58 this.endpoint = endpoint;
59 }
60
61 protected static MuleMessage cloneMessage(MuleMessage message)
62 {
63
64 synchronized (message)
65 {
66 return new DefaultMuleMessage(message.getPayload(), message);
67 }
68 }
69
70 protected String getPayloadToString()
71 {
72 try
73 {
74 return ((MuleMessage)source).getPayloadAsString();
75 }
76 catch (Exception e)
77 {
78 return source.toString();
79 }
80 }
81
82 public String toString()
83 {
84 return EVENT_NAME + "{action=" + getActionName(action) + ", endpoint: " + endpoint.getEndpointURI()
85 + ", resourceId=" + resourceIdentifier + ", timestamp=" + timestamp + ", serverId="
86 + serverId + ", message: " + source + "}";
87 }
88
89 public ImmutableEndpoint getEndpoint()
90 {
91 return endpoint;
92 }
93
94 }