lazy summer

Originally uploaded by pixietart

I wrote a tiny and very handy JMS drainer in JRuby with Spring at work, but I got fed up with running it from a command line because I am lazy.

So I wanted a web interface to run a drainer in background. Since I got JRuby on Rails in Tomcat running, I checked out BackgroundDRb only briefly, or not harder enough to get it working. To be honest, I could not figure out how I run a JRuby script as task.

Anyway, I came up with a better and simpler solution. I don’t need a fully featured background tasks management for this. I don’t need to persist tasks nor schedule tasks. I don’t care if tasks were terminated in the middle. The only things I need are:

  • Run a task from a web form
  • Show running tasks

I played with JSON and Jetty in JRuby before and found that combination very easy to develop. I have also learnt jQuery to work with JSON at client side recently. So I have used them to implement the above the followings.

  • Make a standalone JRuby task class runnable in a Java thread
  • A servlet in Jetty in JRuby with POST to execute a task in a thread and store the task instance in a global array and GET to return a list of running tasks of their status in JSON.
  • A default servlet in Jetty in JRuby to serve static content, i.e. one HTML page with css, javascripts and images
  • Use jQuery Ajax to load a JSON from the local servlet and populate the task list table dynamically.

That is simple and works well. It scales, too. 20-odd JMS drainers can run in one JVM. The execution is faster and save loads on the server.

I might post sample codes here if anyone is interested in.

la vía láctea

Originally uploaded by sanabria

Simon Willison’s blog post made me try Comet finally. The Jetty and Dojo demo has worked without any hassle. Simon said:

The entire application took less than an hour to put together, which I think is a testament to the quality of the Bayeux implementation present in both Jetty and Dojo. [...] Comet is probably about 90% of the way to being usable for mainstream project.

So I have decided to give it a go in my new experimental monitoring project and got a core feature working – a RESTish webservice being able to publish and cache a message and retrieve the latest message from the cache on top of Comet in Jetty and Dojo. Bayeux’s channel names are used as URIs in REST and keys in the cache.

What I wanted to archive with this feature is to mashup monitoring data from various tools, Nagios, Ganglia, etc. by server push. Even a simple chat can be in the same page!

First, I have replicated the demo into a webapp war and deployed it in tomcat 6.0, in which process I have learnt how it works more in details. Basically what I need is to deploy a Jetty’s Continuation Servlet, which does all server side magic for you.

I have chosen MemCached to cache Bayeux’s messages which are JSON objects.

