JettyRails 0.7, Merb 1.0 support

After the 1.0 official release, Merb is gaining more and more attention.

I’ve updated JettyRails to support Merb 1.0 applications, making it a good choice to run your rails and merb applications with JRuby, particularly in development time.

The release notes include:

* Merb 1.0 support!
* jruby-rack updated to the latest release (0.9.3)
* jetty server update to 6.1.14
* JSP and JSP Expression Language support
* some minor bugs

It is very simple to run any Merb 1.0.x and Rails 2.x applications. You just need to have JRuby properly installed, but JettyRails doesn’t work with jruby-1.1.4 (JRUBY-2959). First step is to install jetty-rails:

jruby -S gem install jetty-rails

Then, for Rails applications:

cd myrailsapp
jruby -S jetty_rails

And for Merb applications:

cd mymerbapp
jruby -S jetty_merb

Please note that you can’t use Merb with DataMapper in JRuby right now, but ActiveRecord does the job. Work is being done by Yehuda Katz (wycats) and Nick Sieger to port the native parts of DataObjects (used by DataMapper) in the do_jdbc project. Because of that, you can’t just install the merb gem. Wanted Merb modules should be installed separately:

jruby -S gem install merb-core # required
jruby -S gem install merb-more # extras

Play with JMaglev yourself

JMaglev is finally public available!

I’m releasing my experiments with JRuby and Terracotta, so you can play with JMaglev and contribute some code. The project is in Github.

I had to patch JRuby to make RubyObjects a little less dependent from the JRuby Runtime. It isn’t perfect yet, but is working. The patch against the current jruby trunk (rev. 8091) and the patched jruby-complete are included in the project.

The code in Github is just a TIM (Terracotta Integration Module) with a sample maven project and the JMaglev use-case included. Unfortunately, I haven’t any time yet to upload the TIM to Terracotta Forge. BTW, does anyone know how to do this?

For those who want to reproduce my JMaglev demo, here is a step-by-step. You must have GIT, Maven 2 and the JDK properly installed. It only works on Linux and OS X. Is anyone wanting to contribute support for Windows users?

  1. git clone git://github.com/fabiokung/clustered-jruby.git
  2. long time waiting, because terracotta-2.7.1 (vanilla) and jruby-complete (patched) are bundled.
  3. cd clustered-jruby
  4. mvn install (although mvn package is enough)
  5. cd jmaglev
  6. start the terracotta server:
    lib/terracotta-2.7.1/bin/start-tc-server.sh
  7. open another two terminals
  8. run the simplified jirb inside them:
  9. cd clustered-jruby/jmaglev
    ./bin/jmaglev jmaglev.rb

  10. Follow the demo. You will be able to share global variables among all jmaglevs:
    require 'hat'
    $hat
    require 'rabbit'
    $hat.put(Rabbit.new)
    
  11. in the other terminal, try to see the magic hat contents:
    $hat
    

I haven’t tested it with rails applications, but right now, it isn’t able to run IRB. I never thought that running IRB could be so hard. 🙂

More drawbacks and limitations are being discussed in the JRuby Users Mailing List.

I hope to see many contributions. Happy hacking!

EJB 4: the Future

Reading an article from Reza Rahman in TSS about what is new in EJB 3.1, I could predict the future. Here is a code snippet from the article:

EJBContainer container = EJBContainerFactory.createEJBContainer();
Context context = container.getContext();
PlaceBid placeBid = (PlaceBid) context.lookup("java:global/action-bazaar/PlaceBid");
placeBid.addBid(new Bid("rrahman", 10059, 200.50));
container.close();

Yes, PicoContainer will be standardized as EJB 4.0!

How long is going to take to people learn that less is more?

This is obviously a joke. It isn’t really true.

JRuby, sharing objects across multiple runtimes. JMagLev?

MagLev was a show from the last RailsConf (2008). Presentation and demos of the product are really impressive.

Recently, Brian Takita asked in the JRuby mailing list:

JRuby + TerraCotta == Maglev?

What an idea! In the last few days I’ve tried to make something useful and I’m happy to have something to show.

JRuby + Nailgun and JRuby + Terracotta

