Coverage Report - org.mule.transaction.constraints.BatchConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
BatchConstraint
0%
0/21
0%
0/4
1.25
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transaction.constraints;
 8  
 
 9  
 import org.mule.api.MuleEvent;
 10  
 
 11  
 /**
 12  
  * <code>BatchConstraint</code> is a filter that counts on every execution and
 13  
  * returns true when the batch size value equals the execution count.
 14  
  */
 15  
 // @ThreadSafe
 16  0
 public class BatchConstraint extends ConstraintFilter
 17  
 {
 18  
     // @GuardedBy(this)
 19  0
     private int batchSize = 1;
 20  
     // @GuardedBy(this)
 21  0
     private int batchCount = 0;
 22  
 
 23  
     public boolean accept(MuleEvent event)
 24  
     {
 25  0
         synchronized (this)
 26  
         {
 27  0
             batchCount++;
 28  0
             return batchCount == batchSize;
 29  0
         }
 30  
     }
 31  
 
 32  
     public int getBatchSize()
 33  
     {
 34  0
         synchronized (this)
 35  
         {
 36  0
             return batchSize;
 37  0
         }
 38  
     }
 39  
 
 40  
     public synchronized void setBatchSize(int batchSize)
 41  
     {
 42  0
         synchronized (this)
 43  
         {
 44  0
             this.batchSize = batchSize;
 45  0
         }
 46  0
     }
 47  
 
 48  
     public Object clone() throws CloneNotSupportedException
 49  
     {
 50  0
         synchronized (this)
 51  
         {
 52  0
             BatchConstraint clone = (BatchConstraint) super.clone();
 53  0
             clone.setBatchSize(batchSize);
 54  0
             for (int i = 0; i < batchCount; i++)
 55  
             {
 56  0
                 clone.accept(null);
 57  
             }
 58  0
             return clone;
 59  0
         }
 60  
     }
 61  
 
 62  
 }