View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.lifecycle;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  import org.mule.api.construct.FlowConstruct;
12  import org.mule.api.construct.FlowConstructAware;
13  import org.mule.api.processor.MessageProcessor;
14  import org.mule.management.stats.ComponentStatistics;
15  
16  import org.mockito.Mockito;
17  
18  /**
19   * @author David Dossot (david@dossot.net)
20   */
21  public class LifecycleTrackerProcessor extends AbstractLifecycleTracker
22      implements FlowConstructAware, MessageProcessor
23  {
24      public static String LIFECYCLE_TRACKER_PROCESSOR_PROPERTY = "lifecycle";
25      public static String FLOW_CONSRUCT_PROPERTY = "flowConstruct";
26  
27      private FlowConstruct flowConstruct;
28  
29      public void springInitialize()
30      {
31          getTracker().add("springInitialize");
32      }
33  
34      public void springDestroy()
35      {
36          getTracker().add("springDestroy");
37      }
38  
39      public void setFlowConstruct(final FlowConstruct flowConstruct)
40      {
41          getTracker().add("setService");
42          this.flowConstruct = flowConstruct;
43      }
44  
45      public FlowConstruct getFlowConstruct()
46      {
47          return flowConstruct;
48      }
49  
50      public ComponentStatistics getStatistics()
51      {
52          return Mockito.mock(ComponentStatistics.class);
53      }
54  
55      public MuleEvent process(MuleEvent event) throws MuleException
56      {
57          event.getMessage().setOutboundProperty(LIFECYCLE_TRACKER_PROCESSOR_PROPERTY, getTracker().toString());
58          event.getMessage().setOutboundProperty(FLOW_CONSRUCT_PROPERTY, flowConstruct);
59          return event;
60      }
61  }