The most difficult part so far was hooking the caching function into the Jetty Cometd Servlet. First, I tried DataFilter, but I can’t get the real channel id as I use a wildcard channel “/**”. It always returns the root channel “/”. Next, I tried BayeuxService used in the echo demo, but it does not allow to subscribe a wildcard channel. So I ended up adding a simple server side client which updates the cache on deliver method in Listener interface.

The RESTish webservice servlet, mapped to /galaxy/*, serves the only 2 methods, the HTTP GET to return the last Bayeux’s JSON message on the channel named by getPathInfo() and the HTTP POST to publish posted data onto the channel named by getPathInfo(). For example,

% curl http://localhost:8080/galaxy/nagios
% curl -d “status=OK” http://localhost:8080/galaxy/nagios

At client side I use jQuery with Dojo and its color animations to notify a changed value by changing the background colors. It loads the initial data by getJSON on the galaxy servlet and updates the data by cometd subscriber.

So far so good.

Super Ray

Originally uploaded by *MSM*

I have a Rails 1.2.3 application running in JRuby 1.0.1 on Tomcat 5.5.9 at work. The application itself is not mine (actually Tim‘s), but I helped him to run it in JRuby on Tomcat so that we can utilize the existing infrastructure at work.

After I’ve got the Rails 2.0 development tools working, as recommended, I have upgraded the application to Rails 1.2.6 and successfully run it in JRuby 1.0.3 on Tomcat 6.0.10 with ActiveRecord -JDBC 0.7 and goldspike 1.4. I haven’t seen any deprecation warnings so far, which is a good sign.

Here are some short tips (and notes for myself) so far:

  • As mentioned in Nick’s post, for Rails 1.2.x to use the AR-JDBC 0.7, you need to add the followings into “config/environment.rb” in the usual spot above the “Rails::Initializer”, for example

require ‘rubygems’
gem ‘activerecord-jdbcmysql-adapter’

  • Use the absolute path with RAILS_ROOT when accessing a file directly. This is because the working directory of the webapps is different from when the rails app is running in WEBrick or mongrel.
  • Consolidate logging into one stream by configuring the both Tomcat and Rails logging to STDOUT. In “config/environment.rb” insert the followings right after the “ do |config|” line. I also disable the colorized log messages to make them readable in the Eclipse console window.

config.logger =
config.active_record.colorize_logging = false

  • I don’t use the goldspike plugin that provides tasks to package up a web archive. Instead, I use the static web.xml without “jruby.home” and “rails.env params” to make the web archive deployment environment independent. Instead I set JRUBY_HOME and RAILS_ENV.
  • In general, use Gems On Rails – “vendor everything”, which allows you to push dependent gems into your rails app thus ensuring your application will be guaranteed to work when deployed. This makes the deployment much easier even at work place. My team provides application hosting environments where only core gems are installed.

See also:

JRuby on Rails in Tomcat inside Eclipse (Part 2)
Originally uploaded by Lilly

It was only a few weeks ago when JRuby 1.0.2 did not work well with Rails 2.0.1. Now JRuby 1.0.3 is out and Rails 2.0.2 is out, too.

So I have tried this again – JRuby on Rails in Eclipse IDE with WebTools Platform and RadRails.

Since RadRails 0.9.1 which has fixed compatibility issues with Eclipse 3.3 was out in November, I have upgraded Eclipse to 3.3.1 with WebTools Platform 2.0.1. I have also upgraded Tomcat to 6.0 as WTP 2.0 supports it.

ActiveRecord-JDBC 0.7 and GoldSpike 1.4 are just out, too. Basically I have upgraded everything and they have worked well together. I am going to upgrade or maybe re-write a few of my old rails apps in this development environment. How exciting!

See also:

play me
Originally uploaded by Lars van de Goor

It’s been long time since my last post here, but some of you may know I have been tumblring frequently lately.

I have tried Twitter, Facebook, etc, but I never kept using them. Tumblr is different. In explaining Union Square Ventures’ investment in Tumblr, Andrew Parke says:

Tumblelogging exists to express a more ethereal identity. Sometimes a simple image or snippet of video I find online can say much more about my current opinion, mood, or self-identity than any number of text paragraphs.

Personal expression online should be simple, and, more importantly, it should be beautiful. … the beauty in Tumblr is in its simplicity.

On 1st of November they released Tumblr 3.0 and have been working very hard. Check that out once if you haven’t.

You may find it a little bit unstable sometimes as I experienced last week, but as Jamis Buck (37signals) says, I have full confidence in them, too.

Reading all the bile and frustration in the comments, I felt I had to add a bit to counterbalance it. Being a web app developer myself, I’ve been there, and I know how it is to deploy a much-anticipated update and have it go bad. What the users are currently feeling is NOTHING to what the developers are currently feeling.

Calm down, people. Give the devs some time to straighten things out. I, for one, applaud their desire to improve tumblr, and I have full confidence in them. Yeah, in the meantime, my blog is down. I can live with that. I’ve got RL hobbies I can fall back on until things are working again. Life goes on! :)

It’s also very encouraging that the Tumblr community started the forum via Ning and the customer service via GetSatisfaction.


Related Posts:

The avenue in mist and sun

Originally uploaded by algo

Spring JMS has made JMS easy. JRuby makes it even easier.

I have used the OpenAdaptor as JMS clients for benchmarking and supporting tasks. With many ready-built components I can do most of things I need to do, but sometimes I can’t do simple things like sending a sample message in a file repeatedly for benchmarking unless I do a bit of java programming to extend the existing components.

The Spring’s SimpleMessageContrainer works well as a simple subscriber like for benchmarking or draining messages. I just needed to set the AutoStartup to false and set a JRuby implementation of the MessageListener to the SimpleMessageContainer bean programmatically before starting it up.

However, the JmsTemplate falls short on the publishing side, i.e. it opens and closes a session every time it sends a message. James Strachan has more on that. So I needed to create a session and a publisher in JRuby. Even so, it’s still easy as the Spring does the rest.

OpenAdaptor’s JMS Peek utility is useful as a diagnostic aid especially for Topic as it does not have a browsing interface like QueueBrowser. There were a few support cases in the past where users wanted to peek more than one messages. Not surprisingly, it was easily done in JRuby with Spring JMS. Fisrt, I tried to set the SessionAcknowledgeMode of SimpleMessageContainer to CLIENT_ACKNOWLEDGE, but it turned out that the SimpleMessageContainer called acknowledge() on Message. So, like the JRuby publisher, I have created a durable subscriber to receive a number of messages without acknowledging them.

Here are source codes of the above JRuby scripts. They are good enough to get simple things done quickly and simply. That’s why I love JRuby.

Related Posts:

Young Vic
Originally uploaded by Lilly

It was a perfect weather weekend for Open House London 2007. I was looking forward to the event and planning my days using their Google Map enabled search tool. 600 places for just 2 days! Some places are open for only one day and some popular places require pre-booking. Obviously I had to give up many of my first choices.

I have used Google My Map to organize my Sunday. Since the does not allow to embed the map yet, check my Sunday plan if you are interested.

On Saturday afternoon I drove down to Richmod area to visit Ham House, one of the most haunted 17th-century houses in Britain. Before that I had a delicious home-made cake and tea at Petersham Nurseries Teahouse. The stunning photos at their website led me to Nordljus, a talented Japanese food blogger Keiko Oikawa’s blog. I thought she was a professional photographer.

On Sunday, I got up a bit early and went down to London by train. I visited City Hall first to avoid queuing. Views from rooftop were a great start of the day. I really liked the famous spiral staircase and I thought I would use it every day if I worked there. The next planned visit was the Bank of England, but as I feared there was a long queue and I skipped it this time. After having visited Bartholomew’s Hospital, I came across a shooting some 80′s or 70′s scene on Old Bailey on the way to the next place. In my original schedule, I did not plan to visit 101 Victoria Embankment, but because I skipped the Bank of England and Middle Temple Hall was not open until 1pm, I just popped in the building. Then I was surprised by free refreshment, a bottle of iced tea and an ice cream! My last visit was Haworth TompkinsYoung Vic Theatre, which was shortlisted for RIBA Stirling Prize 2007. I really enjoyed the guided tour and they even allowed the visitors to get up on the slightly sloped stage in the auditorium.

I have uploaded selected photos to my Flickr.

I just thought it would have been more fun with iPod Touch and free Wi-Fi in London.

Finally I would like to thank to the organizer and volunteers for the fantastic event.

Time to Mingle…
Originally uploaded by l. argos

I installed ThoughtWorks Studios’ Mingle (Early Access Windows Version) a few weeks ago. I was interested in Mingle only because it runs on JRuby.

The installation was straightaway. It just worked. It runs a small executable called MingleServer.exe in which something are hidden. Hmm. Most of the ruby codes are obfuscated to protect IP. Fair enough. But, still it is interesting to see how it is deployed.

Mingle freezes not only rails but also all required gems.Everything even JRE is in one package to guarantee it will work when deployed. I have used Gems On Rails (aka vendor everything) to freeze some gems, but I could not get freezed ActiveRecord-JDBC working when I tried to run JRuby on Rails in Tomcat. Fortunately config files are not obfuscated. The environment.rb includes similar codes to Gems On Rails, which might be a trick to get all working.

Mingle has a retty plugin installed. Retty is a Ruby on Rails plugin that lets Jetty run as a server using JRuby. Even though it’s specific to Rails, it’s very interesting to read the server code since I tried the Jetty in JRuby, too.

Now 1.0 general release is available with an interesting pricing. I might try UNIX version to see if anything changed or wait for 1.1 release which will be delivered as a .war file that can be deployed on any of the popular Java EE application servers.

P.S. I’ve just realized that the public search on does not search comments. Why? Google crawl the comment feed of each post.

Related Posts:

Originally uploaded by Lucee.

In my previous post, I’ve re-written my old Java JMX client program in JRuby with Jetty.

In other area of my old Java program, I chose the data-push model, calling a set of JMX commands periodically and publishing data onto JMS, because I did not want them called too much frequently by accident. It has worked well, but there are a few things I wanted to change like, 1) It can’t run another instance for redundancy, 2) it’s not simple to get data because of JMS.

So, this time I’ve chosen the data-pull model with embedded HTTP servlet container jetty, implementing JSON webservice.

I also chose data caching without database backend in the JBoss webapp that subscribes to the JMX data on JMS. I admit I made a wrong decision on that. The data became stale from time to time and the JBoss server needed to restart to resolve the problem.

This time, as you would expect, I’ve chosen MySQL since I am thinking to rewrite the webapp in Rails.

The point of this post is how I gather data for a Rails application.

What I need is to gather data every minute. There are a few ways to run background jobs in Rails, but there is a better and simpler way to do that, which is running Rake tasks using Active Records from Cron. There is a great tutorial on that from Rails Envy.

Each task takes 15-20 secs to complete. Anything could go wrong and more than one task would run at once, which would make the problem worse. How can I prevent this? Lockrun comes handy here. Lockrun serves as a protective wrapper and it insures that another instance of the same command is not already running. My co-worker Phil has been using this for his applications for sometime now.

Related Posts:

Originally uploaded by streunerin

MIT’s SIMILE has announced 2 new projects in their blog: Timeplot and Potluck.

Timeplot is a DHTML-based AJAXy widget for plotting time series and overlay time-based events over them. Timeplot extends our existing Timeline widget to provide the ability to overlay time series over existing Timeline event data.

I have used Timeline a few times and I’ve loved it. I can’t wait to try out Timeplot. Plotting time-based events and time series data together is somehting missing in Swivel and Many Eyes. You will be able to plot a stock price chart with its news overlay like Google Finance. I’ve found the website stats example very interesting. Have you seen anything like that?

Why another charting tool? Timeplot FAQ answers:

  • it’s fully written in javascript and DHTML (you can use regular HTML web developer tools such as Firebug to check out its internals, debug it or modify it)
  • it doesn’t require any plugin to be installed in your browser
  • it doesn’t require any software to be installed on the server
  • it’s based on Timeline’s code so it’s naturally capable of reusing event data and mash it up with time series
  • it’s highly modular: you can write your own time series processing algorithms or your own layout geometries and add them directly from your pages (without having to wait for us to add them).
  • it’s open source software (under a BSD license)

Potluck is a Web user interface that lets casual users, those without programming skills and data modeling expertise, mash up data themselves. (From the research paper)

  • It allows the user to merge fields from different data sources, so that they are treated identically for sorting, filtering, and visualization. Fields are merged using simple drag and drop of field names.
  • It provides an efficient means for the user to clean up data syntactically, homogenize data formats, and extract fields syntactically embedded within existing fields, all through the application of simultaneous editing.
  • It supports faceted browsing to let users explore and identify subsets of data of interest or subsets of data that need alignment and clean up

Watch the screencast. We don’t have much Exhibit-powered pages to play with. I can’t think of any interesting mash up with Potluck (yet).

Related Posts:


Blog Stats

  • 85,763 hits



Get every new post delivered to your Inbox.