/* (non-Javadoc)
* @see ca.eandb.jdcp.remote.JobService#requestTask()
*/
public synchronized TaskDescription requestTask() throws SecurityException {
TaskDescription taskDesc = scheduler.getNextTask();
if (taskDesc != null) {
ScheduledJob sched = jobs.get(taskDesc.getJobId());
try {
ServerUtil.setHostService(sched);
sched.scheduleNextTask();
} catch (JobExecutionException e) {
handleJobExecutionException(e, sched.id);
} finally {
ServerUtil.clearHostService();
}
return taskDesc;
}
int n = services.size();
if (n > 0) {
ServiceInfo[] serv;
synchronized (this) {
serv = (ServiceInfo[]) services.toArray(new ServiceInfo[n]);
}
for (ServiceInfo info : serv) {
try {
synchronized (this) {
if (services.remove(info)) {
services.add(info);
}
}
TaskDescription task = info.requestTask();
if (task != null) {
UUID jobId = task.getJobId();
routes.put(jobId, info);
return task;
}
} catch (Exception e) {
logger.error("Failed to request task from server", e);