Coverage Report - org.mule.transaction.constraints.BatchConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
BatchConstraint
86%
18/21
100%
4/4
1.25
 
 1  
 /*
 2  
  * $Id: BatchConstraint.java 10489 2008-01-23 17:53:38Z dfeist $
 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.transaction.constraints;
 12  
 
 13  
 import org.mule.api.MuleEvent;
 14  
 
 15  
 /**
 16  
  * <code>BatchConstraint</code> is a filter that counts on every execution and
 17  
  * returns true when the batch size value equals the execution count.
 18  
  */
 19  
 // @ThreadSafe
 20  2
 public class BatchConstraint extends ConstraintFilter
 21  
 {
 22  
     // @GuardedBy(this)
 23  2
     private int batchSize = 1;
 24  
     // @GuardedBy(this)
 25  2
     private int batchCount = 0;
 26  
 
 27  
     public boolean accept(MuleEvent event)
 28  
     {
 29  8
         synchronized (this)
 30  
         {
 31  8
             batchCount++;
 32  8
             return batchCount == batchSize;
 33  0
         }
 34  
     }
 35  
 
 36  
     public int getBatchSize()
 37  
     {
 38  2
         synchronized (this)
 39  
         {
 40  2
             return batchSize;
 41  0
         }
 42  
     }
 43  
 
 44  
     public synchronized void setBatchSize(int batchSize)
 45  
     {
 46  4
         synchronized (this)
 47  
         {
 48  4
             this.batchSize = batchSize;
 49  4
         }
 50  4
     }
 51  
 
 52  
     public Object clone() throws CloneNotSupportedException
 53  
     {
 54  2
         synchronized (this)
 55  
         {
 56  2
             BatchConstraint clone = (BatchConstraint) super.clone();
 57  2
             clone.setBatchSize(batchSize);
 58  4
             for (int i = 0; i < batchCount; i++)
 59  
             {
 60  2
                 clone.accept(null);
 61  
             }
 62  2
             return clone;
 63  0
         }
 64  
     }
 65  
 
 66  
 }