Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Timouts for RMI

Thread view: 
Volker Raum - 07 Mar 2007 10:57 GMT
Hi all,
i know there are several posts, and a google search found lots of hits on this topic.
My Problem is: Nothing works...

My intension is very simple:
Use Rmi to transmit data from a client to a server.
In principle it works fine. My Problem are the RMI-timeouts. They are too long.

I have to take into account that some "unclever Guy" pulled the network plug.
My Client still wants to send data to the Server (call a servermethod via rmi).
I call the method and this thread is blocked. Fine. Network is still broken.

Depending on the OS of the client (windows, linux) the Timeouts vary.
In Windows its about 20 Sec => Exception. In Linux? Years? It looks like the method never returns
with an error.

Is there a way to set the timeout for calling a method.
(The time after the methodcall returns an error when the server isn't reachable)

I tried:
a) Setting the RMISocketFactory creating my own clientsockets having the SoTimeout set... didnt work.
b) setting the Systems sun.rmi.transport.connectionTimeout ... didnt work

Hope you can help me.
Esmond Pitt - 08 Mar 2007 01:41 GMT
> Is there a way to set the timeout for calling a method.
> (The time after the methodcall returns an error when the server isn't
[quoted text clipped - 3 lines]
> a) Setting the RMISocketFactory creating my own clientsockets having the
> SoTimeout set... didnt work.

It should have. You must have done something wrong.

> b) setting the Systems sun.rmi.transport.connectionTimeout ... didnt work

That's a timeout enforced at the client on idle connections. Nothing to
do with what you want.

> Hope you can help me.

http://java.sun.com/j2se/1.5.0/docs/guide/rmi/javarmiproperties.html
http://java.sun.com/j2se/1.5.0/docs/guide/rmi/sunrmiproperties.html
sun.rmi.transport.tcp.handshakeTimeout
sun.rmi.transport.tcp.readTimeout - this is not documented for some
reason, but it is the timeout for reading the remote method reply in
milliseconds.
Volker Raum - 08 Mar 2007 06:45 GMT
Thanx a lot for your answer. To be exact i call the following method
   public static void configureSockets (final int timeout)
   {
      try
      {
         RMISocketFactory.setSocketFactory(new RMISocketFactory()
         {
            public Socket createSocket(String host, int port) throws IOException
            {
               Socket socket = new Socket(host, port);
               socket.setSoTimeout(timeout);
               socket.setSoLinger(false, 0);
               return socket;
            }

            public ServerSocket createServerSocket(int port) throws IOException
            {
               return new ServerSocket(port);
            }
         });
      }
      catch (IOException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

   }

One question remains. When to call the Method? Before any Naming.lookup() i think.
What i didnt mention is... I create the RMI Registry within my application with

Registry registry = java.rmi.registry.LocateRegistry.createRegistry(registryPort);

Calling the configureSockets method before or after didnt work.

So what do i do wrong?

Greets,
Volker

Esmond Pitt schrieb:

>> Is there a way to set the timeout for calling a method.
>> (The time after the methodcall returns an error when the server isn't
[quoted text clipped - 19 lines]
> reason, but it is the timeout for reading the remote method reply in
> milliseconds.
Esmond Pitt - 08 Mar 2007 09:25 GMT
You shouldn't be using RMISocketFactory at all. It's been deprecated for
about 8 years.

Have a look at RMIClientSocketFactory and
UnicastRemoteObject.UnicastRemoteObject(port, RMIClientSocketFactory,
RMIServerSocketFactory) and
UnicastRemoteObject.exportObject(port, RMIClientSocketFactory,
RMIServerSocketFactory).

OTOH RMI may be interfering with the timeouts after you create the
sockets. Have you tried the system properties I mentioned?
Volker Raum - 12 Mar 2007 13:14 GMT
Uh, got that code from a Website. Thanx for the hint.
I tried the System properties. No result.

Do you have a little example Code for me that shows how a client connects to the server via
Unicast Remote including using its own Socket Factory ?
My code goes something like that

...
String name = "rmi://"+hostname + ":" + port+"/"+servicename ;
Object service = Naming.lookup(name) ;
...

Thanx
Volker

Esmond Pitt schrieb:
> You shouldn't be using RMISocketFactory at all. It's been deprecated for
> about 8 years.
[quoted text clipped - 7 lines]
> OTOH RMI may be interfering with the timeouts after you create the
> sockets. Have you tried the system properties I mentioned?
Esmond Pitt - 13 Mar 2007 00:06 GMT
> I tried the System properties. No result.

What do you mean by 'no result'?

> Do you have a little example Code for me that shows how a client
> connects to the server via
> Unicast Remote including using its own Socket Factory ?

It doesn't. The server defines the client socket factory when it calls
the superclass constructor of UnicastRemoteObject, and the CSF is
serialized to the client along with the stub. There are perfectly
adequate samples in the JDK.
Volker Raum - 13 Mar 2007 12:04 GMT
Dear Esmond,

thank you for your help. Your last words gave me the hint.
I programmed the stuff completely different.
I found a good example in a Sun Tutorial.
I now do it as they say (incl. a soTimeout) and .... BINGO i get the timeout.

AGAIN...
thank you very much

Esmond Pitt schrieb:
>> I tried the System properties. No result.
>
[quoted text clipped - 8 lines]
> serialized to the client along with the stub. There are perfectly
> adequate samples in the JDK.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.