View Javadoc

1   /*
2    * $Id: ComponentMessageNotification.java 22908 2011-09-09 19:57:25Z dfeist $
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      protected transient FlowConstruct flowConstruct;
31      protected transient Component component;
32  
33      static
34      {
35          registerAction("component pre invoke", COMPONENT_PRE_INVOKE);
36          registerAction("component post invoke", COMPONENT_POST_INVOKE);
37      }
38  
39      /**
40       * @param message
41       * @param action
42       */
43      public ComponentMessageNotification(MuleMessage message,
44                                          Component component,
45                                          FlowConstruct flowConstruct,
46                                          int action)
47      {
48          super(cloneMessage(message), action);
49          this.flowConstruct = flowConstruct;
50          this.component = component;
51          resourceIdentifier = flowConstruct.getName();
52  
53      }
54  
55      @Override
56      protected String getPayloadToString()
57      {
58          return ((MuleMessage) source).getPayloadForLogging();
59      }
60  
61      /**
62       * @return the message
63       */
64      public String getServiceName()
65      {
66          return resourceIdentifier;
67      }
68  
69      @Override
70      public String toString()
71      {
72          return EVENT_NAME + "{action=" + getActionName(action) + ", message: " + source + ", resourceId="
73                 + resourceIdentifier + ", timestamp=" + timestamp + ", serverId=" + serverId + ", component: "
74                 + "}";
75      }
76  
77      @Override
78      public String getType()
79      {
80          return "trace";
81      }
82  
83      @Override
84      public MuleMessage getSource()
85      {
86          return (MuleMessage) super.getSource();
87      }
88  
89      public FlowConstruct getFlowConstruct()
90      {
91          return flowConstruct;
92      }
93  
94      public Component getComponent()
95      {
96          return component;
97      }
98  }