View Javadoc

1   /*
2    * $Id: LifecycleTrackerProcessor.java 22730 2011-08-24 23:58:29Z 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.lifecycle;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.construct.FlowConstruct;
16  import org.mule.api.construct.FlowConstructAware;
17  import org.mule.api.processor.MessageProcessor;
18  import org.mule.management.stats.ComponentStatistics;
19  
20  import org.mockito.Mockito;
21  
22  /**
23   * @author David Dossot (david@dossot.net)
24   */
25  public class LifecycleTrackerProcessor extends AbstractLifecycleTracker
26      implements FlowConstructAware, MessageProcessor
27  {
28      public static String LIFECYCLE_TRACKER_PROCESSOR_PROPERTY = "lifecycle";
29      public static String FLOW_CONSRUCT_PROPERTY = "flowConstruct";
30  
31      private FlowConstruct flowConstruct;
32  
33      public void springInitialize()
34      {
35          getTracker().add("springInitialize");
36      }
37  
38      public void springDestroy()
39      {
40          getTracker().add("springDestroy");
41      }
42  
43      public void setFlowConstruct(final FlowConstruct flowConstruct)
44      {
45          getTracker().add("setService");
46          this.flowConstruct = flowConstruct;
47      }
48  
49      public FlowConstruct getFlowConstruct()
50      {
51          return flowConstruct;
52      }
53  
54      public ComponentStatistics getStatistics()
55      {
56          return Mockito.mock(ComponentStatistics.class);
57      }
58  
59      public MuleEvent process(MuleEvent event) throws MuleException
60      {
61          event.getMessage().setOutboundProperty(LIFECYCLE_TRACKER_PROCESSOR_PROPERTY, getTracker().toString());
62          event.getMessage().setOutboundProperty(FLOW_CONSRUCT_PROPERTY, flowConstruct);
63          return event;
64      }
65  }