Timouts for RMI

V

Volker Raum

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.
 
E

Esmond Pitt

Volker said:
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.

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.
 
V

Volker Raum

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
 
E

Esmond Pitt

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?
 
V

Volker Raum

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
 
E

Esmond Pitt

Volker said:
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.
 
V

Volker Raum

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
 
Joined
Jun 3, 2008
Messages
1
Reaction score
0
Hello Volker and Esmond.

I have exactly the same problem, with an rmi timeout of 3 minute between a unix caller and a windows exported object. I already posted the problem on 3 forums, no luck :) This discussion seems to be the closest to my problem.

Could yoou Volker give me a link to the tutorial you found. Thanks,

Emil.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top