Announcement Announcement Module
Collapse
No announcement yet.
RMI recovery (using RmiProxyFactoryBean) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RMI recovery (using RmiProxyFactoryBean)

    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

  • #2
    My solution

    Code:
    <bean id="feisService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
      <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;lastUpdateDate&#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;

    Comment


    • #3
      In Spring 1.1 this is greatly simplified due to new boolean properties of RmiClientInterceptor:
      - lookupRmiProxyOnStartup
      - cacheRmiProxy
      - refreshRmiProxyOnConnectFailure

      Thanks to Juergen!

      Comment


      • #4
        I cannot find these new properties in spring1.1 api

        kajism,i cannot find these new properties in spring1.1 api you referred.
        Can you show me the right place to find?
        Many thanks.

        Comment


        • #5
          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

          Comment


          • #6
            Thanks,kajism

            Thanks,kajism :lol:

            Comment


            • #7
              what a great new feature!
              I can not wait no more!

              Comment


              • #8
                This is available in 1.1 final now, as "lookupStubOnStartup" / "cacheStub" / "refreshStubOnConnectFailure". Give it a try!

                Juergen (using Rod's account)

                Comment

                Working...
                X