I want to have an object in which I store user activity information, and I want this object to be replicated across all nodes of a cluster. When one node of the cluster fails I don't want to lose the data being stored in this object. Essentially it will act as a central and unique (global) repository for my application's user activity information. No matter which node's Servlets service the user's requests the user activity information record (containing login time, last error, etc., updated at each request) should be stored in the same object, which should survive a crash of one or more nodes of the cluster. In this way I will be able to see all user information from the same UserActivityManager object (I plan to view this data using MBean methods).
I already have such a class coded and working as an HASingleton MBean, but it is a bit clunky and does not support failover whenever the master node of the cluster goes down. From what I've been able to find out it appears that I will never be able to get true failover capabilities using this Singleton-based approach, and need to come up with a better solution. I am hoping that JBossCache will be able to do the trick.
I have created an MBean class, UserActivityManager, which stores the user activity records in a TreeCacheAop member object. This MBean is deployed in its own SAR file in the deploy directory. In this SAR I have the UserActivityManager MBean class and interface, as well as two deployment descriptors: jboss-service.xml, which describes the MBean itself (with just a code and name), and replSync-service.xml, which I use to configure the TreeCacheAop object (this is the replSync-service.xml from the example, unaltered).
So far I have not been able to get the MBean to either replicate or failover as I'd like, and before I spend too much more time with it I wanted to ask here to make sure that I will be able to make this work as I want. If not then hopefully someone can suggest a better idea.
If this is the right approach then how should I go about configuring the MBean and/or TreeCacheAop to get the behavior I'm looking for ? How do I make it so that only one of these MBeans is used by all nodes of a cluster ? If this is not the right way to go about this then what is a better option ? I have considered/suggested using Hibernate objects for this instead, but my manager is against the idea of using a database for this sort of temporary persistence. (It seems like a logical solution to me, but I'm somewhat of a rookie and hence have little decision making clout.)
If anyone can comment on the above I will certainly appreciate the feedback. I am by no means an expert on this sort of thing and will gladly consider any reasonable advice. Also I can post my MBean code and deployment descriptors if this will help.
Thanks in advance.
I am not sure if I understand your question fully. But here is what I think.
1. We have plan to support MBean clustering using JBossCache in the future.
2. Meanwhile, if you want to do it yourself, you can have MBean sit on top of the Cache. Then to notify the MBean of a cache update, you subscribe to TreeCacheListener event.
Thanks for the reply Ben. Probably you didn't understand my question because I was a little long-winded and not altogether to-the-point. I'll try to state what I want to do more succinctly.
* I want to maintain a unique (global) collection of objects (user activity records) for a clustered application.
* I only want to have one and only one such collection of objects, no matter how many nodes I have in my cluster.
* The collection of objects should be available to the application components (Servlets and EJBs) across all nodes of the cluster.
* I will update an object in this collection whenever there is a user activity.
* A crash of one or more nodes of the cluster should not hose the collection, i.e. it should still be intact and available to all other surviving nodes of the cluster.
What I'm asking is whether or not I can cook up an MBean (or any other component) which uses JBossCache to store a collection of objects and which can be available to all nodes of a cluster and survive a failure of the node it was started on. If so then how would I deploy the MBean so that it behaves essentially as a Singleton, with both replication and failover, without resorting to an HASingleton approach (since that doesn't appear to provide replication or failover) ?
I have tried this already using an MBean (I'm calling it UserActivityManager) which stores the objects in a HashMap, and which is deployed as an HASingleton. It is working well but still it's only a partial solution since HASingletons don't appear to support true failover, in that when the master node which provides the HASingleton goes down the HASingleton MBean is lost for good (no real replication or failover). With this approach I need to access the object collection via the MBean by way of an RMIAdaptor. You can see details of this in a posting I added a few months back: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=55794. My feeling is that this is really a hack and that there must be a more elegant solution. I have been instructed by my manager to investigate using JBossCache instead, and from my preliminary efforts at getting it to work it looks as if this is not the right thing to be using for the job. The idea is that I can use JBossCache as sort of an in-memory cache where I can store my objects, and since JBossCache looks to have some replication abilities I assumed that it could be used to replicate and share a cache of objects across nodes of a cluster. It's not clear to me that this is true, and that maybe my idea of replication is not the same thing as the replication provided by JBossCache. As far as failover goes it doesn't appear to be provided by JBossCache either, and if not then it is definitely not the right service to be using for the solution I need.
My impression is that instead of using JBossCache this would be a better solved by using Hibernate objects, since the objects I want to store could be kept in a central persistent database and accessible to all components of my application regardless of which node of a cluster they happen to be running on at the time of access. In this approach I wouldn't need to maintain the object collection in an MBean itself but instead the MBean would access the objects as Hibernate objects, as would the other components of the application. There would be no need to roll my own replication and failover capabilities (as I'm currently doing by using an HASingleton MBean) since this is provided by virtue of keeping the objects in a central database which is not going to lose the data if any one node of my clustered application fails.
What I'm hoping for is some guidance from those of you reading this forum who are more experienced and knowledgeable on these topics, as I'm not enough of an expert to be able to say one way or another which approach is best. I don't want to waste my time again by using the wrong tool for the job.
I've again been long-winded, but hopefully I've explained the problem more clearly. Thanks in advance for any suggestions or insight.
After looking into this more it seems that what I want to do can in fact be done with JBossCache, and in a more elgant manner than what I had originally thought of myself (no big surprise). I can just use the TreeCacheAop MBean to hold all of the objects that I want to replicate across all nodes of a cluster. My EJBs, Servlets, and MBeans just access the TreeCacheAop MBean when they need to get or put objects, and they will all be accessing the same data by virtue of the replication provided by JBossCache. (Someone please let me know if I am still mistaken !)
Sorry to have wasted bandwidth by my "thinking out loud" in this thread. Hopefully it will at least be helpful to another JBossCache beginner in the future.
I'm trying to solve the exact same problem. Would you be willing to post some of the details of the MBean you wrote? Thanks very much for writing out the thoughts above.
Hi Justin. I have made another posting to this forum which hopefully explains my approach: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=63328. Basically I have written an MBean which uses a TreeCacheAop service to cache some objects, and it is supposed to synchronously replicate across all nodes of a cluster. In my opinion this design is much better/cleaner than using a HASingleton. Unfortunately it still isn't working for me, in that the replication only happens on the original TreeCacheAop.putObject() call (when a new object is added to the cache), and subsequent modifications to cached objects only take effect in the cache on the local node of the cluster. According to the JBossCache developers this is not supposed to happen and the replication should actually work using the approach I've taken. So I must be missing some piece of the puzzle, but as yet I haven't been able to figure it out on my own. If you take this same approach and actually get the synchronous replication to work as advertised then I'd be interested in seeing your code.
Good luck, and let me know if I can provide any other details which might help you out.
I found that thread and was reading through it. If you don't mind, could you email me the MBean (maybe remove your bizlogic) and whatever else is needed to get it deployed, and I'll use that as a starting point. Since we're both trying to do the same thing, hopefully two minds will solve the problem faster than one. We should take the correspondence offline then post a working solution here when/if it is found.
Thanks for your help
jcasp at bellsouth net