(distributed-lock client
&
{:keys [lock-node request-id] :or {lock-node "/lock"}})
Initializer for ZKDistributedReentrantLock
Examples:
(use 'zookeeper) (use 'avout.locks) (require '[zookeeper.logger :as log])
(def client (connect "127.0.0.1"))
(delete-lock client "/lock")
(def dlock (distributed-lock client)) (future (with-lock dlock (log/debug "dlock granted: count = " (.getHoldCount dlock) ", owner = " (.getOwner dlock)) (Thread/sleep 5000)) (log/debug "dlock released: count = " (.getHoldCount dlock) ", owner = " (.getOwner dlock)))
(.getOwner dlock) (delete client (str "/lock/" (.getOwner dlock)))
(def dlock2 (distributed-lock client)) (future (with-lock dlock2 (log/debug "dlock2 granted: count = " (.getHoldCount dlock2) ", owner = " (.getOwner dlock2)) (Thread/sleep 5000) (log/debug "attempting to lock dlock2 again...") (with-lock dlock2 (log/debug "dlock2 granted again: count = " (.getHoldCount dlock2) ", owner = " (.getOwner dlock2)) (log/debug "sleeping...") (Thread/sleep 5000) (log/debug "awake...")) (log/debug "dlock2 unlocked: count = " (.getHoldCount dlock2) ", owner = " (.getOwner dlock2))) (log/debug "dlock2 unlocked again: count = " (.getHoldCount dlock2) ", owner = " (.getOwner dlock2)))
(.getOwner dlock2) (delete client (str "/lock/" (.getOwner dlock2)))
(future (.lock dlock) (log/debug "first lock acquired acquired again")) (.getOwner dlock) (.unlock dlock)
(.queuedRequests dlock)
;; from another repl ;; connect to dlock lock (def dlock-reconnected (distributed-lock client :request-id (.getOwner dlock))) (.unlock dlock-reconnected)
(.delete dlock)
Initializer for ZKDistributedReentrantLock Examples: (use 'zookeeper) (use 'avout.locks) (require '[zookeeper.logger :as log]) (def client (connect "127.0.0.1")) (delete-lock client "/lock") (def dlock (distributed-lock client)) (future (with-lock dlock (log/debug "dlock granted: count = " (.getHoldCount dlock) ", owner = " (.getOwner dlock)) (Thread/sleep 5000)) (log/debug "dlock released: count = " (.getHoldCount dlock) ", owner = " (.getOwner dlock))) (.getOwner dlock) (delete client (str "/lock/" (.getOwner dlock))) (def dlock2 (distributed-lock client)) (future (with-lock dlock2 (log/debug "dlock2 granted: count = " (.getHoldCount dlock2) ", owner = " (.getOwner dlock2)) (Thread/sleep 5000) (log/debug "attempting to lock dlock2 again...") (with-lock dlock2 (log/debug "dlock2 granted again: count = " (.getHoldCount dlock2) ", owner = " (.getOwner dlock2)) (log/debug "sleeping...") (Thread/sleep 5000) (log/debug "awake...")) (log/debug "dlock2 unlocked: count = " (.getHoldCount dlock2) ", owner = " (.getOwner dlock2))) (log/debug "dlock2 unlocked again: count = " (.getHoldCount dlock2) ", owner = " (.getOwner dlock2))) (.getOwner dlock2) (delete client (str "/lock/" (.getOwner dlock2))) (future (.lock dlock) (log/debug "first lock acquired acquired again")) (.getOwner dlock) (.unlock dlock) (.queuedRequests dlock) ;; from another repl ;; connect to dlock lock (def dlock-reconnected (distributed-lock client :request-id (.getOwner dlock))) (.unlock dlock-reconnected) (.delete dlock)
(distributed-read-write-lock client
&
{:keys [lock-node request-id]
:or {lock-node "/read-write-lock"}})
(deleteLock this)
Deletes the distributed lock.
Deletes the distributed lock.
(getCondition this name)
Returns the condition with the given name.
Returns the condition with the given name.
(getOwner this)
Returns the child node that holds the lock.
Returns the child node that holds the lock.
(hasLock this)
Indicates if the current thread has the lock.
Indicates if the current thread has the lock.
(queuedRequests this)
Returns all queued request-nodes for this distributed lock.
Returns all queued request-nodes for this distributed lock.
(requestNode this)
Returns the child node representing this lock request instance.
Returns the child node representing this lock request instance.
(getHoldCount this)
Gets the number of holds for this lock in the current thread
Gets the number of holds for this lock in the current thread
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close