Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a sample project and wiki pages on how to write JRuby extensions #825

Closed
headius opened this issue Jun 24, 2013 · 3 comments
Closed
Milestone

Comments

@headius
Copy link
Member

headius commented Jun 24, 2013

We really should have a better set of examples and documents for how to write a JRuby extension. Many folks could be creating high-performance extensions to JRuby if this information were available.

The most recent article on writing an extension appears to be one from @jcoglan:

http://blog.jcoglan.com/2012/08/02/your-first-ruby-native-extension-java/

The "service" model of getting the code to load has largely (but unofficially) been deprecated in favor of simply using Java integration to boot up the extension directly, as seen in JRuby's OpenSSL ruby bits:

# Attempt to load the gem first
begin
  require 'jruby-openssl'
rescue LoadError
  # Not available, use built-in
  require 'bouncy-castle-java'
  require 'jopenssl.jar'
  org.jruby.ext.openssl.OSSLLibrary.new.load(JRuby.runtime, false)
...

But otherwise, we do have several good examples of how to write extensions.

A few current extensions that would be good models:

  • The weakling gem implements a more reliable weakref for (J)Ruby.
  • Extensions in the thread_safe gem and the atomic gem provide concurrency utilities.
  • The psych gem will soon incorporate JRuby's extension alongside the C extension. It provides a very good model of how to write a minimal Java-based extension that you wire up and provide a nice API for in Ruby.
@yokolet
Copy link
Member

yokolet commented Jun 24, 2013

Please don't forget Nokogiri, https://github.com/sparklemotion/nokogiri/

Also, https://github.com/relevance/diametric, ActiveRecord wrapper for Datomic, is a Java extension and supports CRuby (CRuby API is really limited). Although the code is in master, it's not yet released.

Every time I use JRuby's internal API, I think I need "GreenBridge" (Tom talked about a while ago) for those of who write Java extensions including me. Especially, when a method signature is different depends on CompatVersion, I think it's better to have Java side API for such method.

@jcoglan
Copy link

jcoglan commented Jun 24, 2013

I will happily correct my blog post and the codebase it's based on (now faye/websocket-driver-ruby) if someone shows me what I should be doing instead. I was quite confused at the time and that was the first thing I got to work.

@headius
Copy link
Member Author

headius commented May 11, 2016

There's a sample project, articles, and wiki stuff out there now. We need better linkage between our docs, but since this has been around a long time I'm closing it.

@headius headius closed this as completed May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants