In that recent Ruby piece, I remarked that Ruby threading struck me as kind of feeble, and that threading is getting real important. Well, I know one way to solve that problem. So I tracked down JRuby geek Tom Enebo and got some news and he pointed to me to some code that I think is pretty cool.
On that threading thing, Tom tells me that “We currently implement Ruby threads using Java native threads. It is our plan to continue doing so.” So, JRuby is ready for the threading era.
Rome · Tom also wrote “Java’s library ecosystem is gigantic. If you have ever thought of it, then some guy in Prague has a library that does it.” One library that I care about a lot is Rome, the RSS/Atom reading/writing package. Tom pointed me to this, originally written for a Polish computer magazine. He didn’t bother to tell me what it does, and remember, I only really started looking at Ruby last week, but it’s obvious: in 50 lines (15 if them requires and includes), it reads a list of feed URIs off the command line, aggregates them all together, and generates a new feed containing either the last 24 hours’ worth or some other number of hours from a command-line option, and runs the output through an XSLT filter.
Here are a few of my favorite morsels:
include_class('java.util.Date') {|p,n| "J" + n }
This arranges for Java’s Date class to be called JDate in JRuby code.
ARGV.each do |arg|
feed = SyndFeedInput.new.build(XmlReader.new(URL.new(arg)))
feed.entries.each do |entry|
entry.setTitle "#{feed.getTitle}: #{entry.getTitle}"
aEntries << entry
end
end
This loads a Rome instance from each of the URIs on the command line, decorates its title with its source, and jams it into the aggregate feed.
Whatever you call this mash-up of dynamic postmodern languages and Java infrastructure and low-rent syndication technology, I think it’s gonna catch on.