diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs | 200 |
1 files changed, 177 insertions, 23 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs index e68764a..26044f0 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs | |||
@@ -42,7 +42,6 @@ using OpenSim.Region.Framework.Scenes; | |||
42 | using System.Collections.Generic; | 42 | using System.Collections.Generic; |
43 | using System.Text.RegularExpressions; | 43 | using System.Text.RegularExpressions; |
44 | 44 | ||
45 | |||
46 | namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | 45 | namespace OpenSim.Region.OptionalModules.Scripting.JsonStore |
47 | { | 46 | { |
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreModule")] | 47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreModule")] |
@@ -54,9 +53,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
54 | 53 | ||
55 | private IConfig m_config = null; | 54 | private IConfig m_config = null; |
56 | private bool m_enabled = false; | 55 | private bool m_enabled = false; |
56 | private bool m_enableObjectStore = false; | ||
57 | private int m_maxStringSpace = Int32.MaxValue; | ||
58 | |||
57 | private Scene m_scene = null; | 59 | private Scene m_scene = null; |
58 | 60 | ||
59 | private Dictionary<UUID,JsonStore> m_JsonValueStore; | 61 | private Dictionary<UUID,JsonStore> m_JsonValueStore; |
62 | |||
60 | private UUID m_sharedStore; | 63 | private UUID m_sharedStore; |
61 | 64 | ||
62 | #region Region Module interface | 65 | #region Region Module interface |
@@ -90,15 +93,19 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
90 | } | 93 | } |
91 | 94 | ||
92 | m_enabled = m_config.GetBoolean("Enabled", m_enabled); | 95 | m_enabled = m_config.GetBoolean("Enabled", m_enabled); |
96 | m_enableObjectStore = m_config.GetBoolean("EnableObjectStore", m_enableObjectStore); | ||
97 | m_maxStringSpace = m_config.GetInt("MaxStringSpace", m_maxStringSpace); | ||
98 | if (m_maxStringSpace == 0) | ||
99 | m_maxStringSpace = Int32.MaxValue; | ||
93 | } | 100 | } |
94 | catch (Exception e) | 101 | catch (Exception e) |
95 | { | 102 | { |
96 | m_log.ErrorFormat("[JsonStore] initialization error: {0}",e.Message); | 103 | m_log.Error("[JsonStore]: initialization error: {0}", e); |
97 | return; | 104 | return; |
98 | } | 105 | } |
99 | 106 | ||
100 | if (m_enabled) | 107 | if (m_enabled) |
101 | m_log.DebugFormat("[JsonStore] module is enabled"); | 108 | m_log.DebugFormat("[JsonStore]: module is enabled"); |
102 | } | 109 | } |
103 | 110 | ||
104 | // ----------------------------------------------------------------- | 111 | // ----------------------------------------------------------------- |
@@ -133,6 +140,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
133 | m_sharedStore = UUID.Zero; | 140 | m_sharedStore = UUID.Zero; |
134 | m_JsonValueStore = new Dictionary<UUID,JsonStore>(); | 141 | m_JsonValueStore = new Dictionary<UUID,JsonStore>(); |
135 | m_JsonValueStore.Add(m_sharedStore,new JsonStore("")); | 142 | m_JsonValueStore.Add(m_sharedStore,new JsonStore("")); |
143 | |||
144 | scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene; | ||
136 | } | 145 | } |
137 | } | 146 | } |
138 | 147 | ||
@@ -142,6 +151,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
142 | // ----------------------------------------------------------------- | 151 | // ----------------------------------------------------------------- |
143 | public void RemoveRegion(Scene scene) | 152 | public void RemoveRegion(Scene scene) |
144 | { | 153 | { |
154 | scene.EventManager.OnObjectBeingRemovedFromScene -= EventManagerOnObjectBeingRemovedFromScene; | ||
155 | |||
145 | // need to remove all references to the scene in the subscription | 156 | // need to remove all references to the scene in the subscription |
146 | // list to enable full garbage collection of the scene object | 157 | // list to enable full garbage collection of the scene object |
147 | } | 158 | } |
@@ -154,7 +165,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
154 | // ----------------------------------------------------------------- | 165 | // ----------------------------------------------------------------- |
155 | public void RegionLoaded(Scene scene) | 166 | public void RegionLoaded(Scene scene) |
156 | { | 167 | { |
157 | if (m_enabled) {} | 168 | if (m_enabled) |
169 | { | ||
170 | } | ||
158 | } | 171 | } |
159 | 172 | ||
160 | /// ----------------------------------------------------------------- | 173 | /// ----------------------------------------------------------------- |
@@ -168,8 +181,68 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
168 | 181 | ||
169 | #endregion | 182 | #endregion |
170 | 183 | ||
184 | #region SceneEvents | ||
185 | // ----------------------------------------------------------------- | ||
186 | /// <summary> | ||
187 | /// | ||
188 | /// </summary> | ||
189 | // ----------------------------------------------------------------- | ||
190 | public void EventManagerOnObjectBeingRemovedFromScene(SceneObjectGroup obj) | ||
191 | { | ||
192 | obj.ForEachPart(delegate(SceneObjectPart sop) { DestroyStore(sop.UUID); } ); | ||
193 | } | ||
194 | |||
195 | #endregion | ||
196 | |||
171 | #region ScriptInvocationInteface | 197 | #region ScriptInvocationInteface |
172 | 198 | ||
199 | |||
200 | // ----------------------------------------------------------------- | ||
201 | /// <summary> | ||
202 | /// | ||
203 | /// </summary> | ||
204 | // ----------------------------------------------------------------- | ||
205 | public JsonStoreStats GetStoreStats() | ||
206 | { | ||
207 | JsonStoreStats stats; | ||
208 | |||
209 | lock (m_JsonValueStore) | ||
210 | { | ||
211 | stats.StoreCount = m_JsonValueStore.Count; | ||
212 | } | ||
213 | |||
214 | return stats; | ||
215 | } | ||
216 | |||
217 | // ----------------------------------------------------------------- | ||
218 | /// <summary> | ||
219 | /// | ||
220 | /// </summary> | ||
221 | // ----------------------------------------------------------------- | ||
222 | public bool AttachObjectStore(UUID objectID) | ||
223 | { | ||
224 | if (! m_enabled) return false; | ||
225 | if (! m_enableObjectStore) return false; | ||
226 | |||
227 | SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID); | ||
228 | if (sop == null) | ||
229 | { | ||
230 | m_log.ErrorFormat("[JsonStore] unable to attach to unknown object; {0}", objectID); | ||
231 | return false; | ||
232 | } | ||
233 | |||
234 | lock (m_JsonValueStore) | ||
235 | { | ||
236 | if (m_JsonValueStore.ContainsKey(objectID)) | ||
237 | return true; | ||
238 | |||
239 | JsonStore map = new JsonObjectStore(m_scene,objectID); | ||
240 | m_JsonValueStore.Add(objectID,map); | ||
241 | } | ||
242 | |||
243 | return true; | ||
244 | } | ||
245 | |||
173 | // ----------------------------------------------------------------- | 246 | // ----------------------------------------------------------------- |
174 | /// <summary> | 247 | /// <summary> |
175 | /// | 248 | /// |
@@ -189,9 +262,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
189 | { | 262 | { |
190 | map = new JsonStore(value); | 263 | map = new JsonStore(value); |
191 | } | 264 | } |
192 | catch (Exception e) | 265 | catch (Exception) |
193 | { | 266 | { |
194 | m_log.InfoFormat("[JsonStore] Unable to initialize store from {0}; {1}",value,e.Message); | 267 | m_log.ErrorFormat("[JsonStore]: Unable to initialize store from {0}", value); |
195 | return false; | 268 | return false; |
196 | } | 269 | } |
197 | 270 | ||
@@ -211,9 +284,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
211 | if (! m_enabled) return false; | 284 | if (! m_enabled) return false; |
212 | 285 | ||
213 | lock (m_JsonValueStore) | 286 | lock (m_JsonValueStore) |
214 | m_JsonValueStore.Remove(storeID); | 287 | return m_JsonValueStore.Remove(storeID); |
215 | |||
216 | return true; | ||
217 | } | 288 | } |
218 | 289 | ||
219 | // ----------------------------------------------------------------- | 290 | // ----------------------------------------------------------------- |
@@ -221,31 +292,76 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
221 | /// | 292 | /// |
222 | /// </summary> | 293 | /// </summary> |
223 | // ----------------------------------------------------------------- | 294 | // ----------------------------------------------------------------- |
224 | public bool TestPath(UUID storeID, string path, bool useJson) | 295 | public bool TestStore(UUID storeID) |
225 | { | 296 | { |
226 | if (! m_enabled) return false; | 297 | if (! m_enabled) return false; |
227 | 298 | ||
299 | lock (m_JsonValueStore) | ||
300 | return m_JsonValueStore.ContainsKey(storeID); | ||
301 | } | ||
302 | |||
303 | // ----------------------------------------------------------------- | ||
304 | /// <summary> | ||
305 | /// | ||
306 | /// </summary> | ||
307 | // ----------------------------------------------------------------- | ||
308 | public JsonStoreNodeType GetNodeType(UUID storeID, string path) | ||
309 | { | ||
310 | if (! m_enabled) return JsonStoreNodeType.Undefined; | ||
311 | |||
228 | JsonStore map = null; | 312 | JsonStore map = null; |
229 | lock (m_JsonValueStore) | 313 | lock (m_JsonValueStore) |
230 | { | 314 | { |
231 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | 315 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) |
232 | { | 316 | { |
233 | m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); | 317 | m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); |
234 | return false; | 318 | return JsonStoreNodeType.Undefined; |
235 | } | 319 | } |
236 | } | 320 | } |
237 | 321 | ||
238 | try | 322 | try |
239 | { | 323 | { |
240 | lock (map) | 324 | lock (map) |
241 | return map.TestPath(path,useJson); | 325 | return map.GetNodeType(path); |
242 | } | 326 | } |
243 | catch (Exception e) | 327 | catch (Exception e) |
244 | { | 328 | { |
245 | m_log.InfoFormat("[JsonStore] Path test failed for {0} in {1}; {2}",path,storeID,e.Message); | 329 | m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e); |
246 | } | 330 | } |
247 | 331 | ||
248 | return false; | 332 | return JsonStoreNodeType.Undefined; |
333 | } | ||
334 | |||
335 | // ----------------------------------------------------------------- | ||
336 | /// <summary> | ||
337 | /// | ||
338 | /// </summary> | ||
339 | // ----------------------------------------------------------------- | ||
340 | public JsonStoreValueType GetValueType(UUID storeID, string path) | ||
341 | { | ||
342 | if (! m_enabled) return JsonStoreValueType.Undefined; | ||
343 | |||
344 | JsonStore map = null; | ||
345 | lock (m_JsonValueStore) | ||
346 | { | ||
347 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
348 | { | ||
349 | m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); | ||
350 | return JsonStoreValueType.Undefined; | ||
351 | } | ||
352 | } | ||
353 | |||
354 | try | ||
355 | { | ||
356 | lock (map) | ||
357 | return map.GetValueType(path); | ||
358 | } | ||
359 | catch (Exception e) | ||
360 | { | ||
361 | m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e); | ||
362 | } | ||
363 | |||
364 | return JsonStoreValueType.Undefined; | ||
249 | } | 365 | } |
250 | 366 | ||
251 | // ----------------------------------------------------------------- | 367 | // ----------------------------------------------------------------- |
@@ -270,12 +386,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
270 | try | 386 | try |
271 | { | 387 | { |
272 | lock (map) | 388 | lock (map) |
273 | if (map.SetValue(path,value,useJson)) | 389 | { |
274 | return true; | 390 | if (map.StringSpace > m_maxStringSpace) |
391 | { | ||
392 | m_log.WarnFormat("[JsonStore] {0} exceeded string size; {1} bytes used of {2} limit", | ||
393 | storeID,map.StringSpace,m_maxStringSpace); | ||
394 | return false; | ||
395 | } | ||
396 | |||
397 | return map.SetValue(path,value,useJson); | ||
398 | } | ||
275 | } | 399 | } |
276 | catch (Exception e) | 400 | catch (Exception e) |
277 | { | 401 | { |
278 | m_log.InfoFormat("[JsonStore] Unable to assign {0} to {1} in {2}; {3}",value,path,storeID,e.Message); | 402 | m_log.Error(string.Format("[JsonStore]: Unable to assign {0} to {1} in {2}", value, path, storeID), e); |
279 | } | 403 | } |
280 | 404 | ||
281 | return false; | 405 | return false; |
@@ -303,12 +427,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
303 | try | 427 | try |
304 | { | 428 | { |
305 | lock (map) | 429 | lock (map) |
306 | if (map.RemoveValue(path)) | 430 | return map.RemoveValue(path); |
307 | return true; | ||
308 | } | 431 | } |
309 | catch (Exception e) | 432 | catch (Exception e) |
310 | { | 433 | { |
311 | m_log.InfoFormat("[JsonStore] Unable to remove {0} in {1}; {2}",path,storeID,e.Message); | 434 | m_log.Error(string.Format("[JsonStore]: Unable to remove {0} in {1}", path, storeID), e); |
312 | } | 435 | } |
313 | 436 | ||
314 | return false; | 437 | return false; |
@@ -319,6 +442,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
319 | /// | 442 | /// |
320 | /// </summary> | 443 | /// </summary> |
321 | // ----------------------------------------------------------------- | 444 | // ----------------------------------------------------------------- |
445 | public int GetArrayLength(UUID storeID, string path) | ||
446 | { | ||
447 | if (! m_enabled) return -1; | ||
448 | |||
449 | JsonStore map = null; | ||
450 | lock (m_JsonValueStore) | ||
451 | { | ||
452 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
453 | return -1; | ||
454 | } | ||
455 | |||
456 | try | ||
457 | { | ||
458 | lock (map) | ||
459 | { | ||
460 | return map.ArrayLength(path); | ||
461 | } | ||
462 | } | ||
463 | catch (Exception e) | ||
464 | { | ||
465 | m_log.Error("[JsonStore]: unable to retrieve value", e); | ||
466 | } | ||
467 | |||
468 | return -1; | ||
469 | } | ||
470 | |||
471 | // ----------------------------------------------------------------- | ||
472 | /// <summary> | ||
473 | /// | ||
474 | /// </summary> | ||
475 | // ----------------------------------------------------------------- | ||
322 | public bool GetValue(UUID storeID, string path, bool useJson, out string value) | 476 | public bool GetValue(UUID storeID, string path, bool useJson, out string value) |
323 | { | 477 | { |
324 | value = String.Empty; | 478 | value = String.Empty; |
@@ -341,7 +495,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
341 | } | 495 | } |
342 | catch (Exception e) | 496 | catch (Exception e) |
343 | { | 497 | { |
344 | m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.Message); | 498 | m_log.Error("[JsonStore]: unable to retrieve value", e); |
345 | } | 499 | } |
346 | 500 | ||
347 | return false; | 501 | return false; |
@@ -380,7 +534,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
380 | } | 534 | } |
381 | catch (Exception e) | 535 | catch (Exception e) |
382 | { | 536 | { |
383 | m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); | 537 | m_log.Error("[JsonStore] unable to retrieve value", e); |
384 | } | 538 | } |
385 | 539 | ||
386 | cback(String.Empty); | 540 | cback(String.Empty); |
@@ -419,7 +573,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
419 | } | 573 | } |
420 | catch (Exception e) | 574 | catch (Exception e) |
421 | { | 575 | { |
422 | m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); | 576 | m_log.Error("[JsonStore]: unable to retrieve value", e); |
423 | } | 577 | } |
424 | 578 | ||
425 | cback(String.Empty); | 579 | cback(String.Empty); |