Nick Sieger: Post-JRuby-1.0 Bits and Bobs tag:blog.nicksieger.com,2005:Typo Typo 2007-07-13T09:49:21+00:00 Dr Nic urn:uuid:7f687301-8c99-44b4-9385-bcbc40603c07 2007-07-13T09:43:43+00:00 2007-07-13T09:49:21+00:00 Comment on Post-JRuby-1.0 Bits and Bobs by Dr Nic <p>JRuby and its community deserves a big hug.</p> <p>We have a billing system that has a limited set of ways you can communicate with it. One is a Java API.</p> <p>So, now we can communicate with the billing system via Ruby/jRuby. Now we can script it and web-app-icize it.</p> <p>Yummy.</p> Nick Sieger urn:uuid:0ddce74b-0d31-440d-8f1b-6abd235ad340 2007-07-12T08:27:00+00:00 2007-07-13T09:49:35+00:00 Post-JRuby-1.0 Bits and Bobs <p>Summer is settling in, and so is the <a href="/articles/2007/06/10/jruby-1-0">JRuby 1.0 release</a>. Most of the core team seemed to take some time off since the release, as the <a href="http://svn.jruby.codehaus.org/changelog/jruby/">commits</a> and <a href="http://www.nabble.com/JRuby-f14106.html">lists</a> have felt quiet compared to the frenetic lead-up to 1.0. I don&#8217;t know if that&#8217;s a good thing yet &#8211; I&#8217;m not bold enough to suggest that it means that JRuby&#8217;s just working for everyone, and that the software is bug-free. There have been calls for a point release (probably 1.0.1) and a better <a href="http://www.headius.com/jrubywiki/index.php/Roadmap">roadmap</a> &#8211; we&#8217;re working on those and should have something in the next couple of weeks.</p> <p>On the other hand, the number and quality of <a href="http://blogsearch.google.com/blogsearch?hl=en&amp;q=jruby&amp;ie=UTF-8&amp;scoring=d">blog posts</a> <a href="http://technorati.com/search/jruby">about</a> <a href="http://www.bloglines.com/search?q=jruby&amp;ql=en&amp;s=f&amp;pop=l&amp;news=m">JRuby</a> seem to be steadily increasing. The number of compelling applications of JRuby, both in the Ruby/Rails and the Java worlds, are being demonstrated more and more. Here are a few examples.</p> <p><a href="http://java.sun.com/products/jms/" title="Java Message Service (JMS)">JMS</a> is turning out to be a great place to sprinkle some JRuby magic. <a href="http://groups.google.com/group/activemessaging-discuss/browse_thread/thread/d3cfc1a4c25f3ce7/2709cdb64e333332#2709cdb64e333332">Ola started by implementing direct JMS support</a> for <a href="http://code.google.com/p/activemessaging/wiki/ActiveMessaging" title="ActiveMessaging - activemessaging - Google Code">ActiveMessaging</a>, eliminating the need for the separate poller process. <a href="http://nutrun.com/weblog/jms-with-jruby-and-activemq/">Nutrun</a> goes the other way and demonstrates how simple it is to run a broker, publisher and subscriber using <a href="http://activemq.apache.org/" title="Apache ActiveMQ -- Index">ActiveMQ</a> and a short JRuby script.</p> <p><a href="http://jmesnil.net/weblog/2007/06/11/jmx4r-a-jmx-libary-for-jruby/">Jeff Mesnil</a> has started <a href="http://code.google.com/p/jmx4r/" title="jmx4r - Google Code">jmx4r</a>, a simple DSL leveraging JRuby to write monitoring scripts for your JMX-enabled applications.</p> <p><a href="http://mojodna.net/2007/05/19/jruby-lucene-and-rejectconf/">Kyle Maxwell</a> whipped up a compelling plugin for Rails in time for RejectConf using <a href="http://lucene.apache.org/java/docs/" title="Apache Lucene - Overview">Lucene</a>. Why <a href="http://ferret.davebalmain.com/trac/">imitate</a> when you can use the real thing?</p> <p>Zed Shaw has caught the JRuby bug, and decided to do his own take on scripted Swing applications with <a href="http://ihate.rubyforge.org/profligacy/index.html">Profligacy</a>. <a href="http://pastie.caboo.se/75065">Check</a> <a href="http://pastie.caboo.se/75067">out</a> <a href="http://pastie.caboo.se/75276">the</a> <a href="http://pastie.caboo.se/75485">progression</a> <a href="http://pastie.caboo.se/76430">of</a> <a href="http://pastie.caboo.se/76438">examples</a> as Zed <a href="http://pastie.caboo.se/76960">hones in</a> on his <a href="http://ihate.rubyforge.org/profligacy/images/chat_proto_right.png">final product</a>. As <a href="http://blog.zerosum.org/?q=node/65">nap points out</a>, Zed&#8217;s Layout Expression Language (LEL) is a refreshingly concise take on specifying UI layouts. Cleaner separation of component layout and event handling logic is also a big win. Move over Groovy SwingBuilder and JavaFX!</p> <p>Last but not least, my own <a href="/articles/2006/12/01/rspec-jruby-mocking-and-multiple-interfaces">earlier proposal on Java interface integration</a> has <a href="http://jira.codehaus.org/browse/JRUBY-991">been implemented in current JRuby trunk</a>. Along the way I found the opportunity to toss in some extra sugar and implement proc and block coercion to interfaces as well. This means you can pass a proc or block to a Java method and it will be converted to the appropriate Java interface type (e.g., <code>Runnable</code> and Swing/AWT listeners):</p> <div class="typocode"><pre><code class="typocode_ruby "><span class="ident">button</span> <span class="punct">=</span> <span class="constant">JButton</span><span class="punct">.</span><span class="ident">new</span> <span class="ident">button</span><span class="punct">.</span><span class="ident">add_action_listener</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">event</span><span class="punct">|</span> <span class="ident">event</span><span class="punct">.</span><span class="ident">source</span><span class="punct">.</span><span class="ident">text</span> <span class="punct">=</span> <span class="punct">&quot;</span><span class="string">You pressed me</span><span class="punct">&quot;</span> <span class="keyword">end</span></code></pre></div> <p>If <a href="http://gafter.blogspot.com/2006/08/closures-for-java.html" title="Neal Gafter's blog: Closures for Java">closures for Java</a> can&#8217;t do this, they will have gotten it wrong. Note that blocks will be converted and used in place of the last argument to the Java method only; if you need to pass behavior to any argument preceding the last, use a proc. <a href="http://pastie.caboo.se/75142">Here&#8217;s one example</a> that gets progressively better as we switch over to blocks.</p> <p>Two parting thoughts &#8211; a couple of things that aren&#8217;t quite ready, but you should keep your eye on.</p> <p>Glassfish dev Jean-Fran&ccedil;ois Arcand demonstrates <a href="http://weblogs.java.net/blog/jfarcand/archive/2007/05/jruby_on_grizzl_1.html">parked Rails requests with Grizzly</a>. And you thought you had to do <em>comet</em>-style request handling outside of Rails? The future of scalable Rails servers looks pretty good to me.</p> <p>Finally, respected object technologist Alan McKean has <a href="http://www.nabble.com/forum/Search.jtp?forum=14106&amp;local=y&amp;query=alan+mckean">started looking at object serialization and persistence for JRuby</a>. You thought you had to wait for that Gemstone-thing that <a href="http://gilesbowkett.blogspot.com/2007/05/avi-bryants-railsconf-keynote-ruby-can.html">Avi Bryant mentioned at RailsConf</a>? Maybe the wait won&#8217;t be too long after all&#8230;</p>