Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BatchConstraint |
|
| 1.25;1.25 |
1 | /* | |
2 | * $Id: BatchConstraint.java 19191 2010-08-25 21:05:23Z tcarlson $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.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 | 0 | public class BatchConstraint extends ConstraintFilter |
21 | { | |
22 | // @GuardedBy(this) | |
23 | 0 | private int batchSize = 1; |
24 | // @GuardedBy(this) | |
25 | 0 | private int batchCount = 0; |
26 | ||
27 | public boolean accept(MuleEvent event) | |
28 | { | |
29 | 0 | synchronized (this) |
30 | { | |
31 | 0 | batchCount++; |
32 | 0 | return batchCount == batchSize; |
33 | 0 | } |
34 | } | |
35 | ||
36 | public int getBatchSize() | |
37 | { | |
38 | 0 | synchronized (this) |
39 | { | |
40 | 0 | return batchSize; |
41 | 0 | } |
42 | } | |
43 | ||
44 | public synchronized void setBatchSize(int batchSize) | |
45 | { | |
46 | 0 | synchronized (this) |
47 | { | |
48 | 0 | this.batchSize = batchSize; |
49 | 0 | } |
50 | 0 | } |
51 | ||
52 | public Object clone() throws CloneNotSupportedException | |
53 | { | |
54 | 0 | synchronized (this) |
55 | { | |
56 | 0 | BatchConstraint clone = (BatchConstraint) super.clone(); |
57 | 0 | clone.setBatchSize(batchSize); |
58 | 0 | for (int i = 0; i < batchCount; i++) |
59 | { | |
60 | 0 | clone.accept(null); |
61 | } | |
62 | 0 | return clone; |
63 | 0 | } |
64 | } | |
65 | ||
66 | } |