Did you try putting the state of your HASingleton in a distributed cache (like JBossCache ) instead of having it locally on your Master Singleton alone? So when the master dies and one of the slaves is promoted to Master, the state should be still accessible to it via the distributed cache. No?
Thanks for your response.
Yes this is exactly what I am doing now, I only wish I had known of this possibility before wasting so much time trying to use a Singleton. I now have MBeans which use the TreeCacheAop service with synchronous replication, and except for a few minor problems it is working flawlessly.
Try using DistributedState of HAPartition. I have similar application where I need to share information in two nodes. All my caches are stored in DistributedState. Whenever this state is changes, jboss frameworks informs all the nodes about change in state.
DistributedState is ok but JBossCache is now recommended for the state replication since future DistributedState will be refactored using cache underneath as well.
Does the use-case above appear in any of the cache docs? If you have any more info on this, I would very much like to read it. I want to do something similar to the above, i.e., access a distributed cache from EJBs in order to implement an in-memory, cluster-aware singleton.
I was reading through this doc:
I'm not sure what is necessary to integrate those examples into an EJB. Can I get a reference to a cache instance similar to the way I get, for example, a Hibernate SessionFactory via JNDI?
Thanks in advance for your help.
If you deploy your TreeCacheAop as a mbean service, you can then access from ejb (directly or through a wrapper). As a result, all memebers in the group will have the replicated state.