PDA

View Full Version : RMI recovery (using RmiProxyFactoryBean)



kajism
Aug 19th, 2004, 02:41 AM
Hi all,

I'm using RmiProxyFactoryBean for binding my RMI remote objects into my Spring's application context. It works fine, but when the remote server restarts (or I stop and start the remote server again) calling methods on the "remote bean" starts to produce ConnectException-s .

The only way to get it work again is to restart my application (eg. creation of new Spring application context).

I'm sure there must be a better way how to recover the connection ... ?

Any help kindly welcome, regards,
Karel

kajism
Aug 20th, 2004, 12:36 AM
<bean id="feisService" class="org.springframework.remoting.rmi.RmiProxyFactoryBe an">
<property name="serviceUrl"><value>rmi&#58;//xyz&#58;1099/FeisService</value></property>
<property name="serviceInterface"><value>com.xyz.feissync.FeisService</value></property>
</bean>

<bean id="feisSynchronizer" class="com.xyz.feissync.FeisSynchronizerImpl">
<property name="feisService"><ref local="feisService"/></property>
</bean>


public class FeisSynchronizerImpl implements FeisSynchronizer, ApplicationContextAware &#123;
private ApplicationContext ac;
private FeisService feisService;

public void setApplicationContext&#40;ApplicationContext ac&#41; throws BeansException &#123;
this.ac = ac;
&#125;

public void setFeisService&#40;FeisService feisService&#41; &#123;
this.feisService = feisService;
&#125;

public void syncFeisContracts&#40;&#41; &#123;
List feisContracts = null;
int repeatCount = 0;
while &#40;repeatCount <= 1&#41; &#123;
repeatCount++;
try &#123;
feisContracts = feisService.findContractsModifiedSince&#40;lastUpdateD ate&#41;;
&#125; catch &#40;RemoteException ex&#41; &#123;
log.warn&#40;ex&#41;;
log.info&#40;"Trying to obtain new feisService from application context"&#41;;
InitializingBean factory = &#40;InitializingBean&#41;ac.getBean&#40;"&feisService"&#41;;
try &#123;
factory.afterPropertiesSet&#40;&#41;; // rebind remote server
feisService = &#40;FeisService&#41;ac.getBean&#40;"feisService"&#41;;
&#125; catch &#40;Exception ex2&#41; &#123;
log.warn&#40;ex2&#41;;
&#125;
&#125;
&#125;
&#125;
&#125;

kajism
Aug 31st, 2004, 01:07 PM
In Spring 1.1 this is greatly simplified due to new boolean properties of RmiClientInterceptor:
- lookupRmiProxyOnStartup
- cacheRmiProxy
- refreshRmiProxyOnConnectFailure

Thanks to Juergen!

ruilau
Sep 1st, 2004, 02:51 AM
kajism,i cannot find these new properties in spring1.1 api you referred.
Can you show me the right place to find?
Many thanks.

kajism
Sep 1st, 2004, 03:07 AM
Hi, it is still in CVS only, because it was added after 1.1 RC2. So you can wait for the final release or get the latest CVS version. HTH, Karel

ruilau
Sep 2nd, 2004, 01:42 AM
Thanks,kajism :lol:

Savagearts
Sep 7th, 2004, 12:44 AM
what a great new feature!
I can not wait no more!

Rod Johnson
Sep 7th, 2004, 03:51 AM
This is available in 1.1 final now, as "lookupStubOnStartup" / "cacheStub" / "refreshStubOnConnectFailure". Give it a try!

Juergen (using Rod's account)