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


Java DataUpdater类代码示例

本文整理汇总了Java中org.I0Itec.zkclient.DataUpdater的典型用法代码示例。如果您正苦于以下问题:Java DataUpdater类的具体用法?Java DataUpdater怎么用?Java DataUpdater使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: update

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
@Override
public boolean update(String path, DataUpdater<T> updater, int options) {
  String clientPath = path;
  String serverPath = prependChroot(clientPath);

  Cache<T> cache = getCache(serverPath);

  if (cache != null) {
    try {
      cache.lockWrite();
      ZkBaseDataAccessor<T>.AccessResult result =
          _baseAccessor.doUpdate(serverPath, updater, options);
      boolean success = (result._retCode == RetCode.OK);
      updateCache(cache, result._pathCreated, success, serverPath, result._updatedValue,
          result._stat);

      return success;
    } finally {
      cache.unlockWrite();
    }
  }

  // no cache
  return _groupCommit.commit(_baseAccessor, options, serverPath, updater);
  // return _baseAccessor.update(serverPath, updater, options);
}
 
开发者ID:apache,项目名称:helix,代码行数:27,代码来源:ZkCacheBaseDataAccessor.java

示例2: updateDataSerialized

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
/**
 * Updates data of an existing znode. The current content of the znode is passed to the {@link DataUpdater} that is
 * passed into this method, which returns the new content. The new content is only written back to ZooKeeper if
 * nobody has modified the given znode in between. If a concurrent change has been detected the new data of the
 * znode is passed to the updater once again until the new contents can be successfully written back to ZooKeeper.
 *
 * @param <T>
 * @param path
 *            The path of the znode.
 * @param updater
 *            Updater that creates the new contents.
 */
@SuppressWarnings("unchecked") public <T extends Object> void updateDataSerialized(String path,
    DataUpdater<T> updater) {
  Stat stat = new Stat();
  boolean retry;
  do {
    retry = false;
    try {
      T oldData = (T) readData(path, stat);
      T newData = updater.update(oldData);
      writeData(path, newData, stat.getVersion());
    } catch (ZkBadVersionException e) {
      retry = true;
    }
  } while (retry);
}
 
开发者ID:apache,项目名称:helix,代码行数:28,代码来源:ZkClient.java

示例3: setConstraint

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
@Override
public void setConstraint(String clusterName, final ConstraintType constraintType,
    final String constraintId, final ConstraintItem constraintItem) {
  BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkClient);

  Builder keyBuilder = new Builder(clusterName);
  String path = keyBuilder.constraint(constraintType.toString()).getPath();

  baseAccessor.update(path, new DataUpdater<ZNRecord>() {
    @Override
    public ZNRecord update(ZNRecord currentData) {
      ClusterConstraints constraints = currentData == null
          ? new ClusterConstraints(constraintType)
          : new ClusterConstraints(currentData);

      constraints.addConstraintItem(constraintId, constraintItem);
      return constraints.getRecord();
    }
  }, AccessOption.PERSISTENT);
}
 
开发者ID:apache,项目名称:helix,代码行数:21,代码来源:ZKHelixAdmin.java

示例4: removeConstraint

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
@Override
public void removeConstraint(String clusterName, final ConstraintType constraintType,
    final String constraintId) {
  BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkClient);

  Builder keyBuilder = new Builder(clusterName);
  String path = keyBuilder.constraint(constraintType.toString()).getPath();

  baseAccessor.update(path, new DataUpdater<ZNRecord>() {
    @Override
    public ZNRecord update(ZNRecord currentData) {
      if (currentData != null) {
        ClusterConstraints constraints = new ClusterConstraints(currentData);

        constraints.removeConstraintItem(constraintId);
        return constraints.getRecord();
      }
      return null;
    }
  }, AccessOption.PERSISTENT);
}
 
开发者ID:apache,项目名称:helix,代码行数:22,代码来源:ZKHelixAdmin.java

