0 Replies Latest reply on Jan 8, 2015 9:41 AM by Subrahmanya Pendyala

    How to get clustered JNDI context with in a servlet to look up an EJB in JBoss 5.0.1 GA cluster ?

    Subrahmanya Pendyala Newbie


      I  have created two nodes in Jboss cluster. I have deployed an EAR containing EJB Jar and a web application WAR.

      When I try to look up the EJB  from a stand alone client, my request is getting processed by the EJB's evenly . Means.., if I make 3000 requests, 1500 requests are getting processed by each node.

       

      How ever the same behavior is not seen when I make a call to the EJB from a servlet. (http://<host>:port/ <WebContextRoot>/Servet

       

      Code snippet in standalone client:

      private MyUtilBeanRemote getMyUtil() throws NamingException {

       

        Properties p = new Properties();

        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

        p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");

        // HA-JNDI is registered under the partition name passed to JBoss via -g 

        String bindAddress = System.getProperty("jboss.bind.address", "172.25.129.81");

        p.put(Context.PROVIDER_URL, bindAddress + ":1100"); // HA-JNDI address and port.

        String partitionName = System.getProperty("jboss.partition.name", "HPPCluster");

        p.put("jnp.partitionName", partitionName);

        Context ctx = new InitialContext(p);

        MyUtilBeanRemote remote = (MyUtilBeanRemote)ctx.lookup("ejb/MyUtil");

        return remote;

      }

       

      Code snippet in Servlet:

      ------------------------------------

       

      private MyUtilBeanRemote getMyUtil() throws NamingException {

       

        Properties p = new Properties();

        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

        p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");

        // HA-JNDI is registered under the partition name passed to JBoss via -g 

        //String bindAddress = System.getProperty("jboss.bind.address", "172.25.129.81");

        p.put(Context.PROVIDER_URL, "172.25.129.81:1100");

        //p.put(Context.PROVIDER_URL, bindAddress + ":1100"); // HA-JNDI address and port.

        String partitionName = System.getProperty("jboss.partition.name", "DefaultPartition");// Even tries with HPPCluster which is my name of the cluster

        p.put("jnp.partitionName", partitionName);

        Context ctx = new InitialContext(p);

        MyUtilBeanRemote remote = (MyUtilBeanRemote)ctx.lookup("ejb/MyUtil");

        return remote;

      }

       

      JBoss configurations done:

       

      Copied the all distribution as node 1 and node 2 on same machine .

      Used the following commnds to start the cluster nodes;

       

      run.bat -c node1 -g HPPCluster -u 239.255.100.100 -b 172.25.129.81 -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-default

      run.bat -c node2 -g HPPCluster -u 239.255.100.100 -b 172.25.129.81 -Djboss.messaging.ServerPeerID=2 -Djboss.service.binding.set=ports-01

       

      Is there any additional steps which I have missed out for cluster configuration in JBoss 5.0.1 GA ?