diff options
author | Mic Bowman | 2013-02-08 15:07:43 -0800 |
---|---|---|
committer | Mic Bowman | 2013-02-08 15:07:43 -0800 |
commit | e93defd0ca326754d1bd5a1a503d6d47428272be (patch) | |
tree | e54f6971522422b3ce25cf3c0fbff70b251d5f46 /OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |
parent | Fix the return values for JsonDestroyStore, JsonRemoveValue, and JsonSetValue. (diff) | |
download | opensim-SC-e93defd0ca326754d1bd5a1a503d6d47428272be.zip opensim-SC-e93defd0ca326754d1bd5a1a503d6d47428272be.tar.gz opensim-SC-e93defd0ca326754d1bd5a1a503d6d47428272be.tar.bz2 opensim-SC-e93defd0ca326754d1bd5a1a503d6d47428272be.tar.xz |
Adds size limits to JsonStore. Adds a separate configuration
variable to enable binding to dynamic attributes.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index c7f0001..088d0cd 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |||
@@ -95,6 +95,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
95 | 95 | ||
96 | // ----------------------------------------------------------------- | 96 | // ----------------------------------------------------------------- |
97 | /// <summary> | 97 | /// <summary> |
98 | /// This is a simple estimator for the size of the stored data, it | ||
99 | /// is not precise, but should be close enough to implement reasonable | ||
100 | /// limits on the storage space used | ||
101 | /// </summary> | ||
102 | // ----------------------------------------------------------------- | ||
103 | public int StringSpace { get; set; } | ||
104 | |||
105 | // ----------------------------------------------------------------- | ||
106 | /// <summary> | ||
98 | /// | 107 | /// |
99 | /// </summary> | 108 | /// </summary> |
100 | // ----------------------------------------------------------------- | 109 | // ----------------------------------------------------------------- |
@@ -110,6 +119,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
110 | // ----------------------------------------------------------------- | 119 | // ----------------------------------------------------------------- |
111 | public JsonStore() | 120 | public JsonStore() |
112 | { | 121 | { |
122 | StringSpace = 0; | ||
113 | m_TakeStore = new List<TakeValueCallbackClass>(); | 123 | m_TakeStore = new List<TakeValueCallbackClass>(); |
114 | m_ReadStore = new List<TakeValueCallbackClass>(); | 124 | m_ReadStore = new List<TakeValueCallbackClass>(); |
115 | } | 125 | } |
@@ -247,6 +257,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
247 | if (path.Count == 0) | 257 | if (path.Count == 0) |
248 | { | 258 | { |
249 | ValueStore = ovalue; | 259 | ValueStore = ovalue; |
260 | StringSpace = 0; | ||
250 | return true; | 261 | return true; |
251 | } | 262 | } |
252 | 263 | ||
@@ -278,8 +289,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
278 | { | 289 | { |
279 | string npkey = String.Format("[{0}]",amap.Count); | 290 | string npkey = String.Format("[{0}]",amap.Count); |
280 | 291 | ||
281 | amap.Add(ovalue); | 292 | if (ovalue != null) |
282 | InvokeNextCallback(pexpr + npkey); | 293 | { |
294 | StringSpace += ComputeSizeOf(ovalue); | ||
295 | |||
296 | amap.Add(ovalue); | ||
297 | InvokeNextCallback(pexpr + npkey); | ||
298 | } | ||
283 | return true; | 299 | return true; |
284 | } | 300 | } |
285 | 301 | ||
@@ -287,9 +303,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
287 | if (0 <= aval && aval < amap.Count) | 303 | if (0 <= aval && aval < amap.Count) |
288 | { | 304 | { |
289 | if (ovalue == null) | 305 | if (ovalue == null) |
306 | { | ||
307 | StringSpace -= ComputeSizeOf(amap[aval]); | ||
290 | amap.RemoveAt(aval); | 308 | amap.RemoveAt(aval); |
309 | } | ||
291 | else | 310 | else |
292 | { | 311 | { |
312 | StringSpace -= ComputeSizeOf(amap[aval]); | ||
313 | StringSpace += ComputeSizeOf(ovalue); | ||
293 | amap[aval] = ovalue; | 314 | amap[aval] = ovalue; |
294 | InvokeNextCallback(pexpr + pkey); | 315 | InvokeNextCallback(pexpr + pkey); |
295 | } | 316 | } |
@@ -313,6 +334,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
313 | OSDMap hmap = result as OSDMap; | 334 | OSDMap hmap = result as OSDMap; |
314 | if (ovalue != null) | 335 | if (ovalue != null) |
315 | { | 336 | { |
337 | StringSpace -= ComputeSizeOf(hmap[hkey]); | ||
338 | StringSpace += ComputeSizeOf(ovalue); | ||
339 | |||
316 | hmap[hkey] = ovalue; | 340 | hmap[hkey] = ovalue; |
317 | InvokeNextCallback(pexpr + pkey); | 341 | InvokeNextCallback(pexpr + pkey); |
318 | return true; | 342 | return true; |
@@ -321,6 +345,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
321 | // this is the remove case | 345 | // this is the remove case |
322 | if (hmap.ContainsKey(hkey)) | 346 | if (hmap.ContainsKey(hkey)) |
323 | { | 347 | { |
348 | StringSpace -= ComputeSizeOf(hmap[hkey]); | ||
324 | hmap.Remove(hkey); | 349 | hmap.Remove(hkey); |
325 | return true; | 350 | return true; |
326 | } | 351 | } |
@@ -531,8 +556,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
531 | 556 | ||
532 | return pkey; | 557 | return pkey; |
533 | } | 558 | } |
559 | |||
560 | // ----------------------------------------------------------------- | ||
561 | /// <summary> | ||
562 | /// | ||
563 | /// </summary> | ||
564 | // ----------------------------------------------------------------- | ||
565 | protected static int ComputeSizeOf(OSD value) | ||
566 | { | ||
567 | string sval; | ||
568 | |||
569 | if (ConvertOutputValue(value,out sval,true)) | ||
570 | return sval.Length; | ||
571 | |||
572 | return 0; | ||
573 | } | ||
534 | } | 574 | } |
535 | 575 | ||
576 | // ----------------------------------------------------------------- | ||
577 | /// <summary> | ||
578 | /// </summary> | ||
579 | // ----------------------------------------------------------------- | ||
536 | public class JsonObjectStore : JsonStore | 580 | public class JsonObjectStore : JsonStore |
537 | { | 581 | { |
538 | private static readonly ILog m_log = | 582 | private static readonly ILog m_log = |
@@ -566,6 +610,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
566 | { | 610 | { |
567 | m_scene = scene; | 611 | m_scene = scene; |
568 | m_objectID = oid; | 612 | m_objectID = oid; |
613 | |||
614 | // the size limit is imposed on whatever is already in the store | ||
615 | StringSpace = ComputeSizeOf(ValueStore); | ||
569 | } | 616 | } |
570 | } | 617 | } |
571 | 618 | ||