Coverage Report - org.mule.tck.functional.CountdownCallback
 
Classes in this File Line Coverage Branch Coverage Complexity
CountdownCallback
0%
0/13
0%
0/4
2.25
 
 1  
 /*
 2  
  * $Id: CountdownCallback.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  
 package org.mule.tck.functional;
 11  
 
 12  
 import org.mule.api.MuleEventContext;
 13  
 import org.mule.api.lifecycle.InitialisationException;
 14  
 import org.mule.config.i18n.MessageFactory;
 15  
 
 16  
 import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
 17  
 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
 18  
 import junit.framework.AssertionFailedError;
 19  
 
 20  
 public class CountdownCallback implements EventCallback
 21  
 {
 22  
     private CountDownLatch countDown;
 23  
 
 24  
     public CountdownCallback(int messagesExpected)
 25  0
     {
 26  0
         this.countDown = new CountDownLatch(messagesExpected);
 27  0
     }
 28  
 
 29  
     public void eventReceived(MuleEventContext context, Object Component) throws Exception
 30  
     {
 31  0
         synchronized (this)
 32  
         {            
 33  0
             if (countDown.getCount() > 0)
 34  
             {
 35  0
                 countDown.countDown();
 36  
             }
 37  
             else
 38  
             {
 39  0
                 throw new AssertionFailedError("Too many messages received");
 40  
             }
 41  0
         }
 42  0
     }
 43  
 
 44  
     public long getCount() throws InitialisationException
 45  
     {
 46  0
         if (countDown != null)
 47  
         {
 48  0
             return countDown.getCount();
 49  
         }
 50  
         else 
 51  
         {
 52  0
             throw new InitialisationException(MessageFactory.createStaticMessage("CountDownLatch has not been initialized."), null);
 53  
         }
 54  
     }
 55  
 
 56  
     public boolean await(long timeout) throws InterruptedException
 57  
     {
 58  0
         return countDown.await(timeout, TimeUnit.MILLISECONDS);
 59  
     }
 60  
     
 61  
 }