@Override public void update(final String key, final String value) { try { client.inTransaction().check().forPath(key).and().setData().forPath(key, value.getBytes(Charsets.UTF_8)).and().commit(); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON CuratorZookeeperExceptionHandler.handleException(ex); } }
@Override public void register(final CuratorTransaction transaction) throws Exception { transaction .create().forPath(path).and() .setData().withVersion(version).forPath(path, data); }
@Override public void execute(final CuratorTransactionFinal curatorTransactionFinal) throws Exception { for (Map.Entry<JobInstance, List<Integer>> entry : shardingResults.entrySet()) { for (int shardingItem : entry.getValue()) { curatorTransactionFinal.create().forPath(jobNodePath.getFullPath(ShardingNode.getInstanceNode(shardingItem)), entry.getKey().getJobInstanceId().getBytes()).and(); } } curatorTransactionFinal.delete().forPath(jobNodePath.getFullPath(ShardingNode.NECESSARY)).and(); curatorTransactionFinal.delete().forPath(jobNodePath.getFullPath(ShardingNode.PROCESSING)).and(); } }
/** * 在事务中执行操作. * * @param callback 执行操作的回调 */ public void executeInTransaction(final TransactionExecutionCallback callback) { try { CuratorTransactionFinal curatorTransactionFinal = getClient().inTransaction().check().forPath("/").and(); callback.execute(curatorTransactionFinal); curatorTransactionFinal.commit(); //CHECKSTYLE:OFF } catch (final Exception ex) { //CHECKSTYLE:ON RegExceptionHandler.handleException(ex); } }
/** * Unannounces an announcement created at path. Note that if all announcements get removed, the Announcer * will continue to have ZK watches on paths because clearing them out is a source of ugly race conditions. * <p/> * If you need to completely clear all the state of what is being watched and announced, stop() the Announcer. * * @param path the path to unannounce */ public void unannounce(String path) { log.info("unannouncing [%s]", path); final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.remove(pathAndNode.getNode()) == null) { log.error("Path[%s] not announced, cannot unannounce.", path); return; } try { curator.inTransaction().delete().forPath(path).and().commit(); } catch (KeeperException.NoNodeException e) { log.info("node[%s] didn't exist anyway...", path); } catch (Exception e) { throw Throwables.propagate(e); } }
public void setData(String path, byte[] data, int version) throws Exception { transactionFinal = transactionFinal.setData() .withVersion(version).forPath(path, data).and(); } }
SafeTransaction(List<ACL> fencingACL, String fencingNodePath) throws Exception { this.fencingNodePath = fencingNodePath; CuratorTransaction transaction = curator.inTransaction(); transactionFinal = transaction.create() .withMode(CreateMode.PERSISTENT).withACL(fencingACL) .forPath(fencingNodePath, new byte[0]).and(); }
@Override public void register(final CuratorTransaction transaction) throws Exception { transaction.check().withVersion(version).forPath(path); }
@Override public void update(final String key, final String value) { try { client.inTransaction().check().forPath(key).and().setData().forPath(key, value.getBytes(Charsets.UTF_8)).and().commit(); //CHECKSTYLE:OFF } catch (final Exception ex) { //CHECKSTYLE:ON RegExceptionHandler.handleException(ex); } }
/** * 更新数据 * * @param key * @param value */ public void update(final String key, final String value) { try { /*TransactionOp op = client.transactionOp(); client.transaction().forOperations( op.check().forPath(key), op.setData().forPath(key, value.getBytes(Constants.UTF_8)) );*/ client.inTransaction().check().forPath(key).and().setData().forPath(key, value.getBytes(Constants.UTF_8)).and().commit(); } catch (Exception ex) { Logs.RSD.error("update:{},{}", key, value, ex); throw new ZKException(ex); } }