private void ProcessPool()
{
while (this.stopCounter == 0)
{
if (log.IsDebugEnabled) log.Debug("Looking for the first working node.");
// key is the original url (used for the status dictionary)
// value is the resolved url (used for receiving messages)
var current = GetNextPoolUri();
// the break here will go into the outer while, and reinitialize the lookup table and the indexer
if (current.Key == null)
{
if (log.IsWarnEnabled) log.Warn("Could not found a working node.");
return;
}
try
{
if (log.IsDebugEnabled) log.Debug("Start receiving messages.");
this.currentRetryCount = 0;
while (this.stopCounter == 0)
{
try
{
// start working on the current url
// if it fails in the meanwhile, we'll get another url
this.ReadMessages(current.Value);
// we can only get here properly if the listener is stopped, so just quit the whole loop
if (log.IsDebugEnabled) log.Debug("Processing is aborted.");
return;
}
catch (Exception x)
{
if (log.IsDebugEnabled) log.Debug("ReadMessage failed with exception:", x);
if (this.currentRetryCount == this.RetryCount)
{
if (log.IsDebugEnabled) log.Debug("Reached the retry limit, rethrowing.", x);
throw;
}
}
if (log.IsDebugEnabled) log.DebugFormat("Counter is {0}, sleeping for {1} then retrying.", this.currentRetryCount, this.RetryTimeout);
SleepUntil((int)this.RetryTimeout.TotalMilliseconds);
this.currentRetryCount++;
}
}
catch (Exception e)
{
if (e is IOException || e is System.Net.WebException)
{
// current node url failed, most probably the server was removed from the sockIOPool (or just failed)
if (current.Key != null)
statusPool[current.Key] = false;
if (log.IsWarnEnabled) log.Warn("Current node '" + current.Value + "' has failed.");
}
else
{
if (log.IsErrorEnabled) log.Error("Unexpected pool failure.", e);
throw;
}
}
}
}