Make webloading more robust by addign retries

avinationmerge
Melanie Thielker 2010-07-17 02:38:00 +02:00
parent 85f454e3ae
commit e06b7ee368
1 changed files with 22 additions and 26 deletions

View File

@ -48,6 +48,9 @@ namespace OpenSim.Framework.RegionLoader.Web
public RegionInfo[] LoadRegions() public RegionInfo[] LoadRegions()
{ {
int tries = 3;
int wait = 2000;
if (m_configSource == null) if (m_configSource == null)
{ {
m_log.Error("[WEBLOADER]: Unable to load configuration source!"); m_log.Error("[WEBLOADER]: Unable to load configuration source!");
@ -63,6 +66,8 @@ namespace OpenSim.Framework.RegionLoader.Web
return null; return null;
} }
else else
{
while (tries > 0)
{ {
HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(url); HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(url);
webRequest.Timeout = 30000; //30 Second Timeout webRequest.Timeout = 30000; //30 Second Timeout
@ -77,22 +82,13 @@ namespace OpenSim.Framework.RegionLoader.Web
xmlSource = xmlSource + tempStr; xmlSource = xmlSource + tempStr;
tempStr = reader.ReadLine(); tempStr = reader.ReadLine();
} }
m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " + m_log.Debug("[WEBLOADER]: Request yielded no regions.");
xmlSource.Length); tries--;
XmlDocument xmlDoc = new XmlDocument(); if (tries > 0)
xmlDoc.LoadXml(xmlSource);
if (xmlDoc.FirstChild.Name == "Regions")
{ {
RegionInfo[] regionInfos = new RegionInfo[xmlDoc.FirstChild.ChildNodes.Count]; m_log.Debug("[WEBLOADER]: Retrying");
int i; System.Threading.Thread.Sleep(wait);
for (i = 0; i < xmlDoc.FirstChild.ChildNodes.Count; i++)
{
m_log.Debug(xmlDoc.FirstChild.ChildNodes[i].OuterXml);
regionInfos[i] =
new RegionInfo("REGION CONFIG #" + (i + 1), xmlDoc.FirstChild.ChildNodes[i],false,m_configSource);
} }
return regionInfos;
} }
return null; return null;
} }