JRuby-based Chat Server using Terracotta

Two technologies are currently capturing my imagination, JRuby and Terracotta. JRuby is simply for my purposes the most effective language to tackle most of my computing challenges. Terracotta allows me to take those problems and solve them on large clusters of cheap servers in clouds such as those provided by Amazon EC2.

Getting started with JRuby+Terracotta requires a bit of trial and error as its not as well documented as good old Java+Terracotta. The only post you’re likely to find is one by Jonas Boner (see below). During subsequent revisions of both Terracotta as well as JRuby, the example had stopped working. These files bring that example update to date for JRuby 1.3.1 and Terracotta 3.0.1.

You can download the revised source code from my github account. You will need installs of both JRuby and Terracotta with JRUBY_HOME and TC_HOME pointing to the base folders of both products respectively, e.g.

export JRUBY_HOME=$HOME/java/jruby-1.3.1
export TC_HOME=$HOME/java/terracotta-3.0.1

Once these environment variables have been setup you can start a Terracotta server, followed launching multiple clients by typing:

./chat.sh

Background

The key to fixing the example was fixing the java.lang.NoClassDefFoundError: com/tc/object/event/DmiManager, caused by the references to com.tc.object.bytecode.Manager in the terracotta.rb file:

WRITE_LOCK = com.tc.object.bytecode.Manager::LOCK_TYPE_WRITE
READ_LOCK = com.tc.object.bytecode.Manager::LOCK_TYPE_READ
CONCURRENT_LOCK = com.tc.object.bytecode.Manager::LOCK_TYPE_CONCURRENT

Replacing the above fragment with:

WRITE_LOCK = 2
READ_LOCK = 1
CONCURRENT_LOCK = 4

and the whole example springs to life. My next problem to solve is that of Rubifying the Workmanager examples from chapter 11 of the “Definitive Guide to Terracotta” book.

Useful Links



3 Responses to “JRuby-based Chat Server using Terracotta”

  1. Taylor Gautier says:

    Cool. You’ll want to have a look at tim-messaging on the Terracotta forge. It’s the evolved version of the workmanager examples in the book which are now nearly two years out of date.

  2. admin says:

    Thanks for the tip Taylor. I shall check it out.

  3. Alex Miller says:

    Cool, glad to see someone pick this up. If you’re interested in putting together any kind of packaged integration on the Terracotta forge, drop us a line.

Leave a Reply