JobRecord jobRecord = null;
// Get the JobRecord, its finalize Barrier, all the slots in the
// finalize Barrier, and the job's output Slot.
jobRecord = queryJobOrAbandonTask(jobKey, JobRecord.InflationType.FOR_FINALIZE);
Barrier finalizeBarrier = jobRecord.getFinalizeBarrierInflated();
if (null == finalizeBarrier) {
throw new RuntimeException("" + jobRecord + " has not been inflated");
}
Slot outputSlot = jobRecord.getOutputSlotInflated();
if (null == outputSlot) {
throw new RuntimeException("" + jobRecord + " has not been inflated.");
}
// release the finalize barrier now so that any concurrent
// HandleSlotFilled tasks will stop trying
finalizeBarrier.setReleased();
UpdateSpec updateSpec = new UpdateSpec(jobRecord.getRootJobKey());
updateSpec.getTransaction("releaseFinalizeBarrier").includeBarrier(finalizeBarrier);
backEnd.save(updateSpec);
updateSpec = new UpdateSpec(jobRecord.getRootJobKey());
// Copy the finalize value to the output slot
List<Object> finalizeArguments = finalizeBarrier.buildArgumentList();
int numFinalizeArguments = finalizeArguments.size();
if (1 != numFinalizeArguments) {
throw new RuntimeException("Internal logic error: numFinalizeArguments="
+ numFinalizeArguments);
}