This content has been marked as final.
Show 5 replies
-
1. Re: Bean call bean on muti machines with multi JBoss server
genman Oct 10, 2007 2:32 PM (in response to changemylife)See this example:
http://www.laliluna.de/ejb-3-tutorial-jboss.html
Create a client class on Server1 to connect remotely to Server2. -
2. Re: Bean call bean on muti machines with multi JBoss server
genman Oct 10, 2007 2:33 PM (in response to changemylife)
public class FirstEJB3TutorialClient {
is a good example; use the java.util.Properties object to set the hostname and don't use jndi.properties on Server1. -
3. Re: Bean call bean on muti machines with multi JBoss server
changemylife Oct 10, 2007 11:39 PM (in response to changemylife)But my design is:
On the Server1, I have the bean called BeanA. It's simply:@Remote public interface Check { public boolean isValid(double a, double b); }
and bean class:public @Stateless class CheckBean implements Check { public boolean isValid(double a, double b) { if (b == 0) return false; else return true; } }
Ok, I deploy BeanA on Server1.
Now, On the Server2, I have the bean called BeanB@Remote public interface Divide { public double divideNumber(double a, double b); }
And bean class:public @Stateless class DivideBean implements Divide { private Context context; public double divideNumber(double a, double b) { Context ctx = lookupServer(); double result = 0; try { Check check = (Check)ctx.lookup("CheckBean\remote"); boolean flag = check.isValid(a, b); if (flag) result = a / b; else result = 0; } catch (NamingException e) { e.printStackTrace(); } return result; } private Context lookupServer(){ Properties properties = new Properties(); properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces"); properties.put("java.naming.provider.url","server1:1099"); <-- lookup on Server1 try { context = new InitialContext(properties); } catch (NamingException e) { e.printStackTrace(); throw new RuntimeException(e); } return context; } }
Ok, I deploy BeanB on Server2. But here, I must copy BeanA and paste deploy folder on Server2. How I don't do this (maybe configure to Server2 recognize BeanA)
The Client application on the difference machine:Properties properties = new Properties(); properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces"); properties.put("java.naming.provider.url","server2:1099"); <--- lookup on Server2 Context ctx = new InitialContext(); Divide div = (Divide)ctx.lookup("DivideBean/remote"); div.divideNumber(10,2)
Have some ideas ?
Thanks. -
4. Re: Bean call bean on muti machines with multi JBoss server
jaikiran Oct 11, 2007 3:39 AM (in response to changemylife)I must copy BeanA and paste deploy folder on Server2 . How I don't do this
You dont have to copy the bean implementation of BeanA to Server2. You will just have to copy the bean interface (in this example the interface Check) to the Server2.
-
5. Re: Bean call bean on muti machines with multi JBoss server
changemylife Oct 11, 2007 11:34 PM (in response to changemylife)Hi !
Thanks very much. I solved my problem.