示例5: enableSingleInstance

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
private void enableSingleInstance(final String clusterName, final String instanceName,
    final boolean enabled, BaseDataAccessor<ZNRecord> baseAccessor) {
  String path = PropertyPathBuilder.instanceConfig(clusterName, instanceName);

  if (!baseAccessor.exists(path, 0)) {
    throw new HelixException("Cluster " + clusterName + ", instance: " + instanceName
        + ", instance config does not exist");
  }

  baseAccessor.update(path, new DataUpdater<ZNRecord>()

  {
    @Override
    public ZNRecord update(ZNRecord currentData) {
      if (currentData == null) {
        throw new HelixException("Cluster: " + clusterName + ", instance: " + instanceName
            + ", participant config is null");
      }

      InstanceConfig config = new InstanceConfig(currentData);
      config.setInstanceEnabled(enabled);
      return config.getRecord();
    }
  }, AccessOption.PERSISTENT);
}
 
开发者ID:apache,项目名称:helix,代码行数:26,代码来源:ZKHelixAdmin.java

示例6: updateProperty

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
@Override
public <T extends HelixProperty> boolean updateProperty(PropertyKey key, DataUpdater<ZNRecord> updater, T value) {
  PropertyType type = key.getType();
  String path = key.getPath();
  int options = constructOptions(type);

  boolean success = false;
  switch (type) {
  case CURRENTSTATES:
    success = _groupCommit.commit(_baseDataAccessor, options, path, value.getRecord(), true);
    break;
  case STATUSUPDATES:
    if (LOG.isTraceEnabled()) {
      LOG.trace("Update status. path: " + key.getPath() + ", record: " + value.getRecord());
    }
    break;
  default:
    success = _baseDataAccessor.update(path, updater, options);
    break;
  }
  return success;
}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:ZKHelixDataAccessor.java

示例7: createOrReplace

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