Screencast: Reproducing Avi Bryant's Demo with JRuby + Nailgun and JRuby + Terracotta. (5 min)

The first demo runs with Nailgun. The basic idea is to share a single Java VM across all clients, so they can share some objects. The second is much more complete, as its clients have their own Java VM. There are many true interpreters running, and they are sharing objects through Terracotta. Terracotta is responsible for sharing memory in Java VM clusters and, despite of its slow startup, has much more to offer. The shared objects (hats and rabbits) could be automatically persisted by Terracotta, as MagLev also does.

I’ve patched JRuby and configured Terracotta to make demos run. I’ll upload the patches and configuration somewhere, ASAP.

Working on JRuby to make it run multiple runtimes (VMs) at the same time is being really fun!

I’m a Certified Ruby Programmer Silver

I’ve just passed the certification exam from Ruby Association. I’m not allowed to talk much about the test itself, but I leave my warning here: be prepared.

Ruby Programming Language

Copyright (C) 2008 Ruby Association LLC

I was surprised, when I found it wasn’t an easy exam. I haven’t studied anything, as I’m working with Ruby everyday. But I should. Unfortunately, the test requires you to memorize many methods from core classes.

Learn the Core API, mainly the Array, Hash, String, Fixnum, Float, Object, Kernel, Time and File classes. Study until you memorize their methods. There are many questions about Hashes, Strings and Arrays. Caution with methods that modify the objects itself and methods that don’t (mutable vs immutable).

Also, be sure that you have a good understanding of Ruby Regular Expressions.

It would be great if the certification had more questions about OO in Ruby, Strings vs Symbols, less API memorization, blocks being the functional guys, operator overloading, modules as mixins, Test::Unit, threads, duck typing, dynamic typing, …

I haven’t seen any question about polymorphism! Shame.

Just to be clear, I don’t care that much for certifications. There are many people discussing if certifications are good or not (at least here in Brazil). I won’t discuss it here. My decision to be certified was made, because I teach Ruby classes and, at least here in Brazil, certifications are important to instructors.

Revising my opinion about Spring Framework

In past, at comm.world (Germany), I worked with projects based on Spring. At that time, I built my opinion about the framework: useless. It had nothing you couldn’t do without it. Everything that came with Spring could be done in simpler ways: PicoContainer or plain constructor injection for IoC/DI, plain decorators, dynamic proxies or Servlet Filters instead of AOP for the same results, WebWork simpler than Spring MVC, …

Some time has passed and, influenced by some friends in our endless discussions about Spring, I’ve decided to give it another try and I’ve started to refactor the VRaptor Web Framework, changing it to be fully Spring-based.

After this experience, I must admit: I was a bit wrong. I am going to explain it better, but I think the best part of Spring is that it already comes with many things done, ready to be used; out of the box. Furthermore, Spring 2.5 is much, much better.

Now, I have the sense that Spring brings some complexity, compared to lightweight alternatives; but not that much. This is the cost for the benefits the framework introduces. It is extremely flexible, supporting many different programming styles and idioms. I would be able to completely rewrite VRaptor to use Spring building blocks. Most of the current frameworks could be changed to be Spring-based, with little influence in their current APIs and programming styles!

People has already (re)implemented Google Guice on top of Spring. The EJB3 programming model (@EJB, @PersistenceContext, @Stateless, @Stateful, @Resource, …) can be easily replicated on Spring applications (old – 2005 – article that may be done better nowadays). One could even provide an EJB3 implementation on top of Spring, JBoss Seam could be rewritten on top of Spring and even PicoContainer could be Spring-based.

My current opinion is that Spring is a truly framework, in its original sense, because it acts as a solid base for applications to be built on top of it, without imposing any programming model, style or idiom. You aren’t required to use XML, Spring classes and even Spring annotations. The little bureaucracy comes with a bunch of ready functionality to be used, and with the great flexibility the framework has to be extended.

Today I can say I would consider using Spring Framework for new projects. I even consider it to be a good candidate to become one or more JSRs. It is a great base for applications and other frameworks to be built on top of it. Rod Johnson is a member of Java EE 6 Expert Group, which could point things to something in this direction.