/**
   * @param po Portable object.
   * @return Affinity key.
   */
  public Object affinityKey(BinaryObject po) {
    try {
      BinaryType meta = po.type();

      if (meta != null) {
        String affKeyFieldName = meta.affinityKeyFieldName();

        if (affKeyFieldName != null) return po.field(affKeyFieldName);
      } else if (po instanceof BinaryObjectEx) {
        int id = ((BinaryObjectEx) po).typeId();

        String affKeyFieldName = portableCtx.affinityKeyFieldName(id);

        if (affKeyFieldName != null) return po.field(affKeyFieldName);
      }
    } catch (BinaryObjectException e) {
      U.error(log, "Failed to get affinity field from portable object: " + po, e);
    }

    return po;
  }