You are currently browsing the category archive for the ‘Technology’ category.

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:

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 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:

Originally uploaded by Batram

Have your application ever been blocked by Log4j logging? Ideally your application should be less dependable on external logging services, SMTPAppender or JMSAppender, etc, but you need one to monitor important events remotely.

The AsyncAppender lets you log events asynchronously. It will collect the events sent to it and then dispatch them to all the appenders that are attached to it. You can attach multiple appenders to an AsyncAppender, but I won’t do that. The AsyncAppender uses a separate thread to serve the events in its buffer. The default buffer size is 128 and the blocking is set to true, which means that the logging is blocked when the buffer is full. I don’t know why the default blocking is set to true. Reading the source codes, if it’s set to false, the logging won’t be blocked since events are summarized and discarded. I’ve got to test it.

I have used JRuby to test the AsyncAppender and found it very handy again.

First of all, I needed an Log4j Appender that runs a bit slow. So, I have created a very simple SlowAppender.rb, which is a subclass of Log4j AppenderSkeleton. You just need to implement the append method.

SlowAppender < org.apache.log4j.AppenderSkeleton
def append(event)
sleep 1
puts layout.format(event)

Since I can’t configure it in log4j.xml, I add it to an AsyncAppender programmatically in a test JRuby script.

logger = Logger.getRootLogger()
slow =
slow.setLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n"))
async = logger.getAppender("ASYNC")

Full source codes and the result of the test script are available here.

You may not like that some events are discarded, but ideally you should be notified by catastrophic problems with remote logging services before that. What’s important to you is that your application keeps working without being disrupted by other services.

You should also consider using StringMatchFilter to avoid sending unnecessary log messages to remote logging services. A flood of unnecessary logging messages will cause problems to remove logging services that are most likely shared with other applications.

A while back I came across RSSAppender and I think it’s a very simple way to retrieve and aggregate important logging events. How it works? Why don’t you test it in JRuby?

All Your Famous Friends
Originally uploaded by Thomas Hawk

I have waited for this news, JRuby 1.0.0RC3 Released – And This Is It!

I have already managed to run an example of JRuby on Rails in Tomcat with PKI at work. So what I need next was an application development environment and I’ve got JRuby on Rails running on Tomcat inside Eclipse IDE with Eclipse WebTools Platform and Aptana’s RadRails plugin.

I already have a Tomcat package coupled with JASS (Java Authentication and Authorisation Service) framework at work, which works nicely within Eclipse IDE with WTP. So, I just needed to install RadRails as a plugin to that. I can only use RadRails to develop a Rails app, but can’t run it in WEBrick because it calls Java JASS API functions to get out other information about the user. However, you can add it to a Tomcat server as an external web module (you can’t add this as a web module because it’s not a web project, but a rails project) so that you can run the Rails app with JRuby in Tomcat within Eclipse! Here is a short instruction.

  1. Download the Eclipse + WTP all-in-one package
  2. Install RadRails and configure it
  3. Create a new Rails project
  4. Create a WEB-INF folder with necessary files in the root of the project
  5. Create a new server (e.g. Tomcat)
  6. Add the Rails project as an external web module to the server. You just point the directory where the Rails project resides in and give a path like /projectname.
  7. Start the server
  8. Open a browser in Eclipse and access the webapp (screenshot)

Related Posts:

Google Experimental – timeline view

Google Experimental was one of announcements made on Google Searchology Day.

I am particularly interested in their experiment on timeline and map views.

Being a big fan of SIMLE project, I thought it would be interesting to see the search results in Timeline or even Exhibit if they added XML or JSON feeds of the search results with “view:timeline” or “view:map” option.

Beside the early experiment of UI, the search results are not what I expected either. For example, I searched for “Alan Johnston” and the results are ordered by dates in its content, but not the timestamp of the content. There are not much news items on recent his disappearance. So I guess they are intended as biography.

What I expected was more like search results at News Archive like this. Maybe it’s different context. Anyway I’d like to see a timeline slider added to its timeline view, too.

Timelined view of search results are not new. has had it for some time and powered by FAST enterprise search has a timeline slider to refine search results by date.

I also came across Tony Hirst’s Jörn Clausen’s live earthquake mashup which combines a SIMLE Timeline with Google map. Very nice. [via Tony Hirst]

Related Posts:

Don’t Hurt The Web
Use Open Standard Mozilla Developer Center

I realised some of BBC Timelines were shown in Flash with XML data over HTTP. Firebug revealed their XML links! Thanks to Ben Metcalfe’s post for the pointer.

For example, “Fifteen years of the web” page loads XML data from here. It’s interesting, but the data is not re-usable for me to draw them in SIMILE Timeline easily.

The XML data contains Flash proprietary “textformat” tags! I know this particular example is not intended to be used openly, but it could have been a good “open” data source for mashup if they did not use the proprietary standards.

I have no experience in Flash programming at all, but my advice would be:

  1. Don’t use the proprietary Flash “textformat” tag in XML data.
  2. Use other supported HTML tags if necessary and put all inside a CDATA section.
  3. Use CSS to format text when needed.

BTW, “Timeline: The Blair Years” was shown in Flash when first published last week, but it has been replaced with HTML for some reason. Although its XML is still available, I can’t use it in SIMILE Timeline. Shame.

Related Posts:


Blog Stats

  • 87,535 hits