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 | 0 | public class BatchConstraint extends ConstraintFilter |
17 | |
{ |
18 | |
|
19 | 0 | private int batchSize = 1; |
20 | |
|
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 | |
} |