5 Replies Latest reply on Aug 17, 2004 8:58 AM by ganguri

    Clustering - StringIndexOutOfBoundsException Exception

    ganguri

      We are clustering multiple instances of jboss. We are using RpcDispatcher to send the requests. When we try to make a method call on the client instances, they are throwing StringIndexOutOfBoundsException error, which is reflected in the server that tried to invoke the remote method.

      The code we are using is as follows:

      package com.test.cluster.jboss;

      import org.jgroups.*;
      import org.jgroups.blocks.*;
      import org.jgroups.util.*;

      //import java.util.ArrayList;
      //
      //import org.jboss.ha.framework.interfaces.*;
      //import org.jboss.ha.framework.server.*;

      import com.test.util.*;
      //import java.lang.reflect.Method;

      public class RpcDispatcherClient implements java.io.Serializable
      {
      private Channel channel;
      private RpcDispatcher disp;
      private RspList rsp_list;
      private String props;

      public RpcDispatcherClient() throws Exception
      {

      }

      public RpcDispatcherClient(String key, String id) throws Exception
      {
      invoke(key, id);
      }

      private void invoke (String key, String id)throws Exception
      {
      System.out.println("Props: " + props);

      /*
      HAPartition hapi = new HAPartitionImpl("DefaultPartition", new JChannel(props), true);
      hapi.registerRPCHandler("RpcDispatcherClient", this);

      //String localIP = InetAddress.getLocalHost().getHostAddress();
      System.out.println("########################## before callMethodOnCluster method call...");

      System.out.println("########################## PartitionName: " + hapi.getPartitionName());


      System.out.println("########################## clusterview id: " + hapi.getCurrentViewId());

      ArrayList arr = hapi.callMethodOnCluster("CacheNotify", "invoke", new String[]{key,id}, true);

      System.out.println("arr.size: " + arr.size());

      System.out.println("########################## after callMethodOnCluster method call...");
      */
      }

      public void invokeCacheNotify(String key, String id) throws Exception
      {
      Notifiable notify = new Notify();
      notify.invoke(key, id);
      }

      public void start(String key, String id) throws Exception
      {
      try
      {
      channel = new JChannel(props);

      System.out.println("Is Channel connected? " + channel.isConnected());
      if (!channel.isConnected())
      channel.connect("DefaultPartition");
      System.out.println("Channel name? " + channel.getChannelName());
      disp = new RpcDispatcher(channel, null, null, this);

      System.out.println("Server Object name? " + disp.server_obj.getClass().getName());

      rsp_list = disp.callRemoteMethods(null, new MethodCall("invokeCacheNotify", new String[]{key,id}, new String[]{"java.lang.String","java.lang.String"}), GroupRequest.GET_ALL, 0);

      channel.close();
      disp.stop();
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      }

      public static void main(String[] args)
      {
      try
      {
      new RpcDispatcherClient().start(args[0], args[1]);
      }
      catch(Exception e)
      {
      System.err.println(e);
      }
      }
      }


      The console output extract is:


      15:48:15,346 INFO [UDP] unicast sockets will use interface 120.33.15.22
      15:48:15,349 INFO [UDP] socket information:
      local_addr=jbsprde22:33222, mcast_addr=228.1.2.3:45566, bind_addr=/120.33.15.22, ttl=32
      socket: bound to 120.33.15.22:33222, receive buffer size=64000, send buffer size=32000
      multicast socket: bound to 120.33.15.22:45566, send buffer size=32000, receive buffer size=64000
      15:48:15,351 INFO [STDOUT]
      -------------------------------------------------------
      GMS: address is stage:33222
      -------------------------------------------------------
      15:48:20,572 INFO [DefaultPartition] New cluster view (id: 2, delta: 1) : [120.33.15.22:1199, 120.33.15.22:1299, 120.33.15.22:33222]
      15:48:20,575 INFO [DefaultPartition:ReplicantManager] Dead members: 0
      15:48:20,591 INFO [STDOUT] Channel name? DefaultPartition
      15:48:20,601 INFO [STDOUT] Server Object name? com.test.cluster.jboss.RpcDispatcherClient
      15:48:20,638 INFO [STDOUT] [sender=stage:33222], method_call: invokeCacheNotify(Test, 101010)
      15:48:20,639 INFO [STDOUT] server_obj.getClass().getName()com.test.cluster.jboss.RpcDispatcherClient
      15:48:20,641 INFO [STDOUT] Invoking Cache - clearing caches on key Test LocalIP 120.33.15.22 RemoteIP 120.33.15.22
      15:48:20,647 ERROR [RequestCorrelator] error invoking method, exception=java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      15:48:20,722 INFO [DefaultPartition] New cluster view (id: 3, delta: -1) : [120.33.15.22:1199, 120.33.15.22:1299]


      What is wrong with our code? Please help......

        • 1. Re: Clustering - StringIndexOutOfBoundsException Exception
          belaban

          Can you debug this ? Should be simple to find out what's wrong...
          Bela

          • 2. Re: Clustering - StringIndexOutOfBoundsException Exception
            belaban

            I ran your code 10 times, without any exception.

            Can you reproduce this every time ?

            Bela

            • 3. Re: Clustering - StringIndexOutOfBoundsException Exception
              ganguri

              Hi Bela,

              I am getting this exception all the time I am calling the method.

              I know the code is created with the docuemntation we have from jbroups/jboss. But, I think we did something wrong in config or a different version of jdk or something like that......

              • 4. Re: Clustering - StringIndexOutOfBoundsException Exception
                belaban

                Well, then it should be simple to debug this and locate the code in which this fails.

                I debugged it, and it worked fine for me. Can you do this ?
                Bela

                • 5. Re: Clustering - StringIndexOutOfBoundsException Exception
                  ganguri

                  Hi Bela,

                  Thanks for your time and interest to help me.

                  I got the problem fixed. The reason being I am not passing the object name in the method call object constructor. Now I changed

                  MethodCall mCall = new MethodCall("invokeCacheNotify", sArray, cArray);

                  as

                  MethodCall mCall = new MethodCall("RpcDispatcherClient.invokeCacheNotify", sArray, cArray);

                  This fixed the problem.

                  But Now I got another problem. The method call is happening on the local node. But on remote nodes it is not throwing an error but the method call is not executed. The response from the other nodes in the cluster is:

                  08:36:27,012 INFO [STDOUT] responses: [sender=server202:33871 (additional data: 16 bytes), retval=org.jboss.ha.framework.server.HAPartitionImpl$NoHandlerForRPC@1fb9fb3, received=true, suspected=false]

                  My code chunk is :

                  package com.test.cluster.jboss;

                  import org.jgroups.*;
                  import org.jgroups.blocks.*;
                  import org.jgroups.util.*;

                  import java.util.ArrayList;

                  import org.jboss.ha.framework.interfaces.*;
                  import org.jboss.ha.framework.server.*;


                  import javax.naming.InitialContext;

                  public class RpcDispatcherClient implements java.io.Serializable
                  {
                  private Channel channel;
                  private RpcDispatcher disp;
                  private RspList rsp_list;
                  private String props;
                  private String partition;
                  final HAPartitionImpl hapi= (HAPartitionImpl)(new InitialContext()).lookup("/HAPartition/DefaultPartition");


                  public RpcDispatcherClient() throws Exception
                  {

                  //new RpcDispatcherClient(hapi);
                  hapi.registerRPCHandler("RpcDispatcherClient", this);
                  }

                  public RpcDispatcherClient(HAPartition haPartition) throws Exception
                  {
                  //hapi = haPartition;

                  }

                  public RpcDispatcherClient(String key, String id) throws Exception
                  {

                  try
                  {
                  hapi.registerRPCHandler("RpcDispatcherClient", this);
                  hapi.setRequestHandler(hapi);
                  invoke (key, id);

                  }
                  catch (Exception e)
                  {
                  e.printStackTrace();
                  }
                  }

                  private void invoke (String key, String id) throws Exception
                  {
                  try
                  {
                  String[] sArray = new String[2];
                  sArray[0] = key;
                  sArray[1] = id;

                  Class[] cArray = new Class[sArray.length];
                  cArray[0] = Class.forName("java.lang.String");
                  cArray[1] = Class.forName("java.lang.String");

                  System.out.println(hapi.toString());



                  ArrayList arlist = hapi.callMethodOnCluster("RpcDispatcherClient", "invokeCacheNotify", sArray, cArray, false);

                  System.out.println("############### arlist.size: " + arlist.size());
                  }
                  catch (Exception e)
                  {
                  e.printStackTrace();
                  }


                  }

                  public static String invokeCacheNotify(String key, String id) throws Exception
                  {
                  System.out.println("########################## In invokeCacheNotify");
                  Notifiable notify = new CacheNotify();
                  System.out.println("########################## In invokeCacheNotify");
                  String result = notify.invoke(key, id);
                  System.out.println("########################## In invokeCacheNotify");
                  return result;
                  }

                  private String getName()
                  {
                  return "RpcDispatcherClient";
                  }

                  public static void main(String[] args)
                  {
                  try
                  {
                  new RpcDispatcherClient("Test", "10101");
                  }
                  catch(Exception e)
                  {
                  System.err.println(e);
                  }
                  }

                  }

                  This is a crucial moment for me. Please help....