class GetClientPartitionAttributesCommand extends BaseCommand {

  @SuppressWarnings("unchecked")
  @Override
  public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection,
      final SecurityService securityService, long start)
      throws IOException, ClassNotFoundException, InterruptedException {
    String regionFullPath = null;
    regionFullPath = clientMessage.getPart(0).getCachedString();
    String errMessage = "";
    if (regionFullPath == null) {
      errMessage = "The input region path for the GetClientPartitionAttributes request is null";
      logger.warn(errMessage);
      writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR,
          errMessage, serverConnection);
      serverConnection.setAsTrue(RESPONDED);
      return;
    }
    Region region = serverConnection.getCache().getRegion(regionFullPath);
    if (region == null) {
      logger.warn(
          "Region was not found during GetClientPartitionAttributes request for region path : {}",
          regionFullPath);
      errMessage =
          "Region was not found during GetClientPartitionAttributes request for region path : "
              + regionFullPath;
      writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR,
          errMessage.toString(), serverConnection);
      serverConnection.setAsTrue(RESPONDED);
      return;
    }

    try {
      Message responseMsg = serverConnection.getResponseMessage();
      responseMsg.setTransactionId(clientMessage.getTransactionId());
      responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PARTITION_ATTRIBUTES);

      PartitionedRegion prRgion = (PartitionedRegion) region;

      PartitionResolver partitionResolver = prRgion.getPartitionResolver();
      int numParts = 2; // MINUMUM PARTS
      if (partitionResolver != null) {
        numParts++;
      }
      responseMsg.setNumberOfParts(numParts);
      // PART 1
      responseMsg.addObjPart(prRgion.getTotalNumberOfBuckets());

      // PART 2
      if (partitionResolver != null) {
        responseMsg.addObjPart(partitionResolver.getClass().toString().substring(6));
      }

      // PART 3
      String leaderRegionPath = null;
      PartitionedRegion leaderRegion = null;
      String leaderRegionName = prRgion.getColocatedWith();
      if (leaderRegionName != null) {
        Cache cache = prRgion.getCache();
        while (leaderRegionName != null) {
          leaderRegion = (PartitionedRegion) cache.getRegion(leaderRegionName);
          if (leaderRegion.getColocatedWith() == null) {
            leaderRegionPath = leaderRegion.getFullPath();
            break;
          } else {
            leaderRegionName = leaderRegion.getColocatedWith();
          }
        }
      }
      responseMsg.addObjPart(leaderRegionPath);
      responseMsg.send();
      clientMessage.clearParts();
    } catch (Exception e) {
      writeException(clientMessage, e, false, serverConnection);
    } finally {
      serverConnection.setAsTrue(Command.RESPONDED);
    }
  }

}