当前位置: 首页>>代码示例>>Java>>正文


Java ZNRecord.merge方法代码示例

本文整理汇总了Java中org.apache.helix.ZNRecord.merge方法的典型用法代码示例。如果您正苦于以下问题:Java ZNRecord.merge方法的具体用法?Java ZNRecord.merge怎么用?Java ZNRecord.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.helix.ZNRecord的用法示例。


在下文中一共展示了ZNRecord.merge方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Override
public ZNRecord update(ZNRecord currentData) {
  ZNRecord newRec = new ZNRecord(message.getResourceName());

  if (currentData != null) {
    int currentGen = convertToInt(newRec.getSimpleField("currentGen"), 0);
    int currentGenStartSeq = convertToInt(newRec.getSimpleField("currentGenStartSeq"), 0);
    int prevGen = convertToInt(newRec.getSimpleField("prevGen"), 0);
    int prevGenEndSeq = convertToInt(newRec.getSimpleField("prevGenEndSeq"), 0);
    newRec.setSimpleField("currentGen", Integer.toString(currentGen + 1));
    newRec.setSimpleField("currentGenStartSeq", Integer.toString(1));
    if (currentGen > 0) {
      newRec.setSimpleField("prevGen", Integer.toString(currentGen));
      int localEndSeq = 1;
      newRec.setSimpleField("prevGenEndSeq", "" + localEndSeq);
    }
    newRec.merge(currentData);
  } else {
    newRec.setSimpleField("currentGen", Integer.toString(1));
    newRec.setSimpleField("currentGenStartSeq", Integer.toString(1));
  }
  return newRec;
}
 
开发者ID:kishoreg,项目名称:fullmatix,代码行数:24,代码来源:MasterSlaveTransitionHandler.java

示例2: createOrMerge

