Liking cljdoc? Tell your friends :D

avout.locks


distributed-lockclj

(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)
sourceraw docstring

distributed-read-write-lockclj

(distributed-read-write-lock client
                             &
                             {:keys [lock-node request-id]
                              :or {lock-node "/read-write-lock"}})
source

DistributedLockcljprotocol

deleteLockclj

(deleteLock this)

Deletes the distributed lock.

Deletes the distributed lock.

getConditionclj

(getCondition this name)

Returns the condition with the given name.

Returns the condition with the given name.

getOwnerclj

(getOwner this)

Returns the child node that holds the lock.

Returns the child node that holds the lock.

hasLockclj

(hasLock this)

Indicates if the current thread has the lock.

Indicates if the current thread has the lock.

queuedRequestsclj

(queuedRequests this)

Returns all queued request-nodes for this distributed lock.

Returns all queued request-nodes for this distributed lock.

requestNodeclj

(requestNode this)

Returns the child node representing this lock request instance.

Returns the child node representing this lock request instance.
source

DistributedReentrantLockcljprotocol

getHoldCountclj

(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
source

if-lockcljmacro

(if-lock lock then-exp else-exp)
source

if-lock-with-timeoutcljmacro

(if-lock-with-timeout lock duration time-units then-exp else-exp)
source

when-lockcljmacro

(when-lock lock & body)
source

when-lock-with-timeoutcljmacro

(when-lock-with-timeout lock duration time-units & body)
source

with-lockcljmacro

(with-lock lock & body)
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close