KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > distr > Worker


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.distr;
11
12 /**
13  * Worker implementation. A worker receives commands from an IMaster instance
14  * and returns results to the master. A worker can receive commands even when
15  * it is working but it can only work on one task at a time
16  *
17  * @author Klaus Meffert
18  * @since 2.4
19  */

20 public class Worker
21     implements IWorker {
22   /** String containing the CVS revision. Read out via reflection!*/
23   private final static String JavaDoc CVS_REVISION = "$Revision: 1.7 $";
24
25   /**
26    * Display name, only textual information.
27    */

28   private String JavaDoc m_displayName;
29
30   /**
31    * Listener to requests from the (one and only) master of this worker
32    * (=KKMultiServerThread resp. KKMultiServer (to make it more sophisticated
33    * and allow multiple requests from the master at once))
34    */

35   private MasterListener m_masterListener;
36
37   /**
38    * Reference to master for calling him back.
39    */

40   private MasterInfo m_master;
41
42   /**
43    * Construct the worker and tell him who his master is.
44    * @param a_displayName name for imformative purpose
45    * @param a_master the master of this worker
46    * @param a_masterListener listener for requests from master
47    *
48    * @author Klaus Meffert
49    * @since 2.4
50    */

51   public Worker(final String JavaDoc a_displayName, final MasterInfo a_master,
52                 final MasterListener a_masterListener) {
53     m_displayName = a_displayName;
54     m_master = a_master;
55     m_masterListener = a_masterListener;
56   }
57
58   /**
59    * @return display name of the worker
60    *
61    * @author Klaus Meffert
62    * @since 2.4
63    */

64   public String JavaDoc getDisplayName() {
65     return m_displayName;
66   }
67
68   /**
69    * Lets a server send a command to process to the worker
70    * @param a_command the command to process
71    * @return status message
72    *
73    * @author Klaus Meffert
74    * @since 2.4
75    */

76   public Object JavaDoc sendCommand(final WorkerCommand a_command) {
77     /**@todo this should be moved to a thread*/
78     /**@todo implement:
79      * currently working? if yes, add to queue (if queue not full)
80      * if no: start work*/

81     return null;
82   }
83
84   /**
85    * @return current status of the entity
86    *
87    * @author Klaus Meffert
88    * @since 2.4
89    */

90   public Object JavaDoc getStatus() {
91     /**@todo implement:
92      * idle
93      * starting
94      * receiving task
95      * working
96      * sending result
97      * stopping
98      * stopped*/

99     return null;
100   }
101
102   /**
103    * Forces the worker to pause its work (can be resumed)
104    * @return status message
105    *
106    * @author Klaus Meffert
107    * @since 2.4
108    */

109   public Object JavaDoc pause() {
110     /**@todo implement:
111      * able to pause resp. in work?*/

112     return null;
113   }
114
115   /**
116    * Forces the worker to stop its work (cannot be resumed)
117    * @return status message
118    *
119    * @author Klaus Meffert
120    * @since 2.4
121    */

122   public Object JavaDoc stop() {
123     /**@todo implement:
124      * able to stop resp. in work?*/

125     return null;
126   }
127
128   /**
129    * Forces the worker to resume a paused work
130    * @return status message
131    *
132    * @author Klaus Meffert
133    * @since 2.4
134    */

135   public Object JavaDoc resume() {
136     /**@todo implement:
137      * able to resum resp. paused?*/

138     return null;
139   }
140 }
141
Popular Tags