Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DAD0A103E0 for ; Mon, 7 Sep 2015 06:03:28 +0000 (UTC) Received: (qmail 33076 invoked by uid 500); 7 Sep 2015 06:02:54 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 33015 invoked by uid 500); 7 Sep 2015 06:02:54 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 32990 invoked by uid 99); 7 Sep 2015 06:02:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Sep 2015 06:02:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 59807DFB90; Mon, 7 Sep 2015 06:02:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Mon, 07 Sep 2015 06:02:55 -0000 Message-Id: In-Reply-To: <207b0b0934f04216b2ad3068122bdca8@git.apache.org> References: <207b0b0934f04216b2ad3068122bdca8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] curator git commit: Added an indefinite acquire version of the constructor Added an indefinite acquire version of the constructor Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/543860f4 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/543860f4 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/543860f4 Branch: refs/heads/CURATOR-3.0 Commit: 543860f4811fa5327cabe524dad786363eb3f504 Parents: 58a8818 Author: randgalt Authored: Sun Sep 6 15:43:58 2015 -0700 Committer: randgalt Committed: Sun Sep 6 15:43:58 2015 -0700 ---------------------------------------------------------------------- .../curator/framework/recipes/locks/Locker.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/543860f4/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/Locker.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/Locker.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/Locker.java index 97788af..7eb362d 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/Locker.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/Locker.java @@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public class Locker implements AutoCloseable { private final InterProcessLock lock; - private final AtomicBoolean acquired; + private final AtomicBoolean acquired = new AtomicBoolean(false); /** * @param lock a lock implementation (e.g. {@link InterProcessMutex}, {@link InterProcessSemaphoreV2}, etc.) @@ -35,13 +35,24 @@ public class Locker implements AutoCloseable public Locker(InterProcessLock lock, long timeout, TimeUnit unit) throws Exception { this.lock = lock; - acquired = new AtomicBoolean(acquireLock(lock, timeout, unit)); + acquired.set(acquireLock(lock, timeout, unit)); if ( !acquired.get() ) { throw new TimeoutException("Could not acquire lock within timeout of " + unit.toMillis(timeout) + "ms"); } } + /** + * @param lock a lock implementation (e.g. {@link InterProcessMutex}, {@link InterProcessSemaphoreV2}, etc.) + * @throws Exception errors + */ + public Locker(InterProcessLock lock) throws Exception + { + this.lock = lock; + acquireLock(lock); + acquired.set(true); + } + @Override /** * Relase the lock if it has been acquired. Can be safely called multiple times. @@ -60,6 +71,11 @@ public class Locker implements AutoCloseable lock.release(); } + protected void acquireLock(InterProcessLock lock) throws Exception + { + lock.acquire(); + } + protected boolean acquireLock(InterProcessLock lock, long timeout, TimeUnit unit) throws Exception { return lock.acquire(timeout, unit);