Announcement Announcement Module
No announcement yet.
Change target of MethodInvocation in MethodInterceptor? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change target of MethodInvocation in MethodInterceptor?


    I am trying to build some sort of retry and micro-reboot functionality as aspects, pluggable in spring. I am using a ProxyFactoryBean with a MethodInterceptor. The MethodInterceptor is able to do retries on the target, if the target fails with a RecoverableException. That works as desired.

    Then I want my MethodInterceptor to be able to "reboot" components, if they fail with a not recoverable Exception. The MethodInterceptor uses a subclassed HotSwappableTargetSource that is able to swap to a new instance if the old one fails. It works as desired, but ...

    The MethodInterceptor notes the failure of a component and reboots it (creates a new one and swaps to it) but the MethodInvocation can't be invoked, as it uses the old target. My workaround is to modify the ReflectiveMethodInvocation so that it provides a clone with a new target.

    Is there another solution? I am new to Spring, so maybe I missed something obvious?


  • #2
    The target will have been allocated at that point and associated with the invocation. So your solution is probably the only approach.

    I guess we could add a setTarget() method to ReflectiveMethodInvocation. Although that does subvert the TargetSource mechanism, so I'm not sure it would be prudent.

    Anyone else need this?


    • #3
      Hi Rod,

      maybe it's possible to provide a method that clones the ReflectiveMethodInvocation with a new target. That is a bit less subverting as a setTarget().

      Regards, Alex