1
2
3
4
5
6
7 package org.mule.transaction.constraints;
8
9 import org.mule.api.MuleEvent;
10
11
12
13
14
15
16 public class BatchConstraint extends ConstraintFilter
17 {
18
19 private int batchSize = 1;
20
21 private int batchCount = 0;
22
23 public boolean accept(MuleEvent event)
24 {
25 synchronized (this)
26 {
27 batchCount++;
28 return batchCount == batchSize;
29 }
30 }
31
32 public int getBatchSize()
33 {
34 synchronized (this)
35 {
36 return batchSize;
37 }
38 }
39
40 public synchronized void setBatchSize(int batchSize)
41 {
42 synchronized (this)
43 {
44 this.batchSize = batchSize;
45 }
46 }
47
48 public Object clone() throws CloneNotSupportedException
49 {
50 synchronized (this)
51 {
52 BatchConstraint clone = (BatchConstraint) super.clone();
53 clone.setBatchSize(batchSize);
54 for (int i = 0; i < batchCount; i++)
55 {
56 clone.accept(null);
57 }
58 return clone;
59 }
60 }
61
62 }