Accessing HA-Singletons in AS 7
tory.mckeag Nov 27, 2012 5:40 PMHi, I'm porting an app from JBoss 5 to 7. I have an HA singleton EJB (annotated using org.jboss.ejb3.annotation.Service in JBoss 5) that I was able to access before from any node in the cluster. Essentially, I would be able to call the EJB and it would only be invoked on the master node at any given time, by looking it up in HA-JNDI, like this:
private static final Properties p = new Properties(); static { // The partition name may be overridden via system properties. String partitionName = System.getProperty("jboss.partition.name"); if(partitionName == null) { partitionName = "DefaultPartition"; } p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); p.put("jnp.partitionName", partitionName); } public static Object lookupSingleton(String name) throws NamingException { Context ctx = new InitialContext(p); Object result = ctx.lookup(name); return result; }
Now, I've read the example I found in the EAP documentation here: https://access.redhat.com/knowledge/docs/en-US/JBoss_Enterprise_Application_Platform/6/html-single/Development_Guide/index.html#TopicID9154
I can make that work, and that's cool- part of the problem just to make it start and stop just on one node. But I still don't know how to access it. The example is unfortunately trivial; passing a string from the singleton isn't very interesting. What I want is for any node on the cluster to be able to call various methods on the service.
How do you do this in JBoss 7? I tried using an EJB reference for the returned result of getValue(), but that just seems to call the EJB in the local JVM after it's returned. Is there a way I can return the node name (as the sample does), and use the EJB Client API to get a reference to an EJB on the master node?
Help?