if (fcc == null)
{
return invocation.invokeNext();
}
FailoverValve2 valve = fcc.getValve();
JMSRemotingConnection remotingConnection = null;
String methodName = ((MethodInvocation)invocation).getMethod().getName();
if (methodName.equals("startAfterFailover"))
{
//We don't use the valve on this method
return invocation.invokeNext();
}
boolean left = false;
try
{
valve.enter();
// it's important to retrieve the remotingConnection while inside the Valve
remotingConnection = fcc.getRemotingConnection();
return invocation.invokeNext();
}
catch (MessagingNetworkFailureException e)
{
valve.leave();
left = true;
log.debug(this + " detected network failure, putting " + methodName +
"() on hold until failover completes");
fcc.failureDetected(e, this, remotingConnection);
// Set retry flag as true on send() and sendTransaction()
// more details at http://jira.jboss.org/jira/browse/JBMESSAGING-809
if ((invocation.getTargetObject() instanceof ClientSessionDelegate && methodName.equals("send")) ||
(invocation.getTargetObject() instanceof ClientConnectionDelegate && methodName.equals("sendTransaction")))
{
log.trace(this + " caught " + methodName + "() invocation, enabling check for duplicates");
Object[] arguments = ((MethodInvocation)invocation).getArguments();
arguments[1] = Boolean.TRUE;
((MethodInvocation)invocation).setArguments(arguments);
}
// We don't retry the following invocations:
// cancelDelivery(), cancelDeliveries(), cancelInflightMessages() - the deliveries will
// already be cancelled after failover.
if (methodName.equals("cancelDelivery") ||
methodName.equals("cancelDeliveries"))
{
log.trace(this + " NOT resuming " + methodName + "(), let it wither and die");
return null;
}
else
{
log.trace(this + " resuming " + methodName + "()");
return invocation.invokeNext();
}
}
catch (Throwable e)
{
// not failover-triggering, rethrow
if (trace) { log.trace(this + " caught not failover-triggering throwable, rethrowing " + e); }
throw e;
}
finally
{
if (!left)
{
valve.leave();
}
}
}