Coverage Report - org.mule.impl.internal.notifications.MessageNotification
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageNotification
0%
0/18
0%
0/4
1.667
 
 1  
 /*
 2  
  * $Id: MessageNotification.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 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  
  * These notifications are fire when either a message is received via an endpoint, or
 24  
  * dispatcher of if a receive call is made on a dispatcher.
 25  
  */
 26  
 public class MessageNotification extends UMOServerNotification
 27  
 {
 28  
     /**
 29  
      * Serial version
 30  
      */
 31  
     private static final long serialVersionUID = -5118299601117624094L;
 32  
 
 33  
     /**
 34  
      * logger used by this class
 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  
         // TODO we probably need to support deep cloning here
 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  
 }