final Channel.ID mergedChannelID = this.ioManager.createChannel();
registerChannelToBeRemovedAtShudown(mergedChannelID);
final BlockChannelWriter writer = this.ioManager.createBlockChannelWriter(
mergedChannelID, this.numWriteBuffersToCluster);
registerOpenChannelToBeRemovedAtShudown(writer);
final ChannelWriterOutputView output = new ChannelWriterOutputView(writer, writeBuffers,
this.memManager.getPageSize());
final WriterCollector<E> collector = new WriterCollector<E>(output, this.serializer);
final FlatCombineFunction<E> combineStub = CombiningUnilateralSortMerger.this.combineStub;
// combine and write to disk
try {
while (groupedIter.nextKey()) {
combineStub.combine(groupedIter.getValues(), collector);
}
}
catch (Exception e) {
throw new IOException("An error occurred in the combiner user code.");
}
output.close(); //IS VERY IMPORTANT!!!!
final int numBlocksWritten = output.getBlockCount();
// register merged result to be removed at shutdown
unregisterOpenChannelToBeRemovedAtShudown(writer);
// remove the merged channel readers from the clear-at-shutdown list