diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-08 12:28:02 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-08 12:28:02 +0200 |
commit | 6b0a33c6f2433e91251053d2b88b9f31ecdda9bf (patch) | |
tree | fc435ac0329923fa0f4cb2738c3af4066c679266 /zkfacade/src | |
parent | 3b910df3afbf86a7b57eed82d15a00966532de23 (diff) |
Create a mock lock in Lock when possible
Diffstat (limited to 'zkfacade/src')
-rw-r--r-- | zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java index 25e575cdb6a..4ae02bb3745 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java @@ -4,6 +4,7 @@ package com.yahoo.vespa.curator; import com.google.common.util.concurrent.UncheckedTimeoutException; import com.yahoo.transaction.Mutex; import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.recipes.locks.InterProcessLock; import org.apache.curator.framework.recipes.locks.InterProcessMutex; import java.time.Duration; @@ -16,13 +17,20 @@ import java.util.concurrent.TimeUnit; */ public class Lock implements Mutex { - private final InterProcessMutex mutex; + private final InterProcessLock mutex; private final String lockPath; + /** @deprecated pass a Curator instance instead */ + @Deprecated public Lock(String lockPath, CuratorFramework curator) { this.lockPath = lockPath; mutex = new InterProcessMutex(curator, lockPath); } + + public Lock(String lockPath, Curator curator) { + this.lockPath = lockPath; + mutex = curator.createMutex(lockPath); + } /** Take the lock with the given timeout. This may be called multiple times from the same thread - each matched by a close */ public void acquire(Duration timeout) { |