KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > foxtrot > AbstractWorker


1 /**
2  * Copyright (c) 2002-2005, Simone Bordet
3  * All rights reserved.
4  *
5  * This software is distributable under the BSD license.
6  * See the terms of the BSD license in the documentation provided with this software.
7  */

8
9 package foxtrot;
10
11 /**
12  * Base class for all Foxtrot workers, both synchronous and asynchronous.
13  * @version $Revision: 1.2 $
14  */

15 abstract class AbstractWorker
16 {
17    static final boolean debug = false;
18
19    private WorkerThread workerThread;
20
21    AbstractWorker()
22    {
23    }
24
25    /**
26     * Returns the WorkerThread used to run {@link foxtrot.Task}s subclasses in a thread
27     * that is not the Event Dispatch Thread. <br />
28     * Uses a C-style getter method to avoid clash with the static getter method
29     * present in subclasses for API compatibility.
30     * @see #workerThread(WorkerThread)
31     */

32    WorkerThread workerThread()
33    {
34       if (workerThread == null) workerThread(createDefaultWorkerThread());
35       return workerThread;
36    }
37
38    /**
39     * Sets the WorkerThread used to run {@link foxtrot.Task}s subclasses in a thread
40     * that is not the Event Dispatch Thread.
41     * Uses a C-style setter method to avoid clash with the static setter method
42     * present in subclasses for API compatibility.
43     * @see #workerThread()
44     * @throws java.lang.IllegalArgumentException If workerThread is null
45     */

46    void workerThread(WorkerThread workerThread)
47    {
48       if (workerThread == null) throw new IllegalArgumentException JavaDoc("WorkerThread cannot be null");
49       this.workerThread = workerThread;
50       if (debug) System.out.println("[AbstractWorker] Initialized WorkerThread: " + workerThread);
51    }
52
53    /**
54     * Creates a default WorkerThread instance for this worker.
55     */

56    abstract WorkerThread createDefaultWorkerThread();
57 }
58
Popular Tags