Spring 3.0 RmiProxyFactoryBean: how to set connection timeout?

牧云@^-^@ 提交于 2020-01-05 09:14:10

问题


I need to add "test" functionality for RMI connection (checking if the server on the other side is available/existent). I have created this class/beans:

 public class MyRmiClientSocketFactory implements RMIClientSocketFactory {

private int timeout;

public void setTimeout(int timeout) {
    this.timeout = timeout;
}

@Override
public Socket createSocket(String host, int port) throws IOException {
    final Socket socket = new Socket();
    socket.setSoTimeout(timeout);
            socket.setSoLinger(false, 0);
            socket.connect(new InetSocketAddress(host, port), timeout);
    return socket;
}

 }

 <bean id="myRmiClientSocketFactory" class="org.myapp.MyRmiClientSocketFactory">
    <property name="timeout" value="2000"/>
</bean>

 <bean id="myExecutor" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
    <property name="serviceInterface" value="org.myapp.MyExecutor"/>
    <property name="serviceUrl" value="rmi://localhost:1099/myExecutor"/>
<!--        <property name="refreshStubOnConnectFailure" value="true"/> -->
<!--        <property name="lookupStubOnStartup" value="false"/> -->
    <property name="registryClientSocketFactory" ref="myRmiClientSocketFactory"/>
</bean>

When I set a "wrong" url in "serviceUrl" I expect for a "connection timeout" after 2 seconds but that doesn't happen. Any idea how to make it possible?


回答1:


You've set a read timeout, not a connect timeout. Connect timeouts happen when you call connect().



来源:https://stackoverflow.com/questions/10521708/spring-3-0-rmiproxyfactorybean-how-to-set-connection-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!