Tuesday, August 11, 2009

New Improved Industrial Strength Whoop Tooshy

As advertised in my earlier blog that noone read I found my Blaze cluster solution didn't work.

The Reason:
So creating a second subscription on the second server in the cluster stopped the "no active subscription" error which is nice, but it also tended to mean you didn't get your messages when polling against that server.
Clearly I needed a solution, one that actually works (rather than the half arsed hack I did before).

The Solution:
I still used the configurableAMFEndpoint and the ClusterMessagingFilterThingy but I changed some code in the filter. Now When a subscribe command comes in I store in the Tomcat session the cluster address of the server receiving the subscribe command (I still use the flexClientId + endpoint as the key). Then I extended the AMFEndPoint and overrode the handleFlexClientPollCommand() method to check the Tomcat session to see if the current server was the subscription server or some other server. If it was the subscription server I just continue on as normal. Otherwise I use an extended MessageService to grab the cluster manager and send the poll command to the subscription server. The how of how I did that is a kind of magic. I had to extend the JGroupsCluster object and some other JGroups thingy and I had to modify the Blaze JGroupsCluster to allow my extended object access to some of its guts. The real trick lies in once your subscription server has the poll request you need to launch a new thread to do the poll otherwise the JGroups cluster is blocked by the poll wait time (in my case 50 seconds because Mac Safari has a 60 second timeout on open but unanswered requests).

All The Code:
All the code can be added, but I'd need someone to actually ask for it because there is a fair bit of it and I'm essentially pretty lazy. No. You only think you understand how lazy I am, in reality I'm even more lazy than what you think. Kind of like estimating time to perform any given task in a project; you think you've added enough padding but no matter how much you add you always need to double it.