1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transaction.constraints; |
12 | |
|
13 | |
import org.mule.api.MuleEvent; |
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | 2 | public class BatchConstraint extends ConstraintFilter |
21 | |
{ |
22 | |
|
23 | 2 | private int batchSize = 1; |
24 | |
|
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 | |
} |