KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > transaction > constraints > BatchConstraint


1 /*
2  * $Id: BatchConstraint.java 3193 2006-09-24 22:48:20Z holger $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
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.umo.UMOEvent;
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
public class BatchConstraint extends ConstraintFilter
21 {
22     // @GuardedBy(this)
23
private int batchSize = 1;
24     // @GuardedBy(this)
25
private int batchCount = 0;
26
27     public boolean accept(UMOEvent event)
28     {
29         synchronized (this)
30         {
31             batchCount++;
32             return batchCount == batchSize;
33         }
34     }
35
36     public int getBatchSize()
37     {
38         synchronized (this)
39         {
40             return batchSize;
41         }
42     }
43
44     public synchronized void setBatchSize(int batchSize)
45     {
46         synchronized (this)
47         {
48             this.batchSize = batchSize;
49         }
50     }
51
52     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc
53     {
54         synchronized (this)
55         {
56             BatchConstraint clone = (BatchConstraint)super.clone();
57             clone.setBatchSize(batchSize);
58             for (int i = 0; i < batchCount; i++)
59             {
60                 clone.accept(null);
61             }
62             return clone;
63         }
64     }
65
66 }
67
Popular Tags