Fail-Over on EJB stateless fails (!!) (UndeclaredThrowableEx
twingocerise Jun 29, 2004 5:47 PMHi,
i got a problem, and i know you got the solution (please ;) ).
In order to study clustering in JBoss, i need to create a EJB stateless and show, using 2 instances of JBOSS on my pc, how fail-over operates when one node is down.
I use this code (my remote ejb interface is called Clustered):
try{
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "");
InitialContext jndiContext = new InitialContext(properties);
Object ref = jndiContext.lookup(ClusteredHome.JNDI_NAME);
ClusteredHome clHomeBean = (ClusteredHome) PortableRemoteObject.narrow(ref,ClusteredHome.class);
for(int i=0;i<5000;i++){
Clustered clustered = clHomeBean.create();
System.out.print("Call ... ");
// just doing a println and a Thread.sleep(100)
clustered.call("Appel 1-"+i,100);
System.out.println("OK");
// in order to save some cpu time for eclipse IDE during test
Thread.sleep(10);
}
}
catch(Exception e){
System.out.println(" KO ");
System.out.println("Exception : "+e);
e.printStackTrace();
}
My EJB got only 1 method :
public void call(String toDisplay, int time) throws RemoteException {
System.out.println(toDisplay);
try {
Thread.sleep(time);
} catch (Exception e) {
System.out.println(e);
}
}
The configuration is as simple as possible. the "ALL" config is launched and the jboss.xml contains a simple tag "clustered" containing true for the only deployed bean.
I run 2 instances of the server (changing port to avoid conflicts) and i run my little test main()
All's running well until i kill one instance. a very nice exception is thrown :
java.lang.reflect.UndeclaredThrowableException
at $Proxy3.call(Unknown Source)
at com.oosphere.clustering.TestCluster.main(TestCluster.java:48)
OOoOoopps... what is the problem...?
what I can say is both servers are called (printlns) and when i call the home.create() outside of the loop, it works well ! And it also works when i put all the lookup inside the loop...
Is it possible to keep a HomeInterface reference and to use it safely in a cluster architecture ?
Is there any extra-config to had for this ?
Thanks.
Vivien.