Coverage Report - org.mule.tck.TestCaseWatchdog
 
Classes in this File Line Coverage Branch Coverage Complexity
TestCaseWatchdog
0%
0/21
0%
0/2
2
 
 1  
 /*
 2  
  * $Id: TestCaseWatchdog.java 7976 2007-08-21 14:26:13Z 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  0
     protected static final Log log = LogFactory.getLog(TestCaseWatchdog.class);
 22  0
     protected static final AtomicInteger threadNumber = new AtomicInteger(0);
 23  
 
 24  
     private final long delay;
 25  
     private final TimeUnit unit;
 26  
 
 27  
     public TestCaseWatchdog(long delay, TimeUnit unit)
 28  
     {
 29  0
         super("WatchdogThread-" + threadNumber.getAndIncrement());
 30  0
         this.setDaemon(true);
 31  0
         this.delay = delay;
 32  0
         this.unit = unit;
 33  0
     }
 34  
 
 35  
     public void run()
 36  
     {
 37  0
         long millisToWait = this.unit.toMillis(this.delay);
 38  0
         if (log.isDebugEnabled())
 39  
         {
 40  0
             log.debug("Starting with " + millisToWait + "ms timeout.");
 41  
         }
 42  
 
 43  
         try
 44  
         {
 45  0
             Thread.sleep(millisToWait);
 46  0
             log.fatal("Timeout of " + millisToWait + "ms exceeded - exiting VM!");
 47  
             // we should really log a thread dump here to find deadlocks;
 48  
             // too bad the required JMX functionality is not in JDK 1.4 :(
 49  0
             Runtime.getRuntime().halt(1);
 50  
         }
 51  0
         catch (InterruptedException interrupted)
 52  
         {
 53  0
             if (log.isDebugEnabled())
 54  
             {
 55  0
                 log.debug("Watchdog stopped.");
 56  
             }
 57  0
             Thread.currentThread().interrupt();
 58  0
         }
 59  0
     }
 60  
 
 61  
     public void cancel()
 62  
     {
 63  0
         this.interrupt();
 64  0
     }
 65  
 }