0 Replies Latest reply on Jul 12, 2007 11:51 PM by Alena Sviridova

    Home and component interface references in clustered JBoss

    Alena Sviridova Newbie

      Hi all,

      I have a questions about home or component interface references in clustered JBoss, about how they are saved, replicated and managed. They always say "try it" so I wrote a small example to illustrate my point. Basically my question is about how and why home, component and local home references work in clustered JBoss. I would very much appreciate an expert opinion. Below is my example. Many thanks to you all in advance.

      I run JBoss 4.0.5 as a cluster (I put apache with mod_jk) on two boxes, say box1, box2 which makes two nodes: node1, node2 respectively and I use farming to deploy my ejbs. So I put myEjb.jar into farm on node1 and it get distributed to node2
      I enabled a NON-sticky approach (just a test to illustrate my question and be able later on to go to another server that does not support sticky) so requests go a box1/box2/box1.... in a round-robin manner.
      The call is like this JSP -> servlet -> SFSB. I am testing this Stateful Session Bean (let's call it AddressManagerHome). It is a facade for two other stateful beans (it is just a test to illustrate my question). Servlet gets reference to component interface of the bean and stores it into the request.

      For this particular test my SFSB has 3 instance variables (here they are just to make things clear)

      protected AddressHome addressHome = null; (reference to home interface)
      protected Address address = null; (reference to component interface)
      protected WorkAddressLocalHome workAddressHome = null; (reference to local home interface)

      they are all initialized in ejbCreate of the bean. So I create bean in the servlet like this
      public class AddressManagerServlet extends HttpServlet {
      AddressManagerHome home = (AddressManagerHome) ServiceLocator.getInstance().getRemoteHome(.....);
      AddressManager bean = home.create();

      where testAll() does 3 things:
      1. for home reference (addressHome) it creates component interface and calls method :
      Address bean = addressHome.create();
      2. for component reference (address) it just calls method :
      3. for local home interface it creates home component reference and calls method :
      WorkAddressLocal bean = workAddressHome.create();

      Now, the 1st request goes to node1 and everything works fine. Then 2nd request (same session, I use encodeURL) goes to node2 and everything is fine again. WHY????
      I understand why case N1 is fine, we just have reference to remote home so no problem there but why in case N2 it is fine? If we created ejbObject on node1 and then call it from node2? How is node2 even aware of address bean being created earlier in node1?? Shouldn't it say I have no idea, create reference to component interface again?

      And why is case N3 is fine? It is a reference to local to home. Which is by definition local to VM ! So if WorkAddressLocalHome is created in node1 then node2 should have no idea what it is. So how does exactly clustering in JBoss work?