« September 2007 | Main | November 2007 »

October 25, 2007

A Diamond in the Rough

Listen to this articleListen to this article

No, for once this has nothing to do with Ruby (deathly silence) rather, it concerns some problems many people have experienced when trying to use JNDI resources from Quartz jobs under Websphere.

In short, Websphere does not propogate any java:comp/env/ JNDI context to application created (ie non-container) threads. This is apparently by design with the upshot being that if you're using quartz you won't be able to use JDBC data sources from any jobs.

There a number of forum topics that discuss this problem along with various solutions including "use a 3rd-party connection pool instead." Hardly music to the ears when you've just spend the last 3 months converting a customer's entire application over to using JNDI resources. However, after much Googling, I happened upon an article that ultimately solved the problem in a Websphere-friendly manner. It even comes with sample code so you can get started almost immediately.

In essence, the solution makes use of Websphere's Asychronous Beans (and the Work Manager in particular) as a sort of thread pool. We then took this idea and adapted it around the use of Quartz's pluggable ThreadPool.

The final twist was the need to support both Websphere and Tomcat seamlessly without resorting to either build or deployment time configuration. For this we simply created a ThreadPool implementation that looks up the Work Manager in the JNDI context. If it exists, we assume that we're in Websphere and go from there; otherwise we use the default Quartz implementation and hope for the best :)

October 11, 2007

Conventional Validations

Listen to this articleListen to this article

As part of some other work I'm currently undertaking, I've just extracted a VERY new Rails plugin called, you guessed it, Conventional Validations.

As the README says, Conventional Validations is a plugin that attempts to apply validation based on the naming of column. Specifically, the plugin searches for validation methods such that a column named foo or ending in _foo would be validated using a method named validates_foo.

For example, by defining a class method as:

def self.validates_phone(*attr_names)
  validates_format_of attr_names, :with => /[0-9]+(\.[0-9]+)*/, :allow_nil => true 
end

Any columns named phone or ending in _phone would be automatically validated.

I've only just added it (it's only available in trunk) and the matching rules are VERY simplistic but if you have company-wide or even project-wide validation and you're strict about your naming conventions (as I am), consider extracting them into a module and mixing them into ActiveRecord::Base and letting the plugin apply them for you.

There are already some existing plugins such as (off the top of my head) "validates_email" that would most likely just work out of the box.

Enjoy.

October 07, 2007

FarceBook

Listen to this articleListen to this article

WOW! It's been a while since I found something non-politcal to have a good old rant about but dear god what's with facebook!? After being harassed for months with invitations by people I usually respect, I finally caved and signed up. What a load of bollocks!

So the idea is we want people to find one another. OK I got that. Then you only really want to link to friends. OK that sounds great. Then once we're connected, we can...send each other messages via a web page. Holy cow! What an idea! I wish I'd thought of that. Even better, when I receive one of these master pieces I get...wait for it...an email telling me there's a message waiting to be read. Fan-bloody-tastic.

My wife tells me I don't appreciate it because I'm not "as social as other people" I suspect it's more because I'm not bored out of my brains at work with nothing better to do with my time or my life for that matter!