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.


Reply via email to