public void setData(String path, byte[] data, int version) throws Exception { transactionFinal = transactionFinal.setData() .withVersion(version).forPath(path, data).and(); } }
@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 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); } }
@Override public void register(final CuratorTransaction transaction) throws Exception { transaction .create().forPath(path).and() .setData().withVersion(version).forPath(path, data); }
/** * 更新数据 * * @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); } }
@Override public TransactionSetDataBuilder setData() { return new TransactionSetDataBuilderDecorator(inner.setData()); }
public CuratorTransactionFinal build( CuratorFramework client, String serviceRootPath ) throws Exception { // List of paths that are known to exist, or which are about to be created by the transaction // Includes "known to exist" in order to avoid repeated lookups for the same path Set<String> existingAndPendingCreatePaths = new HashSet<>(); CuratorTransactionFinal transaction = client .inTransaction() .check() .forPath(serviceRootPath) .and(); for (Map.Entry<String, byte[]> entry : pathBytesMap.entrySet()) { String path = entry.getKey(); if (!existingAndPendingCreatePaths.contains(path) && client.checkExists().forPath(path) == null) { // Path does not exist and is not being created: Create value (and any parents as needed). transaction = createParentsOf(client, path, transaction, existingAndPendingCreatePaths) .create().forPath(path, entry.getValue()).and(); existingAndPendingCreatePaths.add(path); } else { // Path exists (or will exist): Update existing value. transaction = transaction.setData().forPath(path, entry.getValue()).and(); } } return transaction; } }
@Override public void register(final CuratorTransaction transaction) throws Exception { transaction .create().forPath(path).and() .setData().withVersion(version).forPath(path, data); }
private synchronized SchemaEntry createNewSchema(String schema) { try { // TODO: Make IDs String across the board (not Integer), // TODO: Add pluggable ID generation schemes List<Integer> allSchemaIds = getSchemaIds(); Integer newId = getLatestSchemaId(allSchemaIds) + 1; allSchemaIds.add(newId); byte[] newSchemaFile = schema.getBytes(); byte[] newSchemaIdsFile = serializeSchemaIds(allSchemaIds).getBytes(); // Create new schema and update schema IDs file in one ZK transaction zkClient.inTransaction(). create().forPath(getSchemaFilePath(newId.toString()), newSchemaFile). and(). setData().forPath(getSchemaIdsFilePath(), newSchemaIdsFile). and().commit(); // TODO: Keep new schema in a local cache return new SchemaEntry(String.valueOf(newId), schema); } catch (Exception e) { throw new RuntimeException( "An exception occurred while accessing ZK!", e); } }
@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); } }
@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); } }
@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 throw new EagleFrameException(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); } }
@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); } }
@Override public void update(final String key, final String value) { try { client.inTransaction().check().forPath(key).and().setData().forPath(key, value.getBytes(StandardCharsets.UTF_8)).and().commit(); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON RegExceptionHandler.handleException(ex); } }
@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); } }
@Override public void write(StateMachineContext<S,E> context, Stat stat) { byte[] data = serialize(context); CuratorTransaction tx = curatorClient.inTransaction(); try { CuratorTransactionFinal tt = tx.setData().withVersion(stat.getVersion()).forPath(path, data).and(); if (logPath != null) { tt = tt.setData().forPath(logPath + "/" + stat.getVersion() % logSize, data).and(); } Collection<CuratorTransactionResult> results = tt.commit(); int version = results.iterator().next().getResultStat().getVersion(); stat.setVersion(version); } catch (Exception e) { throw new StateMachineException("Error persisting data", e); } }
.setData().forPath(ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath(), PasswordEncoder.encode(options.getZookeeperPassword()).getBytes(Charsets.UTF_8)) .and() .setData().forPath(ZkPath.CONFIG_ENSEMBLE_URL.getPath(), connectionUrl.getBytes(Charsets.UTF_8)) .and().commit();