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