So far in JBoss, the standard and easy way to deploy a service as a Highly Available (HA) Singleton (meaning it will run only on the master node) is to copy it on all nodes of the cluster, in the ./deploy-hasingleton directory. The way it works, is that a special service (hint: look in ./deploy/deploy-hasingleton-service.xml) will essentially deploy whatever is under ./deploy-hasingleton, on the master node only. This is actually how HA-JMS will run in a clustered setup.

 

Since JBoss 4.0.4/3.2.8 there is an alternative way to do this. You can deploy your service as you would normally do by copying it to ./deploy or ./farm, but remember to add a dependency on:

 

jboss.ha:service=HASingletonDeployer,type=Barrier

 

The service will be deployed normally on all nodes, up to the create step, but will only be started on the master node! The advantage comparing to the previous method is that you can use farming, i.e. automatic distribution of the deployment through the ./farm directory. Or do a normal deployment (copy to ./deploy) on all nodes or just the few ones that will potentially run the singleton service. Note that in both cases you get hot-redeployment (which you don't get with the standard approach).

 

On the other hand, a disadvantage, or better a difference is that the singleton service is actually deployed (up to the create step) on all the non-master nodes, whereas with the ./deploy-hasingleton approach, it's not deployed at all. So any singleton logic will have to be coded in the start()/stop() methods of the singleton service.

 

If you want to find out more details of how this is implemented, take a look here.

 

Cheers
dimitris@jboss