3 Replies Latest reply: Sep 12, 2013 7:39 AM by EJP RSS

    Dynamically set RMI Timeout from client

    saurabharora123

      Hi,

       

      I am stuck with following RMI timeout problem and need urgent help,

       

      1) Is there any way for configuring dynamically different RMI timeout values at RMI client depending upon some criteria.

      2) Is there any way to override "sun.rmi.transport.tcp.responseTimeout" value at RMI client depending upon some criteria.

       

       

      I tried below ways, but none of them worked. Is there any genius who can let me out of this problem.

       

      1) I tried setting "sun.rmi.transport.tcp.responseTimeout" dynamically, but it only accept values that is set very first time.

      System.getProperties().setProperty("sun.rmi.transport.tcp.responseTimeout",

                          rmiTimeout);

                 

      2) To override system properties dynamically, I tried way as below but that did not work

               FileInputStream propFile = new FileInputStream("myProperties.txt");

               Properties p = new Properties(System.getProperties());p.load(propFile);

               p.setProperty("sun.rmi.transport.tcp.responseTimeout",rmiTimeout); System.setProperties(p);

              

      3) I created rmiclientSocketFactory and pass it to LocateRegistry.getRegistry … but that did not work.      

              GUIClientSocketFactory guiClientSocketFactory = new GUIClientSocketFactory(Integer.parseInt(rmiTimeout));

              public Socket createSocket(String host, int port) throws IOException {

                      Socket socket = new Socket(host, port);

                      socket.setSoTimeout(timeout);

                      return socket;

              }

              Registry reg = LocateRegistry. getRegistry(props.getProperty("rmiIpAddress"), (new Integer(props.getProperty("rmiPort"))) .intValue(),guiClientSocketFactory);                 

       

      Any help will be extremely appreciated.

       

      Thanks.

        • 1. Re: Dynamically set RMI Timeout from client
          EJP

          System properties in the JDK are usually read once only, the first time they are needed. I've read the RMI source code many times and I don't remember ever seeing an exception to this rule.

           

          The whole question of client-side timeouts is a significant omission from the RMI design. The old Sun-RPC had a timeout parameter *per call.*

          • 2. Re: Dynamically set RMI Timeout from client
            saurabharora123

            Thanks for the answer...

            But I am unsure wht sol 3 is not working.  Does I did some think worng totally or missed something..

            May be I guess TchChannel is overriding the SoTimeout..m unsure...Any input will be appreocited..I need to do it asap...

            3) I created rmiclientSocketFactory and pass it to LocateRegistry.getRegistry … but that did not work.     

                    GUIClientSocketFactory guiClientSocketFactory = new GUIClientSocketFactory(Integer.parseInt(rmiTimeout));

                    public Socket createSocket(String host, int port) throws IOException {

                            Socket socket = new Socket(host, port);

                            socket.setSoTimeout(timeout);

                            return socket;

                    }

            Registry reg = LocateRegistry. getRegistry(props.getProperty("rmiIpAddress"), (new Integer(props.getProperty("rmiPort"))) .intValue(),guiClientSocketFactory); 

            • 3. Re: Dynamically set RMI Timeout from client
              EJP

              Solution 3 only works for the Registry. It doesn't affect what happens after that.