KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtriver > open > vectorvisuals > task > IndefiniteTaskChain


1 /*
2  * IndefiniteTaskChain.java
3  *
4  * Created on 10 November 2004, 16:02
5  */

6
7 package com.thoughtriver.open.vectorvisuals.task;
8
9 /**
10  * This is a special type of <CODE>TaskChain</CODE> that does not get removed
11  * from the execution pool when it has run out of tasks to execute. Instead, it
12  * keeps itself in a sort of stasis condition by adding an <CODE>KeepAliveTask</CODE>,
13  * and when a new task is added via the <CODE>{@link #addTask}</CODE> method,
14  * the <CODE>KeepAliveTask</CODE> is stopped and the new task is allowed to
15  * execute. The value of this is that a single <CODE>IndefiniteTaskChain</CODE>
16  * can be used to keep all desired <CODE>AnimationTask</CODE>s in sequence,
17  * no matter when they are generated.
18  *
19  * @author Brandon Franklin
20  * @version $Date: 2006/11/25 09:15:42 $
21  */

22 public class IndefiniteTaskChain extends TaskChain {
23
24     /**
25      * The <CODE>AnimationTask</CODE> used to keep the chain alive when it's
26      * "empty"
27      */

28     private AnimationTask keepAliveTask;
29
30     /**
31      * Creates a new instance of <CODE>IndefiniteTaskChain</CODE>.
32      */

33     public IndefiniteTaskChain() {
34         keepAliveTask = new KeepAliveTask();
35         super.addTask(keepAliveTask);
36     }
37
38     /**
39      * {@inheritDoc}
40      */

41     @Override JavaDoc
42     public void addTask(final AnimationTask task) {
43         super.addTask(task);
44
45         AnimationTask oldKeepAliveTask = keepAliveTask;
46         keepAliveTask = new KeepAliveTask();
47         super.addTask(keepAliveTask);
48
49         // The old keep alive task no longer needs to operate
50
oldKeepAliveTask.stop();
51     }
52
53 }
54
Popular Tags