@Override
 public void readFieldsRequest(DataInput input) throws IOException {
   oneToAllMsgs =
       new ByteArrayOneToAllMessages<I, M>(getConf().<M>getOutgoingMessageValueFactory());
   oneToAllMsgs.setConf(getConf());
   oneToAllMsgs.readFields(input);
 }
  @Override
  public void doRequest(ServerData serverData) {
    CentralizedServiceWorker<I, ?, ?> serviceWorker = serverData.getServiceWorker();
    // Get the initial size of ByteArrayVertexIdMessages per partition
    // on this worker. To make sure every ByteArrayVertexIdMessages to have
    // enough space to store the messages, we divide the original one-to-all
    // message size by the number of partitions and double the size
    // (Assume the major component in one-to-all message is a id list.
    // Now each target id has a copy of message,
    // therefore we double the buffer size)
    // to get the initial size of ByteArrayVertexIdMessages.
    int initialSize =
        oneToAllMsgs.getSize() / serverData.getPartitionStore().getNumPartitions() * 2;
    // Create ByteArrayVertexIdMessages for
    // message reformatting.
    Int2ObjectOpenHashMap<ByteArrayVertexIdMessages> partitionIdMsgs =
        new Int2ObjectOpenHashMap<ByteArrayVertexIdMessages>();

    // Put data from ByteArrayOneToAllMessages to ByteArrayVertexIdMessages
    ExtendedDataInput reader = oneToAllMsgs.getOneToAllMessagesReader();
    I vertexId = getConf().createVertexId();
    M msg = oneToAllMsgs.createMessage();
    int idCount = 0;
    int partitionId = 0;
    try {
      while (reader.available() != 0) {
        msg.readFields(reader);
        idCount = reader.readInt();
        for (int i = 0; i < idCount; i++) {
          vertexId.readFields(reader);
          PartitionOwner owner = serviceWorker.getVertexPartitionOwner(vertexId);
          partitionId = owner.getPartitionId();
          ByteArrayVertexIdMessages<I, M> idMsgs = partitionIdMsgs.get(partitionId);
          if (idMsgs == null) {
            idMsgs =
                new ByteArrayVertexIdMessages<I, M>(getConf().<M>getOutgoingMessageValueFactory());
            idMsgs.setConf(getConf());
            idMsgs.initialize(initialSize);
            partitionIdMsgs.put(partitionId, idMsgs);
          }
          idMsgs.add(vertexId, msg);
        }
      }
    } catch (IOException e) {
      throw new RuntimeException("doRequest: Got IOException ", e);
    }
    // Read ByteArrayVertexIdMessages and write to message store
    try {
      for (Entry<Integer, ByteArrayVertexIdMessages> idMsgs : partitionIdMsgs.entrySet()) {
        if (!idMsgs.getValue().isEmpty()) {
          serverData
              .getIncomingMessageStore()
              .addPartitionMessages(idMsgs.getKey(), idMsgs.getValue());
        }
      }
    } catch (IOException e) {
      throw new RuntimeException("doRequest: Got IOException.", e);
    }
  }