Autowiring components to a message bus in Javascript

When writing AJAX and SOFEA/SOUI applications, it's a best practice to use a client side message bus to integrate UI components. People recognized this as a best practice lately for GUI development with Swing. As a sidenote Werx was excellent for this but sadly is dead.

One of the ways to do message buses in Javascript is the OpenAjax Hub implementation or TIBCO PageBus.

Subscribing to messages on the bus is easy with the subscribe method:

jo.ListComponent = function() {
  OpenAjax.hub.subscribe("list.get") { 
    function(event, publisherData, subscriberData) {
      // do something when message arrives
    }
}         

When you have lots of those subscriptions though, they clutter up your code. Werx had the nice idea to autowire methods to messages and use the methods as message handlers. I thought I should do the same for Javascript and OpenAjax Hub.

jo.ListComponent = function() {
  this.$list_get = function(list) {
    // do something with list
  }
  // connect the methods
  jo.connect(this); 
}

Some magic happens in the connect method.

jo.connect = function(object) {
  for (var element in object) {
    if (element.charAt(0) == '$') {
      var event = element.substring(1).replace(/_/g, ".");
      var callback;
      // we need to capture the scope
      (function() {
        var fn = object[element];
        callback = function(event, data) {
          fn.apply(object, [data]);
        }
      })();
      jo.Bus.subscribe(event, callback);
    }
  }
}

The same could be achieved with a map of message handlers which is easy with functions in Javascript whereas in Java it takes more boiler code. A solution with methods as messages handlers as seen above has the benefit though that the object can contain other helper methods and state, which a map of message handlers can not. Using autowired methods makes your message bus code cleaner and more readable.

Thanks for listening.

Decided on a NAS: Zyxel, Infrant or Qnap

I needed a NAS urgently. There were several NAS in the game, the Zyxel 220 for the price, the Qnap 209 for the email notifications, the Infrant ReadyNAS because someone told me it was excellent and the Qnap 409, another 4-drive NAS. After some considerations, I chose the Qnap 409.

Why not the 209 or the Zyxel? As 2-drive NAS systems they both had no path for online migration to higher capacity drives. Also adding capacity is much easier for a 4-drive NAS than for a 2-drive NAS. Having two 750gb drives in the NAS and adding a third one will double the capacity from 750gb to 1.5tb. Whereas with a 2-drive NAS you have to replace the drives completely. The Infrant had some discussions on their forums with failed drives which stopped me from buying the ReadyNAS (Also they have been bought by Netgear). So the Qnap 409 is on it's way with two WD 750 GP drives for an initial RAID-1 setup.

Hope they work with time machine, or I have to buy an additional time capsule 😉

Update: Time machine works.

MacBook Pro, Cross Over Games and Half Life 2 – E2

Just say no. When hearing about Cross Over Games for running your Games for Windows with Mac OS X I thought wonderful, no more need for Bootcamp! After trying to play Half Life 2 E2 with Cross Over Games, it doesn't work. The installation from CD (Orange Box) took hours and then insisted on changing to the second CD. Problem was, my MacBook would not eject the first one because it was in use by the installer. Next try was downloading H2 with Steam. Took over 2 days and several tries when it stalled several times. In the end all was downloaded, but the game didn't start. What a bad experience. In no way is this an alternative to Bootcamp.

Update: Got Episode 2 running in Bootcamp after resizing the partition and using iDefrag (worth the $35) and reinstalling XP. E2 is one of the best games I've played in 25 years.