Skip to content
This repository
tree: 7b23ca8e4e
Fetching contributors…

Cannot retrieve contributors at this time

executable file 36 lines (26 sloc) 1.43 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
A groovy library/dsl for using clojure's STM in groovy/grails applications.
this is just a thin layer of syntactic sugar on top of the java objects that implement the clojure language.
Not all concepts implemented here map exactly the their clojure namesakes.

Note, it is highly recommended that you understand how to use the objects in clojure first

This library is intended to be a vessel to sneak clojure.jar into your enterprise applications.
See Neal Ford's master plan for enterprise mindshare at
http://blip.tv/clojure/neal-ford-neal-s-master-plan-for-clojure-enterprise-mindshare-domination-5953926

Once you get used to the joy of coding your concurrency using this model, silently switch your
groovy scripts over to clj and enjoy the rest

See Dr. Venkat Subramaniam's materials from his "Taming Shared Mutability with STM" at http://agiledeveloper.com/downloads.html for examples and concepts in using clojure STM from Java


Example usage:

import clojure.lang.Ref
import static groovystm.STM.doSync
import static groovystm.STM.alter

class MyStateClass {
    /** Make sure your Ref's wrap immutable objects - try out clojure.lang.PersistentHashMap for example */
    Ref balanceRef = new Ref(0)

    int deposit(int amt) {
        doSync {
            alter(balanceRef) { balance -> balance + amt }
        }
    }

    int currentBalance() {
        deref(balanceRef)
    }
}
Something went wrong with that request. Please try again.