PDA

View Full Version : Change target of MethodInvocation in MethodInterceptor?



a_weber
Apr 17th, 2005, 11:39 AM
Hi,

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?

Regards,
Alex

Rod Johnson
May 4th, 2005, 05:11 AM
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?

a_weber
May 12th, 2005, 03:54 PM
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