zookeeper-atom
zookeeper-atom copied to clipboard
Looks and behaves like a Clojure atom but uses Zookeeper synchronize access to it's value.
Zookeeper Atom ![Build Status](https://travis-ci.org/torsten/zookeeper-atom.svg)
Looks and behaves like a Clojure atom but works distributed across many machines by storing it's data as EDN in a Zookeeper node.
Features
- Simple API:
atom
(to create),deref
/@
,swap
, andreset
. Just like Clojure's API. - Reads don't block, they just return a cached value. All updates from Zookeeper get applied in the background.
- Values are encoded as EDN.
Releases and Dependency Information
zookeeper-atom is released via Clojars. The Latest stable release is 1.0.0
Leiningen dependency information:
[zookeeper-atom "1.0.0"]
Maven dependency information:
<dependency>
<groupId>zookeeper-atom</groupId>
<artifactId>zookeeper-atom</artifactId>
<version>1.0.0</version>
</dependency>
Usage
This example requires that you have Zookeeper installed and running:
(require '[zookeeper-atom.core :as zk])
(def client (zk/connect "127.0.0.1"))
(def a-atom (zk/atom client "/some/znode/path"))
@a-atom
;; => nil
(zk/swap a-atom assoc :foo "bar")
;; => {:foo "bar"}
(zk/reset a-atom {})
;; => {}
Alternatively to the code above, a zookeeper-atom can be initialized:
(def b-atom (zk/atom client "/some/path" [1 2 3]))
@b-atom
;; => [1 2 3]
However, if there already exists a node at the given path, it's value will not be overwritten:
(def c-atom (zk/atom client "/some/path" "WAT?!"))
@c-atom
;; => [1 2 3]
Contributing
Reporting bugs and pull requests are very welcome!
Here is a little snippet to get you started in your REPL in case you want to extend zookeeper-atom:
(use 'clj-logging-config.log4j 'midje.repl)
(set-loggers! :root {:level :warn} "zookeeper-atom.core" {:level :debug})
(autotest)
; hack!
License
Copyright © 2014 Torsten Becker.
Distributed under the Eclipse Public License, the same as Clojure.