Пример #1
0
  /**
   * @param inTag
   * @param inVariable
   * @param inData
   * @return
   */
  public static Message createRequestMessage(
      int inTag,
      long inType,
      String inService,
      String inVariable,
      IPersistentMap<String, DataType<?>> inData) {

    RequestMessage.Builder builder = RequestMessage.newBuilder();
    builder.setTag(inTag);
    builder.setService(inService);

    if (inVariable != null) builder.setVariable(inVariable);

    if (inData != null) {
      DataMap.Builder dataMapBuilder = DataMap.newBuilder();
      parseMapValues(inData, dataMapBuilder);

      builder.setData(dataMapBuilder.build());
      builder.setType(inType);
    }

    Message.Builder messBuilder = Message.newBuilder();
    messBuilder.setType(Message.Type.RequestMessage);
    messBuilder.setRequestMessage(builder.build());

    return messBuilder.build();
  }
Пример #2
0
  /**
   * @param inTag
   * @param inRef
   * @param inStatus
   * @param inEntry
   * @return
   */
  public static Message createSubResponse(
      Long inTag, int inRef, Status inStatus, ISTMEntryKey inKey, ISTMEntry inEntry) {

    SubQueryResponseMessage.Builder builder = SubQueryResponseMessage.newBuilder();
    builder.setReference(inRef);
    builder.setTag(inTag.intValue());
    builder.setStatus(inStatus.ordinal());

    if (inEntry != null) {
      DataMap.Builder dataBuilder = DataMap.newBuilder();
      parseMapValues(inEntry.getDataMap(), dataBuilder);
      builder.setData(dataBuilder.build());
    }

    if (inKey != null) {
      DataKey dKey = createDataKey(inKey);

      builder.setKey(dKey);
    }

    Message.Builder messBuilder = Message.newBuilder();
    messBuilder.setSubQueryResponseMessage(builder.build());
    messBuilder.setType(Message.Type.SubQueryResponseMessage);

    return messBuilder.build();
  }
Пример #3
0
  /**
   * @param inRef
   * @param inDataMap
   * @return
   */
  public static Message createUpdateMessage(
      int inRef, ISTMEntry inEntry, boolean inFullUpdate, ISTMEntryKey inKey) {
    IPersistentMap<String, DataType<?>> dataMap = inEntry.getDataMap();

    UpdateMessage.Builder builder = UpdateMessage.newBuilder();
    builder.setReference(inRef);
    builder.setFullupdate(inFullUpdate);

    DataMap.Builder dataMapBuilder = DataMap.newBuilder();

    if (inFullUpdate) {
      parseMapValues(dataMap, dataMapBuilder);
    } else {
      parseDeltaMapValues(dataMap, inEntry.getDeltaSet(), dataMapBuilder);
    }

    builder.setData(dataMapBuilder.build());

    if (inKey != null) {
      DataKey dKey = createDataKey(inKey);
    }

    Message.Builder messBuilder = Message.newBuilder();
    try {
      messBuilder.setUpdateMessage(builder.build());
    } catch (Throwable t) {
      t.printStackTrace();
    }
    messBuilder.setType(Message.Type.UpdateMessage);

    return messBuilder.build();
  }
Пример #4
0
  /**
   * @param inData
   * @param inField
   * @param inValue
   */
  public static void addStringValue(DataMap.Builder inData, String inField, String inValue) {
    StringEntry.Builder strEntryBuilder = StringEntry.newBuilder();
    strEntryBuilder.setData(inValue);
    strEntryBuilder.setField(inField);

    inData.addStringEntries(strEntryBuilder.build());
  }
Пример #5
0
  private static void parseReference(
      String inFieldKey, ISTMEntryKey entryKey, DataMap.Builder inBuilder, boolean inLazy) {
    ReferenceEntry.Builder refBuilder = ReferenceEntry.newBuilder();

    DataKey key = createDataKey(entryKey);

    refBuilder.setField(inFieldKey);
    refBuilder.setKey(key);
    refBuilder.setLazy(inLazy);

    inBuilder.addRefEntries(refBuilder.build());
  }
Пример #6
0
  /**
   * @param inKey
   * @param inData
   * @param inBuilder
   */
  public static void parseValueToMap(String inKey, DataType<?> inData, DataMap.Builder inBuilder) {
    if (inData instanceof DataTypeString) {
      StringEntry.Builder strBuilder = StringEntry.newBuilder();
      strBuilder.setField(inKey);
      strBuilder.setData(((DataTypeString) inData).get());
      inBuilder.addStringEntries(strBuilder.build());
    } else if (inData instanceof DataTypeBigDecimal) {
      DataTypeBigDecimal bd = (DataTypeBigDecimal) inData;
      BigDecimalEntry.Builder bdBuilder = BigDecimalEntry.newBuilder();
      bdBuilder.setField(inKey);
      bdBuilder.setScale(bd.get().scale());
      bdBuilder.setIntBytes(ByteString.copyFrom(bd.get().unscaledValue().toByteArray()));
      inBuilder.addBDEntries(bdBuilder.build());
    }
    if (inData instanceof DataTypeLong) {
      LongEntry.Builder longBuilder = LongEntry.newBuilder();
      longBuilder.setField(inKey);
      longBuilder.setData(((DataTypeLong) inData).get());
      inBuilder.addLongEntries(longBuilder.build());
    }
    if (inData instanceof DataTypeBoolean) {
      BooleanEntry.Builder booleanBuilder = BooleanEntry.newBuilder();
      booleanBuilder.setField(inKey);
      booleanBuilder.setData(((DataTypeBoolean) inData).get());
      inBuilder.addBoolEntries(booleanBuilder.build());
    }
    if (inData instanceof DataTypeNull) {
      NullEntry.Builder nullBuilder = NullEntry.newBuilder();
      nullBuilder.setField(inKey);
      inBuilder.addNullEntries(nullBuilder.build());
    }
    if (inData instanceof DataTypeHashMap) {
      HashMapEntry.Builder dataMapBuilder = HashMapEntry.newBuilder();
      dataMapBuilder.setField(inKey);

      DataTypeHashMap hashMap = (DataTypeHashMap) inData;
      DataMap.Builder hashMapBuilder = DataMap.newBuilder();

      parseMapValues(hashMap.get(), hashMapBuilder);

      dataMapBuilder.setData(hashMapBuilder.build());

      inBuilder.addHashMapEntries(dataMapBuilder.build());
    }
    if (inData instanceof DataTypeArrayList) {
      HashMapEntry.Builder dataMapBuilder = HashMapEntry.newBuilder();
      dataMapBuilder.setField(inKey);
      dataMapBuilder.setList(true);

      DataTypeArrayList list = (DataTypeArrayList) inData;
      DataMap.Builder hashMapBuilder = DataMap.newBuilder();

      parseListValues((PersistentArrayList<DataType<?>>) list.get(), hashMapBuilder);

      dataMapBuilder.setData(hashMapBuilder.build());

      inBuilder.addHashMapEntries(dataMapBuilder.build());
    } else if (inData instanceof DataTypeStatus) {
      inBuilder.setStatus(((DataTypeStatus) inData).get().ordinal());
    } else if (inData instanceof DataTypeRef) {
      ISTMEntryKey entryKey = ((DataTypeRef) inData).get();
      parseReference(inKey, entryKey, inBuilder, false);
    } else if (inData instanceof DataTypeLazyRef) {
      ISTMEntryKey entryKey = ((DataTypeLazyRef) inData).get();
      parseReference(inKey, entryKey, inBuilder, true);
    }
  }