[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12879197#action_12879197
 ] 

brian wickman commented on ZOOKEEPER-661:
-----------------------------------------

Yet another version - http://github.com/wickman/zookeeper

In the distant future when we're able to move our app to 1.9, it'd make good 
sense to merge with the FFI branch.  In the meantime, we're stuck on 1.8.  This 
fork uses a client API similar to Reynhout's FFI version (args via hashes w/ 
optionals), but differs in that it works on MRI 1.8 while still supporting 
watchers and callbacks.  Right now it polls to dispatch callbacks, and like 
Topper's, needs only another 10 lines of code to integrate EventMachine to wake 
up to a ping over a FIFO/socket passed to the C extension.  For the sake of 
minimalism, I left it as-is for now since we're not exactly using ZK as a 
hyper-performant datastore.

I'm not sure about Topper's dev environment (maybe Ruby threading on Solaris is 
happier?), but I was unable to get any Ruby C extension API methods to work at 
all from the Zookeeper thread pool.  I'm sure the 1.9 dev environment is a bit 
safer still.  Unfortunately, the instant you try to do anything on 1.8 that has 
the side effect of allocating some data on a stack (e.g. rb_funcall or 
rb_hash_new), the Ruby interpreter segfaults.  To get around this in my 
extension, all callback and watcher completions get saved and queued on the ZK 
side and dispatched from the polling method on the Ruby side, effectively 
decoupling the ZK threadpool from the Ruby interpreter.  Conversion from ZK 
data types to native Ruby data types always happens in a thread context that is 
active in the Ruby interpreter, side-stepping the annoying thread-safety 
problems.

Please take a look.  I'm new to Ruby, so pardon any idiomatic faux pas.

> Add Ruby bindings
> -----------------
>
>                 Key: ZOOKEEPER-661
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-661
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings
>         Environment: MRI Ruby 1.9
> JRuby 1.4
>            Reporter: Andrew Reynhout
>            Priority: Minor
>
> Add Ruby bindings to the ZooKeeper distribution.
> Ruby presents special threading difficulties for asynchronous ZK calls (aget, 
> watchers, etc).  It looks like the simplest workaround is to patch the ZK C 
> API.
> Proposed approach will be described in comment.
> Please use this ticket for discussion and suggestions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to