JRuby Support

Aquarium runs under JRuby. The rake website target runs all the specs under JRuby to ensure that they work as expected.

In addition, JRuby can now advise Java types (with some limitations…)!

Advising Java Types in JRuby

While you might normally turn to AspectJ or the Spring Framework to advise Java classes, if you are using JRuby, you can now use Aquarium! The advantages and disadvantages of Aquarium compared to AspectJ are listed in the README. Briefly, Aquarium lets you add and remove advice dynamically at runtime, you can advise JDK types easily, and Aquarium lets you advise individual objects. The disadvantages of Aquarium are that it will be slower than using AspectJ, Aquarium’s pointcut language is not as full-featured as AspectJ’s, and there are some bugs and limitations in this initial support (V0.4.0).

Here is an example of adding tracing calls to a method doIt in all classes that implement the Java interface com.foo.Work.

1Aspect.new :before, :calls_to => [:doIt, :do_it], 
2    :in_types_and_descendents => Java::com.foo.Work do |jp, obj, *args|
3  names = "#{jp.target_type.name}##{jp.method_name}"
4  log "Entering: #{names}: object = #{object}, args = #{args}" 

There are two important points to notice in this example:

Limitations and Bugs

(Here’s the “fine print”…) In this (V0.4.0) release, there are some important limitations and a few bugs (either in Aquarium or JRuby??).

For more details, see the RSpec examples in the jruby/spec directory.

  • gem install aquarium
  • gem update aquarium


Other Links