5 Replies Latest reply on Oct 11, 2007 11:34 PM by LeQuoc Thai

    Bean call bean on muti machines with multi JBoss server !

    LeQuoc Thai Novice

      Hi all !

      I use jboss-4.0.5.GA, EJB 3.0.

      I have installed JBoss server on two difference machines.

      On the first machine, I have a bean called BeanA (has a method called hello()). ---> BeanA was deployed on the first machine
      On the second machine, I have a bean called BeanB. ---> BeanB was deployed on the second machine.

      Now, on the BeanB, can I call hello() (belong BeanA) ? Both of JBoss server (first and second machine) are running. Can BeanA lookup BeanB but on the difference machines ? If ok, where I must config ?

      Please guide to me or show me some link about my problem !

      thanks.

        • 1. Re: Bean call bean on muti machines with multi JBoss server
          Elias Ross Master

          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
            Elias Ross Master


            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
              LeQuoc Thai Novice

              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 pai Master

                 

                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
                  LeQuoc Thai Novice

                  Hi !

                  Thanks very much. I solved my problem.