KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > mockobjects > WaitTask


1 package net.javacoding.jspider.mockobjects;
2
3 import net.javacoding.jspider.core.SpiderContext;
4 import net.javacoding.jspider.core.task.work.BaseWorkerTaskImpl;
5 import net.javacoding.jspider.core.task.WorkerTask;
6
7 /**
8  * Mock implementation of a Worker task. No real work is done, but there is
9  * simply done a wait for a certain amount of milliseconds.
10  *
11  * $Id: WaitTask.java,v 1.8 2003/04/10 16:19:25 vanrogu Exp $
12  *
13  * @author Günther Van Roey
14  */

15 public class WaitTask extends BaseWorkerTaskImpl {
16
17     /** the number of milliseconds to wait. */
18     protected int wait;
19
20     /** the number of milliseconds to wait during prepare method. */
21     protected int waitDuringPrepare;
22
23     /**
24      * Public constructor.
25      * @param context the spidercontext in user
26      * @param wait the number of milliseconds to wait
27      */

28     public WaitTask ( SpiderContext context, int wait ) {
29         this ( context, wait, 0);
30     }
31
32     /**
33      * Public constructor.
34      * @param context the spidercontext in user
35      * @param wait the number of milliseconds to wait
36      */

37     public WaitTask ( SpiderContext context, int wait, int waitDuringPrepare ) {
38         super(context, WorkerTask.WORKERTASK_THINKERTASK);
39         this.wait = wait;
40         this.waitDuringPrepare = waitDuringPrepare;
41     }
42
43     public void prepare() {
44         if ( waitDuringPrepare > 0 ) {
45             //System.out.println("Waiting in prepare() : " + waitDuringPrepare + " ms");
46
try {
47                 Thread.currentThread().wait(waitDuringPrepare);
48             } catch (InterruptedException JavaDoc e) {
49                 Thread.currentThread().interrupt();
50             }
51         }
52     }
53
54     /**
55      * Worker method implementation. Will just wait the specified number
56      * of milliseconds, and then return.
57      */

58     public void execute() {
59         //System.out.println("Waiting in execute() : " + wait + " ms");
60
try {
61             Thread.currentThread().wait(wait);
62         } catch (InterruptedException JavaDoc e) {
63             Thread.currentThread().interrupt();
64         }
65     }
66
67     // overridden here to avoid NullPointerException when BaseImpl accesses Agent
68
public void tearDown() {
69     }
70
71     public int getType() {
72         return WorkerTask.WORKERTASK_THINKERTASK;
73     }
74
75 }
76
Popular Tags