@Override public boolean apply(CuratorTransactionResult result) { return (result.getType() == type) && result.getForPath().equals(forPath); } };
@Override public boolean apply(CuratorTransactionResult result) { return (result.getType() == type) && result.getForPath().equals(forPath); } };
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; } }
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; } }