You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/05/03 12:58:59 UTC

curator git commit: Added ttl suppport to Create transactions

Repository: curator
Updated Branches:
  refs/heads/CURATOR-407 [created] d7d84c552


Added ttl suppport to Create transactions


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

Branch: refs/heads/CURATOR-407
Commit: d7d84c5527d8e35fc01b6aedb78eaafa9739018d
Parents: ed3082e
Author: randgalt <ra...@apache.org>
Authored: Wed May 3 07:56:51 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Wed May 3 07:56:51 2017 -0500

----------------------------------------------------------------------
 .../transaction/TransactionCreateBuilder.java   | 24 +++++++-------
 .../transaction/TransactionCreateBuilder2.java  | 34 ++++++++++++++++++++
 .../framework/imps/CreateBuilderImpl.java       |  8 +++++
 .../api/AsyncTransactionCreateBuilder.java      | 27 ++++++++++++++++
 .../x/async/details/AsyncTransactionOpImpl.java | 22 +++++++++++--
 5 files changed, 101 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/d7d84c55/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
index f7b2850..cf8016e 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
@@ -18,17 +18,17 @@
  */
 package org.apache.curator.framework.api.transaction;
 
-import org.apache.curator.framework.api.ACLCreateModePathAndBytesable;
-import org.apache.curator.framework.api.ACLPathAndBytesable;
-import org.apache.curator.framework.api.Compressible;
-import org.apache.curator.framework.api.CreateModable;
-import org.apache.curator.framework.api.PathAndBytesable;
-
-public interface TransactionCreateBuilder<T> extends
-    PathAndBytesable<T>,
-    CreateModable<ACLPathAndBytesable<T>>,
-    ACLPathAndBytesable<T>,
-    ACLCreateModePathAndBytesable<T>,
-    Compressible<ACLCreateModePathAndBytesable<T>>
+public interface TransactionCreateBuilder<T> extends TransactionCreateBuilder2<T>
 {
+    /**
+     * Specify a TTL when mode is {@link org.apache.zookeeper.CreateMode#PERSISTENT_WITH_TTL} or
+     * {@link org.apache.zookeeper.CreateMode#PERSISTENT_SEQUENTIAL_WITH_TTL}. If
+     * the znode has not been modified within the given TTL, it will be deleted once it has no
+     * children. The TTL unit is milliseconds and must be greater than 0 and less than or equal to
+     * EphemeralType.MAX_TTL.
+     *
+     * @param ttl the ttl
+     * @return this for chaining
+     */
+    TransactionCreateBuilder2<T> withTtl(long ttl);
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/d7d84c55/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder2.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder2.java b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder2.java
new file mode 100644
index 0000000..420aacf
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder2.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api.transaction;
+
+import org.apache.curator.framework.api.ACLCreateModePathAndBytesable;
+import org.apache.curator.framework.api.ACLPathAndBytesable;
+import org.apache.curator.framework.api.Compressible;
+import org.apache.curator.framework.api.CreateModable;
+import org.apache.curator.framework.api.PathAndBytesable;
+
+public interface TransactionCreateBuilder2<T> extends
+    PathAndBytesable<T>,
+    CreateModable<ACLPathAndBytesable<T>>,
+    ACLPathAndBytesable<T>,
+    ACLCreateModePathAndBytesable<T>,
+    Compressible<ACLCreateModePathAndBytesable<T>>
+{
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/d7d84c55/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
index 718dded..fdd1e15 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
@@ -27,6 +27,7 @@ import org.apache.curator.drivers.OperationTrace;
 import org.apache.curator.framework.api.*;
 import org.apache.curator.framework.api.transaction.OperationType;
 import org.apache.curator.framework.api.transaction.TransactionCreateBuilder;
+import org.apache.curator.framework.api.transaction.TransactionCreateBuilder2;
 import org.apache.curator.utils.ThreadUtils;
 import org.apache.curator.utils.ZKPaths;
 import org.apache.zookeeper.AsyncCallback;
@@ -120,6 +121,13 @@ public class CreateBuilderImpl implements CreateBuilder, CreateBuilder2, Backgro
             }
 
             @Override
+            public TransactionCreateBuilder2<T> withTtl(long ttl)
+            {
+                CreateBuilderImpl.this.withTtl(ttl);
+                return this;
+            }
+
+            @Override
             public ACLPathAndBytesable<T> withMode(CreateMode mode)
             {
                 CreateBuilderImpl.this.withMode(mode);

http://git-wip-us.apache.org/repos/asf/curator/blob/d7d84c55/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncTransactionCreateBuilder.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncTransactionCreateBuilder.java b/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncTransactionCreateBuilder.java
index 81da5c0..64b1c15 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncTransactionCreateBuilder.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/api/AsyncTransactionCreateBuilder.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.x.async.api;
 
 import org.apache.curator.framework.api.transaction.CuratorOp;
@@ -52,6 +53,18 @@ public interface AsyncTransactionCreateBuilder extends AsyncPathAndBytesable<Cur
     AsyncPathAndBytesable<CuratorOp> compressed();
 
     /**
+     * Specify a TTL when mode is {@link org.apache.zookeeper.CreateMode#PERSISTENT_WITH_TTL} or
+     * {@link org.apache.zookeeper.CreateMode#PERSISTENT_SEQUENTIAL_WITH_TTL}. If
+     * the znode has not been modified within the given TTL, it will be deleted once it has no
+     * children. The TTL unit is milliseconds and must be greater than 0 and less than or equal to
+     * EphemeralType.MAX_TTL.
+     *
+     * @param ttl the ttl
+     * @return this for chaining
+     */
+    AsyncPathAndBytesable<CuratorOp> withTtl(long ttl);
+
+    /**
      * Specify mode, acl list and compression
      *
      * @param createMode mode
@@ -63,4 +76,18 @@ public interface AsyncTransactionCreateBuilder extends AsyncPathAndBytesable<Cur
      * @return this
      */
     AsyncPathAndBytesable<CuratorOp> withOptions(CreateMode createMode, List<ACL> aclList, boolean compressed);
+
+    /**
+     * Specify mode, acl list, compression and ttl
+     *
+     * @param createMode mode
+     * @param aclList the ACL list to use
+     * @param compressed true to compress
+     * @see #withMode(org.apache.zookeeper.CreateMode)
+     * @see #withACL(java.util.List)
+     * @see #compressed()
+     * @see #withTtl(long)
+     * @return this
+     */
+    AsyncPathAndBytesable<CuratorOp> withOptions(CreateMode createMode, List<ACL> aclList, boolean compressed, long ttl);
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/d7d84c55/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncTransactionOpImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncTransactionOpImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncTransactionOpImpl.java
index 0be720f..45c0205 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncTransactionOpImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncTransactionOpImpl.java
@@ -22,7 +22,7 @@ import org.apache.curator.framework.api.ACLCreateModePathAndBytesable;
 import org.apache.curator.framework.api.PathAndBytesable;
 import org.apache.curator.framework.api.VersionPathAndBytesable;
 import org.apache.curator.framework.api.transaction.CuratorOp;
-import org.apache.curator.framework.api.transaction.TransactionCreateBuilder;
+import org.apache.curator.framework.api.transaction.TransactionCreateBuilder2;
 import org.apache.curator.framework.api.transaction.TransactionSetDataBuilder;
 import org.apache.curator.framework.imps.CuratorFrameworkImpl;
 import org.apache.curator.x.async.api.AsyncPathAndBytesable;
@@ -54,6 +54,7 @@ class AsyncTransactionOpImpl implements AsyncTransactionOp
             private List<ACL> aclList = null;
             private CreateMode createMode = CreateMode.PERSISTENT;
             private boolean compressed = false;
+            private long ttl = -1;
 
             @Override
             public AsyncPathAndBytesable<CuratorOp> withMode(CreateMode createMode)
@@ -77,6 +78,13 @@ class AsyncTransactionOpImpl implements AsyncTransactionOp
             }
 
             @Override
+            public AsyncPathAndBytesable<CuratorOp> withTtl(long ttl)
+            {
+                this.ttl = ttl;
+                return this;
+            }
+
+            @Override
             public AsyncPathAndBytesable<CuratorOp> withOptions(CreateMode createMode, List<ACL> aclList, boolean compressed)
             {
                 this.createMode = Objects.requireNonNull(createMode, "createMode cannot be null");
@@ -86,6 +94,16 @@ class AsyncTransactionOpImpl implements AsyncTransactionOp
             }
 
             @Override
+            public AsyncPathAndBytesable<CuratorOp> withOptions(CreateMode createMode, List<ACL> aclList, boolean compressed, long ttl)
+            {
+                this.createMode = Objects.requireNonNull(createMode, "createMode cannot be null");
+                this.aclList = aclList;
+                this.compressed = compressed;
+                this.ttl = ttl;
+                return this;
+            }
+
+            @Override
             public CuratorOp forPath(String path, byte[] data)
             {
                 return internalForPath(path, data, true);
@@ -99,7 +117,7 @@ class AsyncTransactionOpImpl implements AsyncTransactionOp
 
             private CuratorOp internalForPath(String path, byte[] data, boolean useData)
             {
-                TransactionCreateBuilder<CuratorOp> builder1 = client.transactionOp().create();
+                TransactionCreateBuilder2<CuratorOp> builder1 = (ttl > 0) ? client.transactionOp().create().withTtl(ttl) : client.transactionOp().create();
                 ACLCreateModePathAndBytesable<CuratorOp> builder2 = compressed ? builder1.compressed() : builder1;
                 PathAndBytesable<CuratorOp> builder3 = builder2.withACL(aclList);
                 try