I am using JBoss 4.0.4RC1 and trying to leverage round-robin load balancing for dividing up work that needs to be performed server side. My approach is to have two EJB classes: EJBWork, and EJBWorker. EJBWork will get though HA-JNDI a reference to EJBWorker and submit parts of the job to execute to that bean. There is only one instance of EJBWork in the cluster, and many instances of EJBWorker. Using the smart stub returned from HA-JNDI, the EJBWork bean will distribute the job among the cluster nodes that have the EJBWork bean deployed.
As per the JBoss documentation, EJBWork looks up EJBWorker using the HA-JNDI port passed to the InitialContext:
Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "localhost:1100"); return new InitialContext(p);