22
22
* results to the job server.
24
24
public interface Worker {
25
// These enums were copied over from the C library.
26
public enum WorkerOption {
27
NON_BLOCKING, PACKET_INIT, GRAB_JOB_IN_USE, PRE_SLEEP_IN_USE, WORK_JOB_IN_USE, CHANGE, GRAB_UNIQ
31
PACKET_IN_USE, CHANGE, REMOVE
35
START, STATE_FUNCTION_SEND, STATE_CONNECT, STATE_GRAB_JOB_SEND, STATE_GRAB_JOB_RECV, STATE_PRE_SLEEP
39
GRAB_JOB, FUNCTION, COMPLETE, FAIL
43
* Wait for a job and call the appropriate callback function when it gets one.
48
* Clears all {@link WorkerOption}s.
50
void clearWorkerOptions();
53
* Returns {@link java.util.EnumSet} of {@link WorkerOption}s.
55
* @return EnumSet of WorkerOptions
57
EnumSet<WorkerOption> getWorkerOptions();
60
* Removes each specified WorkerOption from the current set of Worker options.
62
* @param workerOptions
63
* one or more WorkerOptions
65
void removeWorkerOptions(WorkerOption... workerOptions);
68
* Adds each specified WorkerOption to the current set of Worker options. For
70
* <code>worker.setWorkerOptions(WorkerOption.NON_BLOCKING, WorkerOption.GRAB_JOB_IN_USE))</code>
72
* @param workerOptions
73
* one or more WorkerOptions
75
void setWorkerOptions(WorkerOption... workerOptions);
78
* Adds a {@link Connection} to a job server.
81
* connection to a job server
83
void addServer(Connection conn);
86
* Sends <code>text</code> to a job server with expectation of receiving the
87
* same data echoed back.
92
* connection to a job server
93
* @throws IORuntimeException
95
String echo(String text, Connection conn);
98
* Registers a JobFunction that a Worker can perform on a Job. If the worker
99
* does not respond with a result within the given timeout period in seconds,
100
* the job server will assume the work will not be performed by that worker
101
* and will again make the work available to be performed by any worker
102
* capable of performing this function.
105
* JobFunction for a function a Worker can perform
107
* time in seconds after job server will consider job to be abandoned
109
void registerFunction(JobFunction function, int timeout);
112
* Registers a JobFunction that a Worker can perform on a Job.
115
* JobFunction for a function a Worker can perform
117
void registerFunction(JobFunction function);
120
* Registers a JobFunction that a Worker can perform on a Job. If the worker
121
* does not respond with a result within the given timeout period in seconds,
122
* the job server will assume the work will not be performed by that worker
123
* and will again make the work available to be performed by any worker
124
* capable of performing this function.
127
* JobFunction Class for a function a Worker can perform
129
* time in seconds after job server will consider job to be abandoned
131
void registerFunction(Class<? extends JobFunction> function, int timeout);
134
* Registers a JobFunction that a Worker can perform on a Job.
137
* JobFunction Class for a function a Worker can perform
139
void registerFunction(Class<? extends JobFunction> function);
142
* Registers a JobFunctionFactory that a Worker will use to create a
143
* JobFunction object to execute a Job.If the worker does not respond with a
144
* result within the given timeout period in seconds, the job server will
145
* assume the work will not be performed by that worker and will again make
146
* the work available to be performed by any worker capable of performing this
150
* Factory that will be called to create a JobFunction instance for a
151
* function a Worker can perform
153
* time in seconds after job server will consider job to be abandoned
155
void registerFunctionFactory(JobFunctionFactory factory, int timeout);
158
* Registers a JobFunctionFactory that a Worker will use to create a
159
* JobFunction object to execute a Job.
162
* Factory that will be called to create a JobFunction instance for a
163
* function a Worker can perform
165
void registerFunctionFactory(JobFunctionFactory factory);
168
* Sets the worker ID in a job server so monitoring and reporting commands can
169
* uniquely identify the connected workers.
172
* ID that job server should use for an instance of a worker
174
void setWorkerID(String id);
177
* Sets the worker ID in a job server so monitoring and reporting commands can
178
* uniquely identify the connected workers. If a different ID is set with each
179
* job server, and connections can more easily be monitored and reported on
183
* ID that job server should use for an instance of a worker
185
* connection to the job server
187
void setWorkerID(String id, Connection conn);
190
* Unregisters with the Connection a function that a worker can perform on a
193
* @param functionName
194
* Name for a function a Worker can no longer perform
196
void unregisterFunction(String functionName);
199
* Unregisters all functions on all Connections.
201
void unregisterAll();
204
* Attempts to grab and then execute a Job on each connection.
206
* @return a Map indicating for each connection whether a Job was grabbed
208
Map<Connection, PacketType> grabJob();
211
* Attempts to grab and then execute a Job on the specified connection.
214
* connection to a job server
215
* @return a PacketType indicating with a job was grabbed
217
PacketType grabJob(Connection conn);
220
* Stops the work loop; requests to shutdown
225
* Stops the work loop and closes all open connections.
227
* @return a List of any Exceptions thrown when closing connections
229
List<Exception> shutdown();
25
// These enums were copied over from the C library.
26
public enum WorkerOption {
27
NON_BLOCKING, PACKET_INIT, GRAB_JOB_IN_USE, PRE_SLEEP_IN_USE, WORK_JOB_IN_USE, CHANGE, GRAB_UNIQ
31
PACKET_IN_USE, CHANGE, REMOVE
35
START, STATE_FUNCTION_SEND, STATE_CONNECT, STATE_GRAB_JOB_SEND, STATE_GRAB_JOB_RECV, STATE_PRE_SLEEP
39
GRAB_JOB, FUNCTION, COMPLETE, FAIL
43
* Wait for a job and call the appropriate callback function when it gets
49
* Clears all {@link WorkerOption}s.
51
void clearWorkerOptions();
54
* Returns {@link java.util.EnumSet} of {@link WorkerOption}s.
56
* @return EnumSet of WorkerOptions
58
EnumSet<WorkerOption> getWorkerOptions();
61
* Removes each specified WorkerOption from the current set of Worker
64
* @param workerOptions
65
* one or more WorkerOptions
67
void removeWorkerOptions(WorkerOption... workerOptions);
70
* Adds each specified WorkerOption to the current set of Worker options.
72
* <code>worker.setWorkerOptions(WorkerOption.NON_BLOCKING, WorkerOption.GRAB_JOB_IN_USE))</code>
74
* @param workerOptions
75
* one or more WorkerOptions
77
void setWorkerOptions(WorkerOption... workerOptions);
80
* Adds a {@link PacketConnection} to a job server.
83
* connection to a job server
85
void addServer(PacketConnection conn);
88
* Sends <code>text</code> to a job server with expectation of receiving the
89
* same data echoed back.
94
* connection to a job server
95
* @throws IORuntimeException
97
String echo(String text, PacketConnection conn);
100
* Registers a JobFunction that a Worker can perform on a Job. If the worker
101
* does not respond with a result within the given timeout period in
102
* seconds, the job server will assume the work will not be performed by
103
* that worker and will again make the work available to be performed by any
104
* worker capable of performing this function.
107
* JobFunction for a function a Worker can perform
109
* time in seconds after job server will consider job to be
112
void registerFunction(JobFunction function, int timeout);
115
* Registers a JobFunction that a Worker can perform on a Job.
118
* JobFunction for a function a Worker can perform
120
void registerFunction(JobFunction function);
123
* Registers a JobFunction that a Worker can perform on a Job. If the worker
124
* does not respond with a result within the given timeout period in
125
* seconds, the job server will assume the work will not be performed by
126
* that worker and will again make the work available to be performed by any
127
* worker capable of performing this function.
130
* JobFunction Class for a function a Worker can perform
132
* time in seconds after job server will consider job to be
135
void registerFunction(Class<? extends JobFunction> function, int timeout);
138
* Registers a JobFunction that a Worker can perform on a Job.
141
* JobFunction Class for a function a Worker can perform
143
void registerFunction(Class<? extends JobFunction> function);
146
* Registers a JobFunctionFactory that a Worker will use to create a
147
* JobFunction object to execute a Job.If the worker does not respond with a
148
* result within the given timeout period in seconds, the job server will
149
* assume the work will not be performed by that worker and will again make
150
* the work available to be performed by any worker capable of performing
154
* Factory that will be called to create a JobFunction instance
155
* for a function a Worker can perform
157
* time in seconds after job server will consider job to be
160
void registerFunctionFactory(JobFunctionFactory factory, int timeout);
163
* Registers a JobFunctionFactory that a Worker will use to create a
164
* JobFunction object to execute a Job.
167
* Factory that will be called to create a JobFunction instance
168
* for a function a Worker can perform
170
void registerFunctionFactory(JobFunctionFactory factory);
173
* Sets the worker ID in a job server so monitoring and reporting commands
174
* can uniquely identify the connected workers.
177
* ID that job server should use for an instance of a worker
179
void setWorkerID(String id);
182
* Sets the worker ID in a job server so monitoring and reporting commands
183
* can uniquely identify the connected workers. If a different ID is set
184
* with each job server, and connections can more easily be monitored and
185
* reported on independently.
188
* ID that job server should use for an instance of a worker
190
* connection to the job server
192
void setWorkerID(String id, PacketConnection conn);
195
* Unregisters with the Connection a function that a worker can perform on a
198
* @param functionName
199
* Name for a function a Worker can no longer perform
201
void unregisterFunction(String functionName);
204
* Unregisters all functions on all Connections.
206
void unregisterAll();
209
* Attempts to grab and then execute a Job on each connection.
211
* @return a Map indicating for each connection whether a Job was grabbed
213
Map<PacketConnection, PacketType> grabJob();
216
* Attempts to grab and then execute a Job on the specified connection.
219
* connection to a job server
220
* @return a PacketType indicating with a job was grabbed
222
PacketType grabJob(PacketConnection conn);
225
* Stops the work loop; requests to shutdown
230
* Stops the work loop and closes all open connections.
232
* @return a List of any Exceptions thrown when closing connections
234
List<Exception> shutdown();