// This is going to be reused through every message sending
resetIdSerializers();
resetIdCounter();
// Count messages
int currentMachineId = 0;
PartitionOwner owner = null;
WorkerInfo workerInfo = null;
I vertexId = null;
while (vertexIdIterator.hasNext()) {
vertexId = vertexIdIterator.next();
owner = getServiceWorker().getVertexPartitionOwner(vertexId);
workerInfo = owner.getWorkerInfo();
currentMachineId = workerInfo.getTaskId();
// Serialize this target vertex id
try {
vertexId.write(idSerializer[currentMachineId]);
} catch (IOException e) {
throw new IllegalStateException(
"Failed to serialize the target vertex id.");
}
idCounter[currentMachineId]++;
// Record the first partition id in the worker which message send to.
// If idCounter shows there is only one target on this worker
// then this is the partition number of the target vertex.
if (idCounter[currentMachineId] == 1) {
firstPartitionMap[currentMachineId] = owner.getPartitionId();
}
}
// Add the message to the cache
int idSerializerPos = 0;
int workerMessageSize = 0;