示例8: subtract

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
public static void subtract(ZkClient client, String path, final ZNRecord recordTosubtract) {
  int retryCount = 0;
  while (retryCount < RETRYLIMIT) {
    try {
      if (client.exists(path)) {
        DataUpdater<ZNRecord> updater = new DataUpdater<ZNRecord>() {
          @Override
          public ZNRecord update(ZNRecord currentData) {
            currentData.subtract(recordTosubtract);
            return currentData;
          }
        };
        client.updateDataSerialized(path, updater);
        break;
      }
    } catch (Exception e) {
      retryCount = retryCount + 1;
      logger.warn("Exception trying to createOrReplace " + path + ". Will retry.", e);
    }
  }

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

示例9: addTaskUserContent

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
/**
 * Add an user defined key-value pair data to task level
 *
 * @param manager       a connection to Helix
 * @param job   the name of job
 * @param task  the name of task
 * @param key           the key of key-value pair
 * @param value         the value of key-value pair
 */
protected static void addTaskUserContent(final HelixManager manager, String job,
    final String task, final String key, final String value) {
  String path =
      Joiner.on("/").join(TaskConstants.REBALANCER_CONTEXT_ROOT, job, USER_CONTENT_NODE);

  manager.getHelixPropertyStore().update(path, new DataUpdater<ZNRecord>() {
    @Override public ZNRecord update(ZNRecord znRecord) {
      if (znRecord.getMapField(task) == null) {
        znRecord.setMapField(task, new HashMap<String, String>());
      }
      znRecord.getMapField(task).put(key, value);
      return znRecord;
    }
  }, AccessOption.PERSISTENT);
}
 
开发者ID:apache,项目名称:helix,代码行数:25,代码来源:TaskUtil.java

示例10: update

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
@Override
public boolean update(String path, DataUpdater<T> updater, int options) {
  if (_fallbackStore == null) {
    return super.update(path, updater, options);
  } else {
    Stat stat = super.getStat(path, options);
    if (stat == null) {
      // create znode at new location with fallback-value
      T fallbackValue = _fallbackStore.get(path, null, options);
      boolean succeed = super.create(path, fallbackValue, AccessOption.PERSISTENT);
      if (!succeed) {
        LOG.error("Can't update " + path + " since there are concurrent updates");
        return false;
      }
    }
    return super.update(path, updater, options);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:19,代码来源:AutoFallbackPropertyStore.java

示例11: updateDataSerialized

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
/**
 * Updates data of an existing znode. The current content of the znode is passed to the {@link DataUpdater} that is
 * passed into this method, which returns the new content. The new content is only written back to ZooKeeper if
 * nobody has modified the given znode in between. If a concurrent change has been detected the new data of the
 * znode is passed to the updater once again until the new contents can be successfully written back to ZooKeeper.
 * 
 * @param <T>
 * @param path The path of the znode.
 * @param updater Updater that creates the new contents.
 */
public <T extends Object> void updateDataSerialized(String path, DataUpdater<T> updater) {
    Stat stat = new Stat();
    boolean retry;
    do {
        retry = false;
        try {
            T oldData = (T) readData(path, stat);
            T newData = updater.update(oldData);
            writeData(path, newData, stat.getVersion());
        } catch (ZkBadVersionException e) {
            retry = true;
        }
    } while (retry);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:25,代码来源:ZkClientx.java

示例12: updateNote

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
/**
 * 修改节点数据
 * 
 * @param path
 * @param data
 */
public boolean updateNote(String path, final Object data) {
	if (zkClient.exists(path)) {
		zkClient.updateDataSerialized(path, new DataUpdater<Object>() {
			public Object update(Object currentData) {
				currentData = data;
				return currentData;
			}
		});
		return true;
	} else {
		LOGGER.warn("update path = " + path + " exists!");
		return false;
	}
}
 
开发者ID:hncdyj123,项目名称:config-manager,代码行数:21,代码来源:ZkClientConnect.java

示例13: updateChildren

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
@Override
public boolean[] updateChildren(List<String> paths, List<DataUpdater<T>> updaters, int options) {
  final int size = paths.size();
  List<String> serverPaths = prependChroot(paths);

  Cache<T> cache = getCache(serverPaths);
  if (cache != null) {
    try {
      cache.lockWrite();

      List<Stat> setStats = new ArrayList<Stat>();
      boolean[] success = new boolean[size];
      List<List<String>> pathsCreatedList =
          new ArrayList<List<String>>(Collections.<List<String>> nCopies(size, null));
      List<T> updateData =
          _baseAccessor.update(serverPaths, updaters, pathsCreatedList, setStats, options);

      // System.out.println("updateChild: ");
      // for (T data : updateData)
      // {
      // System.out.println(data);
      // }

      for (int i = 0; i < size; i++) {
        success[i] = (updateData.get(i) != null);
        updateCache(cache, pathsCreatedList.get(i), success[i], serverPaths.get(i),
            updateData.get(i), setStats.get(i));
      }
      return success;
    } finally {
      cache.unlockWrite();
    }
  }

  // no cache
  return _baseAccessor.updateChildren(serverPaths, updaters, options);
}
 
开发者ID:apache,项目名称:helix,代码行数:38,代码来源:ZkCacheBaseDataAccessor.java

示例14: updateChildren

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
/**
 * async update
 */
@Override
public boolean[] updateChildren(List<String> paths, List<DataUpdater<T>> updaters, int options) {

  List<T> updateData = update(paths, updaters, null, null, options);
  boolean[] success = new boolean[paths.size()]; // init to false
  for (int i = 0; i < paths.size(); i++) {
    T data = updateData.get(i);
    success[i] = (data != null);
  }
  return success;
}
 
开发者ID:apache,项目名称:helix,代码行数:15,代码来源:ZkBaseDataAccessor.java

示例15: updateIfExists

import org.I0Itec.zkclient.DataUpdater; //导入依赖的package包/类
public static void updateIfExists(ZkClient client, String path, final ZNRecord record,
    boolean mergeOnUpdate) {
  if (client.exists(path)) {
    DataUpdater<Object> updater = new DataUpdater<Object>() {
      @Override
      public Object update(Object currentData) {
        return record;
      }
    };
    client.updateDataSerialized(path, updater);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:13,代码来源:ZKUtil.java


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