KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > taskman > NullTaskManager


1 package org.sapia.taskman;
2
3 import org.sapia.taskman.transaction.Transaction;
4
5 /**
6  * Implements a TaskManager that can be used EXCLUSIVELY in unit tests. This
7  * task manager has the following behavior:
8  *
9  * <ul>
10  * <li>Processes the added tasks sequentially, in the order in which they where
11  * added.
12  * <li>Does not take into account the time interval between execution of tasks.
13  * </ul>
14  *
15  * <p>
16  * Use the class as follows:
17  *
18  * <pre>
19  *
20  * NullTaskManager taskMan = new NullTaskManager();
21  * ...
22  * taskMan.execSyncTask(...);
23  * ...
24  * taskMan.run();
25  *
26  * </pre>
27  *
28  * Call the run method for as many times as needed by your unit tests.
29  *
30  *
31  * @author Yanick Duchesne
32  * <dl>
33  * <dt><b>Copyright: </b>
34  * <dd>Copyright &#169; 2002-2003 <a
35  * HREF="http://www.sapia-oss.org">Sapia Open Source Software </a>. All
36  * Rights Reserved.</dd>
37  * </dt>
38  * <dt><b>License: </b>
39  * <dd>Read the license.txt file of the jar or visit the <a
40  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the
41  * Sapia OSS web site</dd>
42  * </dt>
43  * </dl>
44  */

45 public class NullTaskManager extends TaskManager {
46   /**
47    * @see org.sapia.taskman.TaskManager#addTaskDescriptor(org.sapia.taskman.TaskDescriptor)
48    */

49   protected synchronized void addTaskDescriptor(TaskDescriptor desc) {
50     super.addTaskDescriptor(desc);
51     run();
52   }
53
54   /**
55    * @see org.sapia.taskman.TaskManager#run()
56    */

57   public void run() {
58     TaskmanTransaction current;
59     for(int i = 0; i < _transactions.size(); i++) {
60       current = (TaskmanTransaction) _transactions.get(i);
61
62       if(current.getStatus() == Transaction.STATUS_COMMITTED) {
63         _transactions.remove(i--);
64       } else if(current.getStatus() == Transaction.STATUS_INITIAL) {
65         // noop
66
} else {
67         current.execute();
68       }
69     }
70   }
71 }
72
Popular Tags