View Javadoc

1   /*
2    * $Id: ComponentMessageNotification.java 20339 2010-11-24 18:32:35Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.context.notification;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.component.Component;
15  import org.mule.api.construct.FlowConstruct;
16  import org.mule.api.context.notification.ServerNotification;
17  
18  /**
19   * These notifications are fired when before and after a service component is
20   * invoked.
21   */
22  public class ComponentMessageNotification extends ServerNotification
23  {
24  
25      private static final long serialVersionUID = -6369685122731797646L;
26  
27      public static final int COMPONENT_PRE_INVOKE = COMPONENT_EVENT_ACTION_START_RANGE + 1;
28      public static final int COMPONENT_POST_INVOKE = COMPONENT_EVENT_ACTION_START_RANGE + 2;
29  
30      static
31      {
32          registerAction("component pre invoke", COMPONENT_PRE_INVOKE);
33          registerAction("component post invoke", COMPONENT_POST_INVOKE);
34      }
35  
36      /**
37       * @param message
38       * @param action
39       */
40      public ComponentMessageNotification(MuleMessage message, Component component, FlowConstruct flowConstruct, int action)
41      {
42          super(cloneMessage(message), action);
43          resourceIdentifier = flowConstruct.getName();
44  
45      }
46  
47      @Override
48      protected String getPayloadToString()
49      {
50         return ((MuleMessage) source).getPayloadForLogging();
51      }
52  
53      /**
54       * @return the message
55       */
56      public String getServiceName()
57      {
58          return resourceIdentifier;
59      }
60  
61      @Override
62      public String toString()
63      {
64          return EVENT_NAME + "{action=" + getActionName(action) + ", message: " + source + ", resourceId="
65                 + resourceIdentifier + ", timestamp=" + timestamp + ", serverId=" + serverId + ", component: "
66                 + "}";
67      }
68  
69      @Override
70      public String getType()
71      {
72          return "trace"; 
73      }
74  
75      @Override
76      public MuleMessage getSource()
77      {
78          return (MuleMessage) super.getSource();
79      }
80  }