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