Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/curator/mutex.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns curator.mutex
(:import
[org.apache.curator.framework.recipes.locks InterProcessMutex]
[org.apache.curator.framework.recipes.locks InterProcessMutex InterProcessSemaphoreMutex]
[org.apache.curator.framework CuratorFramework]
[java.util.concurrent TimeUnit]))

Expand All @@ -9,14 +9,19 @@
[^CuratorFramework client ^String path]
(InterProcessMutex. client path))

(defn ^InterProcessSemaphoreMutex semaphore-mutex
"Create an InterProcessSemaphoreMutex. This mutex is not re-entrant."
[^CuratorFramework client ^String path]
(InterProcessSemaphoreMutex. client path))

(defn acquire
"If no timeunits are given, blocks until acquired. Otherwise returns true or
false depending on if it acquires the lock in the given time. Time defaults
to milliseconds."
([^InterProcessMutex m] (.acquire m))
([^InterProcessMutex m ^long n] (.acquire m n TimeUnit/MILLISECONDS))
([^InterProcessMutex m ^long n ^TimeUnit tu] (.acquire m n tu)))
([m] (.acquire m))
([m ^long n] (.acquire m n TimeUnit/MILLISECONDS))
([m ^long n ^TimeUnit tu] (.acquire m n tu)))

(defn release
"Release a mutex."
[^InterProcessMutex m] (.release m))
[m] (.release m))