Attempt to give script objects a proper lease time (DNE and xengine). Relies on GC. Also removed lease for LSL_Api as it strictly speaking should not be MarshalByRef. Or should it? If so I broke scripting! :)

0.6.1-post-fixes
Tedd Hansen 2008-11-26 11:12:57 +00:00
parent c7d39fb4e3
commit e6ddb5de7d
5 changed files with 48 additions and 16 deletions

View File

@ -28,6 +28,8 @@
using System;
using System.Reflection;
using System.Globalization;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;
using log4net;
using OpenMetaverse;
using OpenSim.Framework;
@ -39,6 +41,7 @@ using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
using OpenSim.Region.ScriptEngine.Shared.CodeTools;
@ -56,6 +59,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
public Dictionary<string, IScriptApi> Apis;
public Dictionary<KeyValuePair<int,int>, KeyValuePair<int,int>>
LineMap;
public ISponsor ScriptSponsor;
}
public class ScriptManager
@ -164,6 +168,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
CompiledScript =
m_scriptEngine.m_AppDomainManager.LoadScript(
CompiledScriptFile, out id.AppDomain);
//Register the sponsor
ISponsor scriptSponsor = new ScriptSponsor();
ILease lease = (ILease)RemotingServices.GetLifetimeService(CompiledScript as MarshalByRefObject);
lease.Register(scriptSponsor);
id.ScriptSponsor = scriptSponsor;
id.LineMap = LSLCompiler.LineMap();
id.Script = CompiledScript;

View File

@ -29,6 +29,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Remoting.Lifetime;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using Nini.Config;
@ -64,7 +65,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// <summary>
/// Contains all LSL ll-functions. This class will be in Default AppDomain.
/// </summary>
public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
public class LSL_Api : ILSL_Api, IScriptApi
{
protected IScriptEngine m_ScriptEngine;
protected SceneObjectPart m_host;
@ -98,17 +99,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
AsyncCommands = new AsyncCommandManager(ScriptEngine);
}
// Object never expires
public override Object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.Zero;
}
return lease;
}
protected void ScriptSleep(int delay)
{

View File

@ -27,6 +27,7 @@
using System;
using System.Runtime.Remoting.Lifetime;
using System.Security.Permissions;
using System.Threading;
using System.Reflection;
using System.Collections;
@ -40,16 +41,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
private Dictionary<string,MethodInfo> inits = new Dictionary<string,MethodInfo>();
//
// Never expire this object
//
// Object expires if we don't keep it alive
// sponsor will be added on object load
[SecurityPermissionAttribute(SecurityAction.Demand,
Flags = SecurityPermissionFlag.Infrastructure)]
public override Object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.Zero;
lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
}
return lease;
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Lifetime;
using System.Text;
namespace OpenSim.Region.ScriptEngine.Shared.Api.Runtime
{
public class ScriptSponsor: ISponsor
{
// In theory: I execute, therefore I am.
// If GC collects this class then sponsorship will expire
public TimeSpan Renewal(ILease lease)
{
return TimeSpan.FromMinutes(2);
}
}
}

View File

@ -27,6 +27,8 @@
using System;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
@ -44,6 +46,7 @@ using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.ScriptEngine.Shared;
using OpenSim.Region.ScriptEngine.Shared.Api;
using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
using OpenSim.Region.ScriptEngine.Shared.CodeTools;
using OpenSim.Region.ScriptEngine.Interfaces;
@ -80,6 +83,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
private int m_ControlEventsInQueue = 0;
private int m_LastControlLevel = 0;
private bool m_CollisionInQueue = false;
private ISponsor m_ScriptSponsor;
private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
m_LineMap;
@ -204,6 +208,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_Script = (IScript)dom.CreateInstanceAndUnwrap(
Path.GetFileNameWithoutExtension(assembly),
"SecondLife.Script");
// Add a sponsor to the script
ISponsor scriptSponsor = new ScriptSponsor();
ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as MarshalByRefObject);
lease.Register(scriptSponsor);
m_ScriptSponsor = scriptSponsor;
}
catch (Exception e)
{