Permalink
Browse files

some more transaction examples

  • Loading branch information...
1 parent a65234d commit 0122a66e99e00b37dff2e18d05cdde42e495af20 @Randgalt Randgalt committed Oct 30, 2012
Showing with 31 additions and 0 deletions.
  1. +31 −0 curator-examples/src/main/java/framework/TransactionExamples.java
View
31 curator-examples/src/main/java/framework/TransactionExamples.java
@@ -17,6 +17,8 @@
package framework;
import com.netflix.curator.framework.CuratorFramework;
+import com.netflix.curator.framework.api.transaction.CuratorTransaction;
+import com.netflix.curator.framework.api.transaction.CuratorTransactionFinal;
import com.netflix.curator.framework.api.transaction.CuratorTransactionResult;
import java.util.Collection;
@@ -42,4 +44,33 @@
return results;
}
+
+ /*
+ These next four methods show how to use Curator's transaction APIs in a more
+ traditional - one-at-a-time - manner
+ */
+
+ public static CuratorTransaction startTransaction(CuratorFramework client)
+ {
+ // start the transaction builder
+ return client.inTransaction();
+ }
+
+ public static CuratorTransactionFinal addCreateToTransaction(CuratorTransaction transaction) throws Exception
+ {
+ // add a create operation
+ return transaction.create().forPath("/a/path", "some data".getBytes()).and();
+ }
+
+ public static CuratorTransactionFinal addDeleteToTransaction(CuratorTransaction transaction) throws Exception
+ {
+ // add a delete operation
+ return transaction.delete().forPath("/another/path").and();
+ }
+
+ public static void commitTransaction(CuratorTransactionFinal transaction) throws Exception
+ {
+ // commit the transaction
+ transaction.commit();
+ }
}

0 comments on commit 0122a66

Please sign in to comment.