Clustered EJB on AS 5.1
vdeminico Jun 28, 2011 5:08 AMHi,
I have a problem executing a @Clustered ejb on a cluster. Cluster has two nodes executing on different machines and it's correctly configured (log says that there are two members). I use Jboss 5.1.0GA AS.
Code for clustered ejb 3.0 is:
import javax.ejb.Stateless;
import org.apache.log4j.Logger;
import org.jboss.ejb3.annotation.Clustered;
/**
* Session Bean implementation class TimsocialClusteredProva
*/
@Stateless(name="clusteredEjb")
@Clustered
public class TimsocialClusteredProva implements TimsocialClusteredProvaRemote {
private static Logger log = Logger.getLogger(TimsocialClusteredProva.class);
/**
* Default constructor.
*/
public TimsocialClusteredProva() {
// TODO Auto-generated constructor stub
}
public String sayHello(String nome) {
log.info("Param: " + nome);
return "Hello " + nome;
}
}
and remote interface is:
import javax.ejb.Remote;
@Remote
public interface TimsocialClusteredProvaRemote {
public String sayHello(String nome);
}
The client is a servlet deployed into the same ear:
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String ejbName = null;
String jndiService = request.getParameter("jndi");
TimsocialClusteredProvaRemote clusteredEjb=null;
try {
Properties properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming");
properties.put("java.naming.provider.url", jndiService);
Context ctx = new InitialContext(properties);
ejbName = "timsocial-ear-0.0.1-SNAPSHOT/clusteredEjb/remote";
log.debug("Fetching remote ejb: " + ejbName);
clusteredEjb = (TimsocialClusteredProvaRemote) ctx
.lookup(ejbName);
} catch (NamingException e) {
log.error("Error in lookup ejb with jndi-name: " + ejbName, e);
}
for (int i=0;i<100;i++) {
log.info(clusteredEjb.sayHello(i + "Valerio "));
}
}
I invoke servlet with "jndi" parameter setted to HA-JNDI or local JNDI... but the result is always the same: all invocations are executing on a single server (the one local to servlet).
When EJB is deployed, this message is displayed into AS console log:
2011-06-28 10:59:52,515 DEBUG [org.jboss.ha.framework.server.HATarget] (AsynchKeyChangeHandler Thread) replicantsChanged 'jboss.j2ee:ear=timsocial-ear-0.0.1-SNAPSHOT.ear,jar=timsocial-ejb-0.0.1-SNAPSHOT.jar,name=clusteredEjb,service=EJB3socketDefaultPartition' to 1 (intra-view id: 1554486437)
What is wrong????
Thanks.
Valerio.