Clustered JBoss 6 Restart with EJB3 Stateless
saifeldeen Jun 8, 2012 4:58 AMHi all,
App server: JBoss AS 6.1.0 Final
I am using JAS6 in a 2 node cluster. I have a single EJB (see below) that simply prints out a System.out when invoked by the test client. I see both instances in my cluster being invoked, which is great. I then shutdown instance 1 in the cluster. Instance 2 then handles subsequent invocations from my test client. I then restart instance 1 (wait until it has completely started) and then shutdown instance 2. My client then throws the following exception and stops working:
java.lang.RuntimeException: cluster invocation failed, last exception was:
at org.jboss.aspects.remoting.ClusterChooserInterceptor.invoke(ClusterChooserInterceptor.java:173)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
...
Caused by: org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection for InvokerLocator [socket://192.168.1.35:3873/?timeout=300000]
at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:831)
at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:169)
... 38 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
TestEjb.java |
---|
import javax.ejb.Stateless; import org.jboss.ejb3.annotation.Clustered; import org.jboss.ejb3.annotation.LocalBinding; import org.jboss.ejb3.annotation.RemoteBinding; @Stateless @Clustered(partition = "DocsPartition", loadBalancePolicy = "org.jboss.ha.client.loadbalance.RoundRobin") @LocalBinding(jndiBinding = "TestEjbLocal") @RemoteBinding(jndiBinding = "TestEjbRemote") public class TestEjb implements TestEjbLocal, TestEjbRemote { static int count; public void testX() { String str = "invoked " + ++count + " times"; System.out.println(str); } } |
Client.java |
---|
public void testEjb() throws Exception { InitialContext context2 = null; Properties jndiProps2 = new Properties(); jndiProps2.put("java.naming.security.principal", "guest"); jndiProps2.put("java.naming.security.credentials", "guest"); jndiProps2.put("java.naming.factory.initial", "org.jboss.security.jndi.JndiLoginInitialContextFactory"); jndiProps2.put("java.naming.provider.url", "192.168.1.35:1100,192.168.1.35:1200"); context2 = new InitialContext(jndiProps2); TestEjbRemote testEjb; testEjb = (TestEjbRemote) context2.lookup("TestEjbRemote"); for (int i = 0; i < 100; i++) { testEjb.testX(); System.out.println(i + ": Logged test action"); Thread.sleep(5 * 1000); } } |
I have seen a number of postings such as:
Also, some JIRA issues which discuss this, but present no solution:
I have found some information regarding a "RetryInterceptor" from the JBoss Clustering documentation (for JAS 5.x only) at this link https://community.jboss.org/wiki/RetryInterceptor however this doesn't appear to help either.
I would like for the "smart proxy" to automagically re-associate with the instances that are running, however, it doesn't appear to do so.
Does anyone have a solution to this problem - other than do a JNDI lookup each time, hence disallowing any caching of my EJB's in the code?
Many thanks
Saifeldeen