Я переопределил refreshAndRetry
& lookupStub
метод RMIProxyFactoryBean
, чтобы добиться этого переключения переключения после отказа.
@Override
protected Object refreshAndRetry(MethodInvocation invocation) throws Throwable {
if (logger.isDebugEnabled()) {
logger.debug("Refreshing & retrying remote invocation.");
}
swapHitURLs();//Swap primary<>secondary URL
return super.refreshAndRetry(invocation);
}
@Override
protected Remote lookupStub() throws RemoteLookupFailureException {
Remote stub=null;
if (logger.isDebugEnabled()) {
logger.debug("Looking up the stub.");
}
try{
stub=super.lookupStub();
}catch(RemoteLookupFailureException rlfx){
swapHitURLs();//Swap primary<>secondary URL
if (logger.isDebugEnabled()) {
logger.debug("Looking up the stub for swapped URL.");
}
stub=super.lookupStub();
}
return stub;
}
конфигурации XML:
<bean id="beanName" class="com.ahamed.poc.rmi.FailOverRMIProxyFactory" lazy-init="true">
<property name="serviceUrl" value="PrimaryURL"/>
<property name="alternativeServiceUrl" value="SecondaryURL"/>
<property name="serviceInterface" value="com.ahamed.poc.rmi.InterfaceClass"/>
</bean>
Если какие-либо лучшие варианты, дайте мне знать.