Merge branch 'master' of ssh://opensimulator.org/var/git/opensim

cpu-performance
Diva Canto 2013-07-12 12:54:29 -07:00
commit 3d700bb42c
8 changed files with 313 additions and 106 deletions

View File

@ -42,6 +42,22 @@ namespace OpenSim.Data.Null
// private string m_connectionString;
private Dictionary<uint, EstateSettings> m_knownEstates = new Dictionary<uint, EstateSettings>();
private EstateSettings m_estate = null;
private EstateSettings GetEstate()
{
if (m_estate == null)
{
// This fools the initialization caller into thinking an estate was fetched (a check in OpenSimBase).
// The estate info is pretty empty so don't try banning anyone.
m_estate = new EstateSettings();
m_estate.EstateID = 1;
m_estate.OnSave += StoreEstateSettings;
}
return m_estate;
}
protected virtual Assembly Assembly
{
get { return GetType().Assembly; }
@ -68,21 +84,18 @@ namespace OpenSim.Data.Null
public EstateSettings LoadEstateSettings(UUID regionID, bool create)
{
// This fools the initialization caller into thinking an estate was fetched (a check in OpenSimBase).
// The estate info is pretty empty so don't try banning anyone.
EstateSettings oneEstate = new EstateSettings();
oneEstate.EstateID = 1;
return oneEstate;
return GetEstate();
}
public void StoreEstateSettings(EstateSettings es)
{
m_estate = es;
return;
}
public EstateSettings LoadEstateSettings(int estateID)
{
return new EstateSettings();
return GetEstate();
}
public EstateSettings CreateNewEstate()
@ -93,13 +106,14 @@ namespace OpenSim.Data.Null
public List<EstateSettings> LoadEstateSettingsAll()
{
List<EstateSettings> allEstateSettings = new List<EstateSettings>();
allEstateSettings.Add(new EstateSettings());
allEstateSettings.Add(GetEstate());
return allEstateSettings;
}
public List<int> GetEstatesAll()
{
List<int> result = new List<int>();
result.Add((int)GetEstate().EstateID);
return result;
}

View File

@ -141,6 +141,11 @@ namespace OpenSim.Framework
public static FireAndForgetMethod DefaultFireAndForgetMethod = FireAndForgetMethod.SmartThreadPool;
public static FireAndForgetMethod FireAndForgetMethod = DefaultFireAndForgetMethod;
public static bool IsPlatformMono
{
get { return Type.GetType("Mono.Runtime") != null; }
}
/// <summary>
/// Gets the name of the directory where the current running executable
/// is located
@ -1326,7 +1331,7 @@ namespace OpenSim.Framework
ru = "OSX/Mono";
else
{
if (Type.GetType("Mono.Runtime") != null)
if (IsPlatformMono)
ru = "Win/Mono";
else
ru = "Win/.NET";

View File

@ -419,7 +419,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
get { return _reqID; }
set { _reqID = value; }
}
public HttpWebRequest Request;
public WebRequest Request;
public string ResponseBody;
public List<string> ResponseMetadata;
public Dictionary<string, string> ResponseHeaders;
@ -431,18 +431,11 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
SendRequest();
}
/*
* TODO: More work on the response codes. Right now
* returning 200 for success or 499 for exception
*/
public void SendRequest()
{
HttpWebResponse response = null;
try
{
Request = (HttpWebRequest) WebRequest.Create(Url);
Request = WebRequest.Create(Url);
Request.Method = HttpMethod;
Request.ContentType = HttpMIMEType;
@ -480,14 +473,17 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
}
}
if (ResponseHeaders != null)
{
foreach (KeyValuePair<string, string> entry in ResponseHeaders)
if (entry.Key.ToLower().Equals("user-agent"))
Request.UserAgent = entry.Value;
if (entry.Key.ToLower().Equals("user-agent") && Request is HttpWebRequest)
((HttpWebRequest)Request).UserAgent = entry.Value;
else
Request.Headers[entry.Key] = entry.Value;
}
// Encode outbound data
if (OutboundBody.Length > 0)
if (OutboundBody != null && OutboundBody.Length > 0)
{
byte[] data = Util.UTF8.GetBytes(OutboundBody);
@ -510,12 +506,19 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
{
throw;
}
response = (HttpWebResponse)e.Response;
HttpWebResponse response = (HttpWebResponse)e.Response;
Status = (int)response.StatusCode;
ResponseBody = response.StatusDescription;
_finished = true;
}
}
catch (Exception e)
{
// m_log.Debug(
// string.Format("[SCRIPTS HTTP REQUESTS]: Exception on request to {0} for {1} ", Url, ItemID), e);
Status = (int)OSHttpStatusCode.ClientErrorJoker;
ResponseBody = e.Message;
_finished = true;
@ -526,36 +529,30 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
{
HttpWebResponse response = null;
try
{
try
{
response = (HttpWebResponse)Request.EndGetResponse(ar);
}
catch (WebException e)
{
if (e.Status != WebExceptionStatus.ProtocolError)
{
throw;
}
response = (HttpWebResponse)e.Response;
}
Status = (int)response.StatusCode;
Stream resStream = response.GetResponseStream();
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
string tempString = null;
int count = 0;
do
using (Stream stream = response.GetResponseStream())
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Util.UTF8.GetString(buf, 0, count);
// continue building the string
sb.Append(tempString);
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
ResponseBody = reader.ReadToEnd();
}
}
while (count > 0); // any more data to read?
ResponseBody = sb.ToString();
}
catch (Exception e)
{
Status = (int)OSHttpStatusCode.ClientErrorJoker;

View File

@ -0,0 +1,198 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using log4net.Config;
using NUnit.Framework;
using OpenMetaverse;
using OpenMetaverse.Assets;
using OpenSim.Framework;
using OpenSim.Region.CoreModules.Scripting.HttpRequest;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Tests.Common;
using OpenSim.Tests.Common.Mock;
namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests
{
class TestWebRequestCreate : IWebRequestCreate
{
public TestWebRequest NextRequest { get; set; }
public WebRequest Create(Uri uri)
{
// NextRequest.RequestUri = uri;
return NextRequest;
// return new TestWebRequest(new SerializationInfo(typeof(TestWebRequest), new FormatterConverter()), new StreamingContext());
}
}
class TestWebRequest : WebRequest
{
public override string ContentType { get; set; }
public override string Method { get; set; }
public Func<IAsyncResult, WebResponse> OnEndGetResponse { get; set; }
public TestWebRequest() : base()
{
// Console.WriteLine("created");
}
// public TestWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext)
// : base(serializationInfo, streamingContext)
// {
// Console.WriteLine("created");
// }
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
{
// Console.WriteLine("bish");
TestAsyncResult tasr = new TestAsyncResult();
callback(tasr);
return tasr;
}
public override WebResponse EndGetResponse(IAsyncResult asyncResult)
{
// Console.WriteLine("bosh");
return OnEndGetResponse(asyncResult);
}
}
class TestHttpWebResponse : HttpWebResponse
{
public string Response { get; set; }
public TestHttpWebResponse(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext) {}
public override Stream GetResponseStream()
{
return new MemoryStream(Encoding.UTF8.GetBytes(Response));
}
}
class TestAsyncResult : IAsyncResult
{
WaitHandle m_wh = new ManualResetEvent(true);
object IAsyncResult.AsyncState
{
get {
throw new System.NotImplementedException ();
}
}
WaitHandle IAsyncResult.AsyncWaitHandle
{
get { return m_wh; }
}
bool IAsyncResult.CompletedSynchronously
{
get { return false; }
}
bool IAsyncResult.IsCompleted
{
get { return true; }
}
}
/// <summary>
/// Test script http request code.
/// </summary>
/// <remarks>
/// This class uses some very hacky workarounds in order to mock HttpWebResponse which are Mono dependent (though
/// alternative code can be written to make this work for Windows). However, the value of being able to
/// regression test this kind of code is very high.
/// </remarks>
[TestFixture]
public class ScriptsHttpRequestsTests : OpenSimTestCase
{
/// <summary>
/// Test what happens when we get a 404 response from a call.
/// </summary>
[Test]
public void Test404Response()
{
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
if (!Util.IsPlatformMono)
Assert.Ignore("Ignoring test since can only currently run on Mono");
string rawResponse = "boom";
TestWebRequestCreate twrc = new TestWebRequestCreate();
TestWebRequest twr = new TestWebRequest();
//twr.OnEndGetResponse += ar => new TestHttpWebResponse(null, new StreamingContext());
twr.OnEndGetResponse += ar =>
{
SerializationInfo si = new SerializationInfo(typeof(HttpWebResponse), new FormatterConverter());
StreamingContext sc = new StreamingContext();
// WebHeaderCollection headers = new WebHeaderCollection();
// si.AddValue("m_HttpResponseHeaders", headers);
si.AddValue("uri", new Uri("test://arrg"));
// si.AddValue("m_Certificate", null);
si.AddValue("version", HttpVersion.Version11);
si.AddValue("statusCode", HttpStatusCode.NotFound);
si.AddValue("contentLength", 0);
si.AddValue("method", "GET");
si.AddValue("statusDescription", "Not Found");
si.AddValue("contentType", null);
si.AddValue("cookieCollection", new CookieCollection());
TestHttpWebResponse thwr = new TestHttpWebResponse(si, sc);
thwr.Response = rawResponse;
throw new WebException("no message", null, WebExceptionStatus.ProtocolError, thwr);
};
twrc.NextRequest = twr;
WebRequest.RegisterPrefix("test", twrc);
HttpRequestClass hr = new HttpRequestClass();
hr.Url = "test://something";
hr.SendRequest();
Assert.That(hr.Status, Is.EqualTo((int)HttpStatusCode.NotFound));
Assert.That(hr.ResponseBody, Is.EqualTo(rawResponse));
}
}
}

View File

@ -4213,31 +4213,12 @@ namespace OpenSim.Region.Framework.Scenes
AddToPhysics(UsePhysics, SetPhantom, false);
pa = PhysActor;
if (pa != null)
{
pa.SetMaterial(Material);
DoPhysicsPropertyUpdate(UsePhysics, true);
if (
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
(CollisionSound != UUID.Zero)
)
{
pa.OnCollisionUpdate += PhysicsCollision;
pa.SubscribeEvents(1000);
}
SubscribeForCollisionEvents();
}
}
else // it already has a physical representation
@ -4291,6 +4272,46 @@ namespace OpenSim.Region.Framework.Scenes
// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
}
// Subscribe for physics collision events if needed for scripts and sounds
public void SubscribeForCollisionEvents()
{
if (PhysActor != null)
{
if (
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
(CollisionSound != UUID.Zero)
)
{
if (!PhysActor.SubscribedEvents())
{
// If not already subscribed for event, set up for a collision event.
PhysActor.OnCollisionUpdate += PhysicsCollision;
PhysActor.SubscribeEvents(1000);
}
}
else
{
// There is no need to be subscribed to collisions so, if subscribed, remove subscription
if (PhysActor.SubscribedEvents())
{
PhysActor.OnCollisionUpdate -= PhysicsCollision;
PhysActor.UnSubscribeEvents();
}
}
}
}
/// <summary>
/// Adds this part to the physics scene.
/// </summary>
@ -4680,39 +4701,7 @@ namespace OpenSim.Region.Framework.Scenes
objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
}
PhysicsActor pa = PhysActor;
if (
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
(CollisionSound != UUID.Zero)
)
{
// subscribe to physics updates.
if (pa != null)
{
pa.OnCollisionUpdate += PhysicsCollision;
pa.SubscribeEvents(1000);
}
}
else
{
if (pa != null)
{
pa.UnSubscribeEvents();
pa.OnCollisionUpdate -= PhysicsCollision;
}
}
SubscribeForCollisionEvents();
//if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
//{

