private void HandleInvocationException(ClientInvocation invocation, Exception exception)
{
try
{
//Should it retry?
if (ShouldRetryInvocation(invocation, exception))
{
try
{
_client.GetClientExecutionService()
.Schedule(() =>
{
var address = GetNewInvocationAddress(invocation);
InvokeInternal(invocation, address);
}, RetryWaitTime, TimeUnit.Milliseconds)
.ContinueWith(t =>
{
HandleInvocationException(invocation, t.Exception.Flatten().InnerExceptions.First());
}, TaskContinuationOptions.OnlyOnFaulted |
TaskContinuationOptions.ExecuteSynchronously);
return;
}
catch (Exception e)
{
HandleInvocationException(invocation, e);
}
}
//Fail with exception
if (!invocation.Future.IsComplete)
{
invocation.Future.Exception = exception;
}
}
catch (Exception ex)
{
if (Logger.IsFinestEnabled())
{
Logger.Finest("HandleInvocationException missed an exception:", ex);
}
throw ex;
}
}