Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
6 experimental/orolo/plugins/avout-sdb/src/avout/sdb/atom.clj
@@ -43,7 +43,11 @@
(atom nil))
.init)))
-
+(defn sdb-initializer
+ ([name {:keys [sdb-client domain-name]}]
+ (sdb-atom sdb-client domain-name name))
+ ([name init-value {:keys [sdb-client domain-name]}]
+ (sdb-atom sdb-client domain-name name init-value)))
(comment
(use 'simpledb.core)
View
2  experimental/orolo/plugins/avout-sdb/src/simpledb/core.clj
@@ -58,7 +58,7 @@ Asia Pacific (Tokyo) Region sdb.ap-northeast-1.amazonaws.com
(comment
- (use 'avout.sdb :reload-all)
+ (use 'simpledb.core :reload-all)
(def ACCESS-KEY (get (System/getenv) "ACCESS_KEY"))
(def SECRET-KEY (get (System/getenv) "SECRET_KEY"))
(def sdb (sdb-client ACCESS-KEY SECRET-KEY))
View
5 experimental/orolo/src/avout/core.clj
@@ -17,3 +17,8 @@
"Cannot use standard reset! because Clojure expects a clojure.lang.Atom."
([atom old-value new-value] (.compareAndSet atom old-value new-value)))
+(defn datom
+ ([name initializer config]
+ (initializer name config))
+ ([name init-value initializer config]
+ (initializer name init-value config)))
View
46 experimental/orolo/src/avout/transaction.clj
@@ -0,0 +1,46 @@
+(ns avout.transaction
+ (:use avout.core))
+
+(defn init-clock [initializer config]
+ (datom "/stm/clock" 0 initializer config))
+
+(defn next-point [clock]
+ (swap!! clock inc))
+
+(defn init-txn-info [clock initializer config]
+ (let [txid (next-point clock)]
+ (datom (str "/stm/txn/" txid) {:txid txid, :state :RUNNING} initializer config)))
+
+(defn get-txn-info [txid initializer config]
+ (datom (str "/stm/txn/" txid) initializer config))
+
+(defn init-ref-info
+ ([name initilizer config]
+ (datom (str "/stm/refs/" name) {:history [], :txid nil} initilizer config)))
+
+(defn get-ref-info [name initializer config]
+ (datom (str "/stm/refs/" name) initializer config))
+
+(defn current-state? [tinfo & states]
+ (reduce #(or %1 (= (:state tinfo) %2)) false states))
+
+(defn tagged? [rinfo initializer config]
+ (when-let [txid (:txid rinfo)]
+ (let [txn (get-txn-info txid initializer config)]
+ (current-state? @txn :RUNNING :COMMITTING))))
+
+(defn try-tag [ref-info txid initializer config]
+ (let [new-info (swap!! ref-info
+ (fn [current-info]
+ (if (tagged? current-info initializer config)
+ current-info
+ (update-in current-info [:txid] identity txid))))]
+ (= (:txid new-info) txid)))
+
+(defn update-state [txn-info old-state new-state]
+ (let [tinfo (swap!! txn-info update-in [:state] #(if (= old-state %) new-state old-state))]
+ (= (:state tinfo) new-state)))
+
+(defn set-commit-point [clock txn-info]
+ (swap!! txn-info update-in [:commit-point] (fn [old-value] (next-point clock))))
+

No commit comments for this range

Something went wrong with that request. Please try again.