Hey thanks for all the feedback. So I got a working solution, bits and pieces of this solution online. Cedric mentioned it, but basically, I'm having my java code call a clojure function that (via STM), pushes new event objects to a list in Clojure (fig.1). And with my Clojure code in place, my Java code looks like the below (fig.2). And this ensures that the Java callback pushes to an STM guarded place in memory.
(def event-list (ref ())) (defn pushEvent [event] (dosync (alter event-list conj event) )) (defn -pushEvent [event] (pushEvent event)) fig.1 eventObject = ... ; //Load the namespace RT.var("clojure.core","eval").invoke(RT.var("clojure.core","read-string").invoke("(use 'my.namespace)")); //Find a function in namespace IFn fn = (IFn)RT.var("my.namespace","my-function"); //Call that function Object result = *fn.invoke( eventObject );* System.out.println(result); fig.2 Now, this works, but I'm always open to a better idea. In clojure-land, 1) there's a thread constantly checking for new events on the list and 2) there will be a thread of execution for each eventID. So I'm trying to come up with the best data and functional pattern to handle all this. I'm not sure a plain-jane Clojure list does the trick. Hmm Tim No 6: "I'm not a number. I'M A FREE MAN!!!" No 2: "HA HA HA HA HAAAAAAA" -- The Prisoner On Tue, Apr 9, 2013 at 3:48 PM, Cedric Greevey <cgree...@gmail.com> wrote: > On Tue, Apr 9, 2013 at 12:41 PM, Timothy Washington <twash...@gmail.com>wrote: > >> Hi all, >> >> I have a polyglot project, comprising of a little Java and mostly Clojure >> code. The Java class is a concrete callback for an external library. There >> will be sub-second firing of that callback, and event map objects will get >> pushed onto a list. >> > > Now, after the generic advice for sharing state between Java and Clojure, > in your specific case it sounds like you might have only a single piece of > state and it *may* be a queue being produced by the Java callback and > consumed by Clojure. > > In the single-piece-of-state-but-not-a-queue case you could use > java.util.concurrent.AtomicReference around a java.util.List from the Java > side, or even a Clojure atom (clojure.lang.Atom class). > > In the queue case you can do better: > java.util.concurrent.LinkedBlockingQueue. In the callback class, static > LinkedBlockingQueue queue = new LinkedBlockingQueue(); and, in the callback > method, queue.offer(anotherEventMapObject); in the Clojure code, (.poll > CallbackClass/queue) to fetch an event map in the consumer (it will block, > as the name implies, if the queue is empty until the producer offers > another one, so you might want a dedicated thread to do the consuming, > depending). > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.