Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (import '[clojure.lang IAtom IDeref])
- (import '[org.apache.ignite IgniteAtomicReference])
- (defn swap-helper [a f & args]
- (let [old-val (deref a)
- new-val (apply f old-val args)]
- (if (.compareAndSet (.-state a) old-val new-val)
- new-val
- (recur a f args))))
- ;; no implementation yet!
- (deftype IgniteAtom [^IgniteAtomicReference state]
- IAtom
- (swap [this f] (swap-helper this f))
- (swap [this f x] (swap-helper this f x))
- (swap [this f x y args] (apply swap-helper this f x y args))
- (compareAndSet [this old-val new-val]
- (.compareAndSet state old-val new-val))
- (reset [this new-val]
- (.set state new-val)
- new-val)
- IDeref
- (deref [this] (.get state)))
- ;; function to create
- (defn ignite-atom [ignite id init-val]
- (->IgniteAtom (.atomicReference ignite id init-val true)))
- (import '[org.apache.ignite Ignition])
- ;; start Ignite node
- (def ignite (Ignition/start))
- ;; create or retrieve
- (def a (ignite-atom ignite "ignite-atom" 0))
Add Comment
Please, Sign In to add comment