refactor: Make stats and sim status simpler by extending BaseStreamHandler like other handlers instead of implementing the IStreamedRequestHandler interface directly

cpu-performance
Justin Clark-Casey (justincc) 2013-07-06 00:12:48 +01:00
parent dd15f95499
commit 5dbdd5f8b4
2 changed files with 23 additions and 77 deletions

View File

@ -759,73 +759,49 @@ namespace OpenSim
/// <summary>
/// Handler to supply the current status of this sim
/// </summary>
/// <remarks>
/// Currently this is always OK if the simulator is still listening for connections on its HTTP service
public class SimStatusHandler : IStreamedRequestHandler
/// </remarks>
public class SimStatusHandler : BaseStreamHandler
{
public byte[] Handle(string path, Stream request,
public SimStatusHandler() : base("GET", "/simstatus", "SimStatus", "Simulator Status") {}
public override byte[] Handle(string path, Stream request,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
return Util.UTF8.GetBytes("OK");
}
public string Name { get { return "SimStatus"; } }
public string Description { get { return "Simulator Status"; } }
public string ContentType
public override string ContentType
{
get { return "text/plain"; }
}
public string HttpMethod
{
get { return "GET"; }
}
public string Path
{
get { return "/simstatus"; }
}
}
/// <summary>
/// Handler to supply the current extended status of this sim
/// Sends the statistical data in a json serialization
/// </summary>
public class XSimStatusHandler : IStreamedRequestHandler
public class XSimStatusHandler : BaseStreamHandler
{
OpenSimBase m_opensim;
string osXStatsURI = String.Empty;
public string Name { get { return "XSimStatus"; } }
public string Description { get { return "Simulator XStatus"; } }
public XSimStatusHandler(OpenSimBase sim)
: base("GET", "/" + Util.SHA1Hash(sim.osSecret), "XSimStatus", "Simulator XStatus")
{
m_opensim = sim;
osXStatsURI = Util.SHA1Hash(sim.osSecret);
}
public byte[] Handle(string path, Stream request,
public override byte[] Handle(string path, Stream request,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
return Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
}
public string ContentType
public override string ContentType
{
get { return "text/plain"; }
}
public string HttpMethod
{
get { return "GET"; }
}
public string Path
{
// This is for the OpenSimulator instance and is the osSecret hashed
get { return "/" + osXStatsURI; }
}
}
/// <summary>
@ -834,42 +810,26 @@ namespace OpenSim
/// If the request contains a key, "callback" the response will be wrappend in the
/// associated value for jsonp used with ajax/javascript
/// </summary>
public class UXSimStatusHandler : IStreamedRequestHandler
public class UXSimStatusHandler : BaseStreamHandler
{
OpenSimBase m_opensim;
string osUXStatsURI = String.Empty;
public string Name { get { return "UXSimStatus"; } }
public string Description { get { return "Simulator UXStatus"; } }
public UXSimStatusHandler(OpenSimBase sim)
: base("GET", "/" + sim.userStatsURI, "UXSimStatus", "Simulator UXStatus")
{
m_opensim = sim;
osUXStatsURI = sim.userStatsURI;
}
public byte[] Handle(string path, Stream request,
public override byte[] Handle(string path, Stream request,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
return Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
}
public string ContentType
public override string ContentType
{
get { return "text/plain"; }
}
public string HttpMethod
{
get { return "GET"; }
}
public string Path
{
// This is for the OpenSimulator instance and is the user provided URI
get { return "/" + osUXStatsURI; }
}
}
#endregion

View File

@ -46,48 +46,34 @@ using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.Framework.Scenes
{
public class RegionStatsHandler : IStreamedRequestHandler
public class RegionStatsHandler : BaseStreamHandler
{
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private string osRXStatsURI = String.Empty;
private string osXStatsURI = String.Empty;
//private string osSecret = String.Empty;
private OpenSim.Framework.RegionInfo regionInfo;
public string localZone = TimeZone.CurrentTimeZone.StandardName;
public TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
public string Name { get { return "RegionStats"; } }
public string Description { get { return "Region Statistics"; } }
public RegionStatsHandler(RegionInfo region_info)
: base("GET", "/" + Util.SHA1Hash(region_info.regionSecret), "RegionStats", "Region Statistics")
{
regionInfo = region_info;
osRXStatsURI = Util.SHA1Hash(regionInfo.regionSecret);
osXStatsURI = Util.SHA1Hash(regionInfo.osSecret);
}
public byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
public override byte[] Handle(
string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
return Util.UTF8.GetBytes(Report());
}
public string ContentType
public override string ContentType
{
get { return "text/plain"; }
}
public string HttpMethod
{
get { return "GET"; }
}
public string Path
{
// This is for the region and is the regionSecret hashed
get { return "/" + osRXStatsURI; }
}
private string Report()
{
OSDMap args = new OSDMap(30);