mirror of
https://github.com/opensim/opensim.git
synced 2026-08-06 01:06:30 +08:00
Adds size limits to JsonStore. Adds a separate configuration
variable to enable binding to dynamic attributes.
This commit is contained in:
@@ -93,6 +93,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
// extract the internals of a has reference
|
||||
protected static Regex m_HashPattern = new Regex("{([^}]+)}");
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// This is a simple estimator for the size of the stored data, it
|
||||
/// is not precise, but should be close enough to implement reasonable
|
||||
/// limits on the storage space used
|
||||
/// </summary>
|
||||
// -----------------------------------------------------------------
|
||||
public int StringSpace { get; set; }
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
/// <summary>
|
||||
///
|
||||
@@ -110,6 +119,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
// -----------------------------------------------------------------
|
||||
public JsonStore()
|
||||
{
|
||||
StringSpace = 0;
|
||||
m_TakeStore = new List<TakeValueCallbackClass>();
|
||||
m_ReadStore = new List<TakeValueCallbackClass>();
|
||||
}
|
||||
@@ -247,6 +257,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
if (path.Count == 0)
|
||||
{
|
||||
ValueStore = ovalue;
|
||||
StringSpace = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -278,8 +289,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
{
|
||||
string npkey = String.Format("[{0}]",amap.Count);
|
||||
|
||||
amap.Add(ovalue);
|
||||
InvokeNextCallback(pexpr + npkey);
|
||||
if (ovalue != null)
|
||||
{
|
||||
StringSpace += ComputeSizeOf(ovalue);
|
||||
|
||||
amap.Add(ovalue);
|
||||
InvokeNextCallback(pexpr + npkey);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -287,9 +303,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
if (0 <= aval && aval < amap.Count)
|
||||
{
|
||||
if (ovalue == null)
|
||||
{
|
||||
StringSpace -= ComputeSizeOf(amap[aval]);
|
||||
amap.RemoveAt(aval);
|
||||
}
|
||||
else
|
||||
{
|
||||
StringSpace -= ComputeSizeOf(amap[aval]);
|
||||
StringSpace += ComputeSizeOf(ovalue);
|
||||
amap[aval] = ovalue;
|
||||
InvokeNextCallback(pexpr + pkey);
|
||||
}
|
||||
@@ -313,6 +334,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
OSDMap hmap = result as OSDMap;
|
||||
if (ovalue != null)
|
||||
{
|
||||
StringSpace -= ComputeSizeOf(hmap[hkey]);
|
||||
StringSpace += ComputeSizeOf(ovalue);
|
||||
|
||||
hmap[hkey] = ovalue;
|
||||
InvokeNextCallback(pexpr + pkey);
|
||||
return true;
|
||||
@@ -321,6 +345,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
// this is the remove case
|
||||
if (hmap.ContainsKey(hkey))
|
||||
{
|
||||
StringSpace -= ComputeSizeOf(hmap[hkey]);
|
||||
hmap.Remove(hkey);
|
||||
return true;
|
||||
}
|
||||
@@ -531,8 +556,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
|
||||
return pkey;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
// -----------------------------------------------------------------
|
||||
protected static int ComputeSizeOf(OSD value)
|
||||
{
|
||||
string sval;
|
||||
|
||||
if (ConvertOutputValue(value,out sval,true))
|
||||
return sval.Length;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
// -----------------------------------------------------------------
|
||||
public class JsonObjectStore : JsonStore
|
||||
{
|
||||
private static readonly ILog m_log =
|
||||
@@ -566,6 +610,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
{
|
||||
m_scene = scene;
|
||||
m_objectID = oid;
|
||||
|
||||
// the size limit is imposed on whatever is already in the store
|
||||
StringSpace = ComputeSizeOf(ValueStore);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user