Coverage Report - org.mule.module.tomcat.MuleTomcatListener
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleTomcatListener
0%
0/31
0%
0/10
4
 
 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.module.tomcat;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.config.builders.DeployableMuleXmlContextListener;
 12  
 import org.mule.context.DefaultMuleContextFactory;
 13  
 
 14  
 import org.apache.catalina.Lifecycle;
 15  
 import org.apache.catalina.LifecycleEvent;
 16  
 import org.apache.catalina.LifecycleListener;
 17  
 import org.apache.juli.logging.Log;
 18  
 import org.apache.juli.logging.LogFactory;
 19  
 
 20  
 /**
 21  
  *
 22  
  */
 23  0
 public class MuleTomcatListener implements LifecycleListener
 24  
 {
 25  
 
 26  0
     private static Log log = LogFactory.getLog(MuleTomcatListener.class);
 27  
 
 28  
     protected MuleContext muleContext;
 29  
 
 30  
     public void lifecycleEvent(LifecycleEvent event)
 31  
     {
 32  0
         if (Lifecycle.BEFORE_START_EVENT.equals(event.getType()))
 33  
         {
 34  0
             if (log.isDebugEnabled())
 35  
             {
 36  0
                 log.debug("BEFORE_START_EVENT");
 37  
             }
 38  0
             doStart();
 39  0
             return;
 40  
         }
 41  
 
 42  0
         if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()))
 43  
         {
 44  0
             if (log.isDebugEnabled())
 45  
             {
 46  0
                 log.debug("BEFORE_STOP_EVENT");
 47  
             }
 48  0
             doStop();
 49  0
             return;
 50  
         }
 51  
 
 52  0
         if (log.isDebugEnabled())
 53  
         {
 54  0
             log.debug("not our event: " + event.getType());
 55  
         }
 56  0
     }
 57  
 
 58  
     protected void doStart()
 59  
     {
 60  0
         log.info("Starting Mule");
 61  0
         DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
 62  
         try
 63  
         {
 64  0
             muleContext = muleContextFactory.createMuleContext();
 65  0
             muleContext.start();
 66  
 
 67  
             // Make single shared instance of mule context
 68  
             // available to DeployableMuleXmlContextListener to support
 69  
             // hot-deployment of Mule configurations in web applications.
 70  0
             DeployableMuleXmlContextListener.setMuleContext(muleContext);
 71  
         }
 72  0
         catch (Exception e)
 73  
         {
 74  0
             log.error("Failed to start Mule", e);
 75  0
         }
 76  0
     }
 77  
 
 78  
     protected void doStop()
 79  
     {
 80  0
         log.info("Stopping Mule");
 81  
         try
 82  
         {
 83  0
             muleContext.stop();
 84  
         }
 85  0
         catch (MuleException e)
 86  
         {
 87  
             // sigh, ridiculous juli bugs - logger would have already been disposed
 88  
             // by a shutdown handler by now
 89  0
             System.err.println("Failed to stop Mule: " + e);
 90  0
         }
 91  0
         muleContext.dispose();
 92  0
     }
 93  
 }