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