final CuratorOp deleteOp = curator.transactionOp().delete().forPath(testPath1); final Collection<CuratorTransactionResult> results = curator.transaction().forOperations(deleteOp); Assert.assertEquals(1, results.size());
public static Collection<CuratorTransactionResult> transaction(CuratorFramework client) throws Exception { // this example shows how to use ZooKeeper's transactions CuratorOp createOp = client.transactionOp().create().forPath("/a/path", "some data".getBytes()); CuratorOp setDataOp = client.transactionOp().setData().forPath("/another/path", "other data".getBytes()); CuratorOp deleteOp = client.transactionOp().delete().forPath("/yet/another/path"); Collection<CuratorTransactionResult> results = client.transaction().forOperations(createOp, setDataOp, deleteOp); for ( CuratorTransactionResult result : results ) { System.out.println(result.getForPath() + " - " + result.getType()); } return results; } }
private CuratorOp internalForPath(String path, byte[] data, boolean useData) { TransactionCreateBuilder2<CuratorOp> builder1 = (ttl > 0) ? client.transactionOp().create().withTtl(ttl) : client.transactionOp().create(); ACLPathAndBytesable<CuratorOp> builder2 = compressed ? builder1.compressed().withMode(createMode) : builder1.withMode(createMode); PathAndBytesable<CuratorOp> builder3 = builder2.withACL(aclList); try { return useData ? builder3.forPath(path, data) : builder3.forPath(path); } catch ( Exception e ) { throw new RuntimeException(e); // should never happen } } };
private CuratorOp internalForPath(String path, byte[] data, boolean useData) { TransactionSetDataBuilder<CuratorOp> builder1 = client.transactionOp().setData(); VersionPathAndBytesable<CuratorOp> builder2 = compressed ? builder1.compressed() : builder1; PathAndBytesable<CuratorOp> builder3 = builder2.withVersion(version); try { return useData ? builder3.forPath(path, data) : builder3.forPath(path); } catch ( Exception e ) { throw new RuntimeException(e); // should never happen } } };
@Override public CuratorOp forPath(String path) { try { return client.transactionOp().check().withVersion(version).forPath(path); } catch ( Exception e ) { throw new RuntimeException(e); // should never happen } } };
public static Collection<CuratorTransactionResult> transaction(CuratorFramework client) throws Exception { // // this example shows how to use ZooKeeper's new transactions // Collection<CuratorTransactionResult> results = client.inTransaction().create().forPath("/a/path", "some data".getBytes()) // .and().setData().forPath("/another/path", "other data".getBytes()) // .and().delete().forPath("/yet/another/path") // .and().commit(); // IMPORTANT! //inTransaction is deprecated. use transaction() instead List<CuratorTransactionResult> results = client.transaction().forOperations( client.transactionOp().create().forPath("/a/path", "some data".getBytes()), client.transactionOp().setData().forPath("/another/path", "other data".getBytes()), client.transactionOp().delete().forPath("/yet/another/path")); // called for (CuratorTransactionResult result : results) { System.out.println(result.getForPath() + " - " + result.getType()); } return results; } }
@Override public CuratorOp forPath(String path) { try { return client.transactionOp().delete().withVersion(version).forPath(path); } catch ( Exception e ) { throw new RuntimeException(e); // should never happen } } };