-
1. Re: Accessing the Singleton Servic MBean
kaobe Mar 11, 2004 1:54 AM (in response to remrick)Hi Ron,
I am working on this problem for several days now, and I can tell you what I learned so far.
First, the SingletonService is a MBean, that means you have to invoke a method on it with the help of a MBeanServer or an RMIAdaptor. This looks something like this:RMIAdaptor server = (RMIAdaptor) new InitialContext().lookup("jmx/rmi/RMIAdaptor"); ObjectName name = new ObjectName("jboss:partitionName=GVP_MK,service=DistributedState"); // Invoke the set(String, Serializable, Serializable) method String[] sig = { "java.lang.String", "java.io.Serializable", "java.io.Serializable" }; Object[] opArgs = { "category", "key", "value" }; Object result = server.invoke(name, "set", opArgs, sig);
In this example you set a value in the DistributedState Service. I think it would be possible to use something like server.setAttribute, but this was the first solution I had and it works. ;)
The problem by trying to address the SingletonService in this way is, that you get the Service on the Node that you are currently connected to. And this one might not be the Master node.
The SingletonService as I understand it, works in that way, that it thinks, the Singleton has to do something when being started and stopped. That works perfect as I see it.
I needed a Singleton that can be addressed via tha SingletonService at any time and perform a method then. So I implemented my own SingletonController and let it call a method on the whole cluster, so that every node gets the call. The action is only performed by the master, so I can be sure that it is real singleton behaviour.
I hope this helps you and was, what you needed to know...
Peter -
2. Re: Accessing the Singleton Servic MBean
remrick Mar 11, 2004 6:37 AM (in response to remrick)Thanks Peter for the insight.
After wading through the docs I found talk of the RMIAdaptor and things became a bit more clear to me. Your reply makes a lot more sense to me now than if I had not seen the discussion about it in the docs.
Another thought I had was using the SingletonService to bind 1 and only 1 instance of an object that it "owns" to the JNDI tree (actually HA-JNDI). For instance, a RO cache (i.e. Hashtable). Clients could then gain access to the cache via a simple JNDI call and then make calls upon the object like any other Java object. This is an idea I plan on testing today. I'll post my findings...
Thanks,
-Ron -
3. Re: Accessing the Singleton Servic MBean
kaobe Mar 11, 2004 9:19 AM (in response to remrick)Hi again,
for your idea with the data cache you could look at the DistributedState Service. I use it to manage clusterwide unique data. The data is manipulated only by the Singleton so that it stays unique.
The DistributedState is explained in the Cluster docu.
Peter -
4. Re: Accessing the Singleton Servic MBean
remrick Mar 11, 2004 10:17 AM (in response to remrick)Will do Peter. Thanks again!
-Ron -
5. Re: Accessing the Singleton Servic MBean
michael.daleiden Mar 16, 2004 1:52 PM (in response to remrick)"kaobe" wrote:
Hi again,
for your idea with the data cache you could look at the DistributedState Service. I use it to manage clusterwide unique data. The data is manipulated only by the Singleton so that it stays unique.
The DistributedState is explained in the Cluster docu.
You might also want to check out JBossCache, which IMHO is easier to work with than DistributedState. I originally started out using DistributedState to manage cluster-wide data, but after tinkering with the JBossCache, I found it to be much more straightforward. Also, from everything I have read, JBossCache is the direction JBoss is moving in for implementing distributed data management.
Check it out at http://www.jboss.org/developers/projects/jboss/cache/index.html -
6. Re: Accessing the Singleton Servic MBean
remrick Mar 21, 2004 9:08 AM (in response to remrick)Hi Michael,
After experimenting and working with the DistributedState it appears it will not suite all my needs. For one it is not transactional and modifying the state is a problem in a clustered environment.
I am currently looking at the JBossCache and it appears that it may suite my needs much better. It's transactional which is something I definitely need.
Thanks for help and validating some of the thoughts I was having.
-Ron