curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject curator git commit: Updated example and some other wip
Date Tue, 12 May 2015 19:46:12 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-215 7d038ad5c -> 854c0b5df


Updated example and some other wip


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/854c0b5d
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/854c0b5d
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/854c0b5d

Branch: refs/heads/CURATOR-215
Commit: 854c0b5dff875c02c40e04977abf50e9dd833d94
Parents: 7d038ad
Author: randgalt <randgalt@apache.org>
Authored: Tue May 12 14:46:06 2015 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Tue May 12 14:46:06 2015 -0500

----------------------------------------------------------------------
 .../java/framework/TransactionExamples.java     | 50 ++++----------------
 .../framework/imps/ExtractingCuratorOp.java     |  5 --
 .../framework/imps/TransactionOpImpl.java       |  8 ++--
 3 files changed, 14 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/854c0b5d/curator-examples/src/main/java/framework/TransactionExamples.java
----------------------------------------------------------------------
diff --git a/curator-examples/src/main/java/framework/TransactionExamples.java b/curator-examples/src/main/java/framework/TransactionExamples.java
index f559b5a..7ff8064 100644
--- a/curator-examples/src/main/java/framework/TransactionExamples.java
+++ b/curator-examples/src/main/java/framework/TransactionExamples.java
@@ -19,25 +19,24 @@
 package framework;
 
 import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.api.transaction.CuratorTransaction;
-import org.apache.curator.framework.api.transaction.CuratorTransactionFinal;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.transaction.CuratorOp;
 import org.apache.curator.framework.api.transaction.CuratorTransactionResult;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.TestingServer;
 import java.util.Collection;
 
 public class TransactionExamples
 {
     public static Collection<CuratorTransactionResult>      transaction(CuratorFramework
client) throws Exception
     {
-        // this example shows how to use ZooKeeper's new transactions
+        // this example shows how to use ZooKeeper's 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! The transaction is not submitted until commit()
is called
+        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 )
         {
@@ -46,33 +45,4 @@ public class TransactionExamples
 
         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();
-    }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/854c0b5d/curator-framework/src/main/java/org/apache/curator/framework/imps/ExtractingCuratorOp.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/ExtractingCuratorOp.java
b/curator-framework/src/main/java/org/apache/curator/framework/imps/ExtractingCuratorOp.java
index 40bd8c8..7a5db69 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/ExtractingCuratorOp.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/ExtractingCuratorOp.java
@@ -32,11 +32,6 @@ class ExtractingCuratorOp implements CuratorOp
         return record;
     }
 
-    CuratorOp asCuratorOp()
-    {
-        return this;
-    }
-
     @Override
     public TypeAndPath getTypeAndPath()
     {

http://git-wip-us.apache.org/repos/asf/curator/blob/854c0b5d/curator-framework/src/main/java/org/apache/curator/framework/imps/TransactionOpImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/TransactionOpImpl.java
b/curator-framework/src/main/java/org/apache/curator/framework/imps/TransactionOpImpl.java
index e0ada17..381842b 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/TransactionOpImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/TransactionOpImpl.java
@@ -38,28 +38,28 @@ public class TransactionOpImpl implements TransactionOp
     public TransactionCreateBuilder<CuratorOp> create()
     {
         ExtractingCuratorOp op = new ExtractingCuratorOp();
-        return new CreateBuilderImpl(client).asTransactionCreateBuilder(op.asCuratorOp(),
op.getRecord());
+        return new CreateBuilderImpl(client).<CuratorOp>asTransactionCreateBuilder(op,
op.getRecord());
     }
 
     @Override
     public TransactionDeleteBuilder<CuratorOp> delete()
     {
         ExtractingCuratorOp op = new ExtractingCuratorOp();
-        return new DeleteBuilderImpl(client).asTransactionDeleteBuilder(op.asCuratorOp(),
op.getRecord());
+        return new DeleteBuilderImpl(client).<CuratorOp>asTransactionDeleteBuilder(op,
op.getRecord());
     }
 
     @Override
     public TransactionSetDataBuilder<CuratorOp> setData()
     {
         ExtractingCuratorOp op = new ExtractingCuratorOp();
-        return new SetDataBuilderImpl(client).asTransactionSetDataBuilder(op.asCuratorOp(),
op.getRecord());
+        return new SetDataBuilderImpl(client).<CuratorOp>asTransactionSetDataBuilder(op,
op.getRecord());
     }
 
     @Override
     public TransactionCheckBuilder<CuratorOp> check()
     {
         ExtractingCuratorOp op = new ExtractingCuratorOp();
-        return CuratorTransactionImpl.makeTransactionCheckBuilder(client, op.asCuratorOp(),
op.getRecord());
+        return CuratorTransactionImpl.<CuratorOp>makeTransactionCheckBuilder(client,
op, op.getRecord());
     }
 
 }


Mime
View raw message