import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
public static void createOrMerge(ZkClient client, String path, final ZNRecord record,
    final boolean persistent, final boolean mergeOnUpdate) {
  int retryCount = 0;
  while (retryCount < RETRYLIMIT) {
    try {
      if (client.exists(path)) {
        DataUpdater<ZNRecord> updater = new DataUpdater<ZNRecord>() {
          @Override
          public ZNRecord update(ZNRecord currentData) {
            if (currentData != null && mergeOnUpdate) {
              currentData.merge(record);
              return currentData;
            }
            return record;
          }
        };
        client.updateDataSerialized(path, updater);
      } else {
        CreateMode mode = (persistent) ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL;
        if (record.getDeltaList().size() > 0) {
          ZNRecord value = new ZNRecord(record.getId());
          value.merge(record);
          client.create(path, value, mode);
        } else {
          client.create(path, record, mode);
        }
      }
      break;
    } catch (Exception e) {
      retryCount = retryCount + 1;
      logger.warn("Exception trying to update " + path + " Exception:" + e.getMessage()
          + ". Will retry.");
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:36,代码来源:ZKUtil.java

示例3: asyncCreateOrMerge

import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
public static void asyncCreateOrMerge(ZkClient client, String path, final ZNRecord record,
    final boolean persistent, final boolean mergeOnUpdate) {
  try {
    if (client.exists(path)) {
      if (mergeOnUpdate) {
        ZNRecord curRecord = client.readData(path);
        if (curRecord != null) {
          curRecord.merge(record);
          client.asyncSetData(path, curRecord, -1, null);
        } else {
          client.asyncSetData(path, record, -1, null);
        }
      } else {
        client.asyncSetData(path, record, -1, null);
      }
    } else {
      CreateMode mode = (persistent) ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL;
      if (record.getDeltaList().size() > 0) {
        ZNRecord newRecord = new ZNRecord(record.getId());
        newRecord.merge(record);
        client.create(path, null, mode);

        client.asyncSetData(path, newRecord, -1, null);
      } else {
        client.create(path, null, mode);

        client.asyncSetData(path, record, -1, null);
      }
    }
  } catch (Exception e) {
    logger.error("Exception in async create or update " + path + ". Exception: " + e.getMessage()
        + ". Give up.");
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:35,代码来源:ZKUtil.java

示例4: update

import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Override
public ZNRecord update(ZNRecord currentData) {
  ZNRecord newRec = new ZNRecord(message.getResourceName());

  if (currentData != null) {
    int currentGen = convertToInt(newRec.getSimpleField("currentGen"), 0);
    int currentGenStartSeq = convertToInt(newRec.getSimpleField("currentGenStartSeq"), 0);
    int prevGen = convertToInt(newRec.getSimpleField("prevGen"), 0);
    int prevGenEndSeq = convertToInt(newRec.getSimpleField("prevGenEndSeq"), 0);
    newRec.setSimpleField("currentGen", Integer.toString(currentGen + 1));
    newRec.setSimpleField("currentGenStartSeq", Integer.toString(1));
    if (currentGen > 0) {
      newRec.setSimpleField("prevGen", Integer.toString(currentGen));
      int localEndSeq = 1;
      if (lastRecordProcessed != null) {
        localEndSeq = (int) lastRecordProcessed.txid;
      }
      newRec.setSimpleField("prevGenEndSeq", "" + localEndSeq);
    }
    newRec.merge(currentData);
  } else {
    newRec.setSimpleField("currentGen", Integer.toString(1));
    newRec.setSimpleField("currentGenStartSeq", Integer.toString(1));
  }
  return newRec;

}
 
开发者ID:apache,项目名称:helix,代码行数:28,代码来源:FileStoreStateModel.java

示例5: getHostedEntitiesRepresentation

import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
StringRepresentation getHostedEntitiesRepresentation(String clusterName, String jobQueueName)
    throws Exception {
  ZkClient zkClient =
      ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
  HelixDataAccessor accessor =
      ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();

  TaskDriver taskDriver = new TaskDriver(zkClient, clusterName);

  // Get job queue config
  // TODO: fix this to use workflowConfig.
  ResourceConfig jobQueueConfig = accessor.getProperty(keyBuilder.resourceConfig(jobQueueName));

  // Get job queue context
  WorkflowContext ctx = taskDriver.getWorkflowContext(jobQueueName);

  // Create the result
  ZNRecord hostedEntitiesRecord = new ZNRecord(jobQueueName);
  if (jobQueueConfig != null) {
    hostedEntitiesRecord.merge(jobQueueConfig.getRecord());
  }
  if (ctx != null) {
    hostedEntitiesRecord.merge(ctx.getRecord());
  }

  StringRepresentation representation =
      new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord),
          MediaType.APPLICATION_JSON);

  return representation;
}
 
开发者ID:apache,项目名称:helix,代码行数:33,代码来源:JobQueueResource.java

示例6: getHostedEntitiesRepresentation

import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
StringRepresentation getHostedEntitiesRepresentation(String clusterName, String jobQueueName,
    String jobName) throws Exception {

  ZkClient zkClient =
      ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
  HelixDataAccessor accessor =
      ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();

  // Get job queue config
  String namespacedJobName = TaskUtil.getNamespacedJobName(jobQueueName, jobName);
  HelixProperty jobConfig = accessor.getProperty(keyBuilder.resourceConfig(namespacedJobName));

  TaskDriver taskDriver = new TaskDriver(zkClient, clusterName);

  // Get job queue context
  JobContext ctx = taskDriver.getJobContext(namespacedJobName);

  // Create the result
  ZNRecord hostedEntitiesRecord = new ZNRecord(namespacedJobName);
  if (jobConfig != null) {
    hostedEntitiesRecord.merge(jobConfig.getRecord());
  }
  if (ctx != null) {
    hostedEntitiesRecord.merge(ctx.getRecord());
  }

  StringRepresentation representation =
      new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord),
          MediaType.APPLICATION_JSON);

  return representation;
}
 
开发者ID:apache,项目名称:helix,代码行数:34,代码来源:JobResource.java

示例7: testMerge

import org.apache.helix.ZNRecord; //导入方法依赖的package包/类
@Test
public void testMerge() {
  ZNRecord record = new ZNRecord("record1");

  // set simple field
  record.setSimpleField("simpleKey1", "simpleValue1");

  // set list field
  List<String> list1 = new ArrayList<String>();
  list1.add("list1Value1");
  list1.add("list1Value2");
  record.setListField("listKey1", list1);

  // set map field
  Map<String, String> map1 = new HashMap<String, String>();
  map1.put("map1Key1", "map1Value1");
  record.setMapField("mapKey1", map1);
  // System.out.println(record);

  ZNRecord updateRecord = new ZNRecord("updateRecord");

  // set simple field
  updateRecord.setSimpleField("simpleKey2", "simpleValue2");

  // set list field
  List<String> newList1 = new ArrayList<String>();
  newList1.add("list1Value1");
  newList1.add("list1Value2");
  newList1.add("list1NewValue1");
  newList1.add("list1NewValue2");
  updateRecord.setListField("listKey1", newList1);

  List<String> list2 = new ArrayList<String>();
  list2.add("list2Value1");
  list2.add("list2Value2");
  updateRecord.setListField("listKey2", list2);

  // set map field
  Map<String, String> newMap1 = new HashMap<String, String>();
  newMap1.put("map1NewKey1", "map1NewValue1");
  updateRecord.setMapField("mapKey1", newMap1);

  Map<String, String> map2 = new HashMap<String, String>();
  map2.put("map2Key1", "map2Value1");
  updateRecord.setMapField("mapKey2", map2);
  // System.out.println(updateRecord);

  record.merge(updateRecord);
  // System.out.println(record);

  ZNRecord expectRecord = new ZNRecord("record1");
  expectRecord.setSimpleField("simpleKey1", "simpleValue1");
  expectRecord.setSimpleField("simpleKey2", "simpleValue2");
  List<String> expectList1 = new ArrayList<String>();
  expectList1.add("list1Value1");
  expectList1.add("list1Value2");
  expectList1.add("list1Value1");
  expectList1.add("list1Value2");
  expectList1.add("list1NewValue1");
  expectList1.add("list1NewValue2");
  expectRecord.setListField("listKey1", expectList1);
  List<String> expectList2 = new ArrayList<String>();
  expectList2.add("list2Value1");
  expectList2.add("list2Value2");
  expectRecord.setListField("listKey2", expectList2);
  Map<String, String> expectMap1 = new HashMap<String, String>();
  expectMap1.put("map1Key1", "map1Value1");
  expectMap1.put("map1NewKey1", "map1NewValue1");
  expectRecord.setMapField("mapKey1", expectMap1);
  Map<String, String> expectMap2 = new HashMap<String, String>();
  expectMap2.put("map2Key1", "map2Value1");
  expectRecord.setMapField("mapKey2", expectMap2);
  Assert.assertEquals(record, expectRecord, "Should be equal.");
}
 
开发者ID:apache,项目名称:helix,代码行数:75,代码来源:TestZNRecord.java


注:本文中的org.apache.helix.ZNRecord.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。