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