Coverage Report - org.mule.tck.TestCaseWatchdog
 
Classes in this File Line Coverage Branch Coverage Complexity
TestCaseWatchdog
80%
16/20
50%
2/4
2
 
 1  
 /*
 2  
  * $Id: TestCaseWatchdog.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.tck;
 12  
 
 13  
 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
 14  
 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
 15  
 
 16  
 import org.apache.commons.logging.Log;
 17  
 import org.apache.commons.logging.LogFactory;
 18  
 
 19  
 public class TestCaseWatchdog extends Thread
 20  
 {
 21  2
     protected static final AtomicInteger threadNumber = new AtomicInteger(0);
 22  
 
 23  844
     protected final Log log = LogFactory.getLog(getClass());
 24  
 
 25  
     protected final long delay;
 26  
     protected final TimeUnit unit;
 27  
     protected final TestCaseWatchdogTimeoutHandler handler;
 28  
 
 29  
     public TestCaseWatchdog(long delay, TimeUnit unit, TestCaseWatchdogTimeoutHandler timeoutHandler)
 30  
     {
 31  844
         super("WatchdogThread-" + threadNumber.getAndIncrement());
 32  844
         this.setDaemon(true);
 33  844
         this.delay = delay;
 34  844
         this.unit = unit;
 35  844
         this.handler = timeoutHandler;
 36  844
     }
 37  
 
 38  
     public void run()
 39  
     {
 40  844
         long millisToWait = this.unit.toMillis(this.delay);
 41  844
         if (log.isDebugEnabled())
 42  
         {
 43  0
             log.debug("Starting with " + millisToWait + "ms timeout.");
 44  
         }
 45  
 
 46  
         try
 47  
         {
 48  844
             Thread.sleep(millisToWait);
 49  0
             handler.handleTimeout(delay, unit);
 50  
         }
 51  844
         catch (InterruptedException interrupted)
 52  
         {
 53  844
             if (log.isDebugEnabled())
 54  
             {
 55  0
                 log.debug("Watchdog stopped.");
 56  
             }
 57  0
         }
 58  844
     }
 59  
 
 60  
     public void cancel()
 61  
     {
 62  844
         this.interrupt();
 63  844
     }
 64  
 
 65  
 }