Job job = message.getJob();
// Sends ACK back
send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());
if (job instanceof ForkJob) {
ForkJob fJob = (ForkJob) job;
// Removes job from global node list
JobInfoList info = getOwnerNode().getJobInfoList();
JobInfo jobData = info.lookFor(job);
if (jobData != null) {
info.remove(jobData);
}
// Removes job from system list
GlobalJobInfoList global = getOwnerNode().getQueueNet().getJobInfoList();
global.removeForkedJob(fJob);
// Needed pieces
int needed;
if (jobs.containsKey(fJob.getForkedJob())) {
needed = jobs.get(fJob.getForkedJob()).intValue();
} else {
needed = fJob.getForkedNumber();
// As we are waiting for other fragments, adds merged job to global and local info list
JobInfo merged = new JobInfo(fJob.getForkedJob());
info.add(merged);
jobsList.add(merged);
}
// Decrement needed as we received this job
needed--;
// If needed is zero, all pieces has been retrived and job can be
// fowarded
if (needed == 0) {
jobs.remove(fJob.getForkedJob());
// Adds original job, otherwise we will have one less job in the network
global.addForkedJob(fJob.getForkedJob());
// Sends job forward
sendForward(fJob.getForkedJob(), 0.0);
// Notify fork node (to support blocking)
send(NetEvent.EVENT_JOIN, fJob.getForkedJob(), 0.0, fJob.getReferenceFork().getSectionID(), fJob.getReferenceFork()
.getOwnerNode());
} else {
// We must wait for more fragments before sending this to
// next section
jobs.put(fJob.getForkedJob(), new Integer(needed));
}
} else {
// If this is not a fork job, sends it forward
sendForward(job, 0.0);
}