View File

@ -59,7 +59,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
public void TestChildAgentSingleRegionCapabilities()
{
TestHelpers.InMethod();
TestHelpers.EnableLogging();
// TestHelpers.EnableLogging();
UUID spUuid = TestHelpers.ParseTail(0x1);

View File

@ -139,18 +139,21 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule
{
string capsBase = "/CAPS/" + caps.CapsObjectPath;
IRequestHandler renderMaterialsPostHandler = new RestStreamHandler("POST", capsBase + "/", RenderMaterialsPostCap);
IRequestHandler renderMaterialsPostHandler
= new RestStreamHandler("POST", capsBase + "/", RenderMaterialsPostCap, "RenderMaterials", null);
caps.RegisterHandler("RenderMaterials", renderMaterialsPostHandler);
// OpenSimulator CAPs infrastructure seems to be somewhat hostile towards any CAP that requires both GET
// and POST handlers, (at least at the time this was originally written), so we first set up a POST
// handler normally and then add a GET handler via MainServer
IRequestHandler renderMaterialsGetHandler = new RestStreamHandler("GET", capsBase + "/", RenderMaterialsGetCap);
IRequestHandler renderMaterialsGetHandler
= new RestStreamHandler("GET", capsBase + "/", RenderMaterialsGetCap, "RenderMaterials", null);
MainServer.Instance.AddStreamHandler(renderMaterialsGetHandler);
// materials viewer seems to use either POST or PUT, so assign POST handler for PUT as well
IRequestHandler renderMaterialsPutHandler = new RestStreamHandler("PUT", capsBase + "/", RenderMaterialsPostCap);
IRequestHandler renderMaterialsPutHandler
= new RestStreamHandler("PUT", capsBase + "/", RenderMaterialsPostCap, "RenderMaterials", null);
MainServer.Instance.AddStreamHandler(renderMaterialsPutHandler);
}

View File

@ -3129,6 +3129,7 @@
<Match path="Avatar/Inventory/Transfer/Tests" pattern="*.cs" recurse="true"/>
<Match path="Framework/InventoryAccess/Tests" pattern="*.cs" recurse="true"/>
<Match path="Framework/UserManagement/Tests" pattern="*.cs" recurse="true"/>
<Match path="Scripting/HttpRequest/Tests" pattern="*.cs" recurse="true"/>
<Match path="Scripting/VectorRender/Tests" pattern="*.cs" recurse="true"/>
<Match path="World/Archiver/Tests" pattern="*.cs" recurse="true"/>
<Match buildAction="EmbeddedResource" path="World/Archiver/Tests/Resources" pattern="*"/>