Skip to content

Commit

Permalink
added automatic stm initialization, moved init-stm and reset-stm impl…
Browse files Browse the repository at this point in the history
…ementations into avout.core namespace, incremented version
  • Loading branch information
liebke committed Dec 1, 2011
1 parent 1dc04f0 commit e067c36
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<p>To get started, you'll need to <a href="http://avout.io/index.html#running-zookeeper">run ZooKeeper</a>, and include Avout as a dependency by adding the following to your project.clj file:</p>

```clojure
[avout "0.5.1"]
[avout "0.5.2"]
```

<p>Below is the Avout equivalent of *Hello World*.</p>
Expand Down
4 changes: 2 additions & 2 deletions plugins/avout-mongo/project.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(defproject avout-mongo "0.5.1"
(defproject avout-mongo "0.5.2"
:description "An example of an Avout-based, MongoDB-backed Distributed Atom and Ref"
:dependencies [[org.clojure/clojure "1.3.0"]
[avout "0.5.1"]
[avout "0.5.2"]
[congomongo "0.1.7"]]
:dev-dependencies [[lein-clojars "0.7.0"]])
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject avout "0.5.1"
(defproject avout "0.5.2"
:description "Avout: Distributed State in Clojure"
:dependencies [[org.clojure/clojure "1.3.0"]
[zookeeper-clj "0.9.1"]]
Expand Down
25 changes: 20 additions & 5 deletions src/avout/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@
avout.refs.local
avout.atoms.zk))

(def init-stm tx/init-stm)

(def connect zk/connect)

(def reset-stm tx/reset-stm)
(defn init-stm
"Called the first time the STM is used, creates necessary ZooKeeper nodes."
([client]
(zk/create-all client (str cfg/*stm-node* cfg/HISTORY) :persistent? true)
(zk/create client (str cfg/*stm-node* cfg/REFS) :persistent? true)
(zk/create client (str cfg/*stm-node* cfg/ATOMS) :persistent? true)))

(defn reset-stm
"Used to clear and re-initialize the STM."
([client]
(zk/delete-all client cfg/*stm-node*)
(init-stm client)))

(defn connect
"Returns a ZooKeeper client, and initializes the STM if it doesn't already exist."
([& args]
(let [client (apply zk/connect args)]
(when-not (zk/exists client cfg/*stm-node*)
(init-stm client))
client)))

;; Distributed versions of Clojure's standard Ref functions

Expand Down
11 changes: 0 additions & 11 deletions src/avout/transaction.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@

(defn retryex? [e] (= "RETRY" (.getMessage e)))

(defn init-stm
([client]
(zk/create-all client (str cfg/*stm-node* cfg/HISTORY) :persistent? true)
(zk/create client (str cfg/*stm-node* cfg/REFS) :persistent? true)
(zk/create client (str cfg/*stm-node* cfg/ATOMS) :persistent? true)))

(defn reset-stm
([client]
(zk/delete-all client cfg/*stm-node*)
(init-stm client)))

(defn init-ref
([client ref-node]
(zk/create-all client (str ref-node cfg/HISTORY) :persistent? true)
Expand Down

0 comments on commit e067c36

Please sign in to comment.