From 134f86e8d5c414409631b25b8c6f0ee45fbd8631 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 3 Nov 2016 21:44:39 +1000 Subject: Initial update to OpenSim 0.8.2.1 source code. --- .../Scripting/JsonStore/JsonStoreModule.cs | 200 ++++++++++++++++++--- 1 file changed, 177 insertions(+), 23 deletions(-) (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs') 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; using System.Collections.Generic; using System.Text.RegularExpressions; - namespace OpenSim.Region.OptionalModules.Scripting.JsonStore { [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreModule")] @@ -54,9 +53,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore private IConfig m_config = null; private bool m_enabled = false; + private bool m_enableObjectStore = false; + private int m_maxStringSpace = Int32.MaxValue; + private Scene m_scene = null; private Dictionary m_JsonValueStore; + private UUID m_sharedStore; #region Region Module interface @@ -90,15 +93,19 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore } m_enabled = m_config.GetBoolean("Enabled", m_enabled); + m_enableObjectStore = m_config.GetBoolean("EnableObjectStore", m_enableObjectStore); + m_maxStringSpace = m_config.GetInt("MaxStringSpace", m_maxStringSpace); + if (m_maxStringSpace == 0) + m_maxStringSpace = Int32.MaxValue; } catch (Exception e) { - m_log.ErrorFormat("[JsonStore] initialization error: {0}",e.Message); + m_log.Error("[JsonStore]: initialization error: {0}", e); return; } if (m_enabled) - m_log.DebugFormat("[JsonStore] module is enabled"); + m_log.DebugFormat("[JsonStore]: module is enabled"); } // ----------------------------------------------------------------- @@ -133,6 +140,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore m_sharedStore = UUID.Zero; m_JsonValueStore = new Dictionary(); m_JsonValueStore.Add(m_sharedStore,new JsonStore("")); + + scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene; } } @@ -142,6 +151,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore // ----------------------------------------------------------------- public void RemoveRegion(Scene scene) { + scene.EventManager.OnObjectBeingRemovedFromScene -= EventManagerOnObjectBeingRemovedFromScene; + // need to remove all references to the scene in the subscription // list to enable full garbage collection of the scene object } @@ -154,7 +165,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore // ----------------------------------------------------------------- public void RegionLoaded(Scene scene) { - if (m_enabled) {} + if (m_enabled) + { + } } /// ----------------------------------------------------------------- @@ -168,8 +181,68 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore #endregion +#region SceneEvents + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public void EventManagerOnObjectBeingRemovedFromScene(SceneObjectGroup obj) + { + obj.ForEachPart(delegate(SceneObjectPart sop) { DestroyStore(sop.UUID); } ); + } + +#endregion + #region ScriptInvocationInteface + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public JsonStoreStats GetStoreStats() + { + JsonStoreStats stats; + + lock (m_JsonValueStore) + { + stats.StoreCount = m_JsonValueStore.Count; + } + + return stats; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool AttachObjectStore(UUID objectID) + { + if (! m_enabled) return false; + if (! m_enableObjectStore) return false; + + SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID); + if (sop == null) + { + m_log.ErrorFormat("[JsonStore] unable to attach to unknown object; {0}", objectID); + return false; + } + + lock (m_JsonValueStore) + { + if (m_JsonValueStore.ContainsKey(objectID)) + return true; + + JsonStore map = new JsonObjectStore(m_scene,objectID); + m_JsonValueStore.Add(objectID,map); + } + + return true; + } + // ----------------------------------------------------------------- /// /// @@ -189,9 +262,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore { map = new JsonStore(value); } - catch (Exception e) + catch (Exception) { - m_log.InfoFormat("[JsonStore] Unable to initialize store from {0}; {1}",value,e.Message); + m_log.ErrorFormat("[JsonStore]: Unable to initialize store from {0}", value); return false; } @@ -211,9 +284,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore if (! m_enabled) return false; lock (m_JsonValueStore) - m_JsonValueStore.Remove(storeID); - - return true; + return m_JsonValueStore.Remove(storeID); } // ----------------------------------------------------------------- @@ -221,31 +292,76 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- - public bool TestPath(UUID storeID, string path, bool useJson) + public bool TestStore(UUID storeID) { if (! m_enabled) return false; + lock (m_JsonValueStore) + return m_JsonValueStore.ContainsKey(storeID); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public JsonStoreNodeType GetNodeType(UUID storeID, string path) + { + if (! m_enabled) return JsonStoreNodeType.Undefined; + JsonStore map = null; lock (m_JsonValueStore) { if (! m_JsonValueStore.TryGetValue(storeID,out map)) { m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); - return false; + return JsonStoreNodeType.Undefined; } } try { lock (map) - return map.TestPath(path,useJson); + return map.GetNodeType(path); } catch (Exception e) { - m_log.InfoFormat("[JsonStore] Path test failed for {0} in {1}; {2}",path,storeID,e.Message); + m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e); } - return false; + return JsonStoreNodeType.Undefined; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public JsonStoreValueType GetValueType(UUID storeID, string path) + { + if (! m_enabled) return JsonStoreValueType.Undefined; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + { + m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); + return JsonStoreValueType.Undefined; + } + } + + try + { + lock (map) + return map.GetValueType(path); + } + catch (Exception e) + { + m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e); + } + + return JsonStoreValueType.Undefined; } // ----------------------------------------------------------------- @@ -270,12 +386,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore try { lock (map) - if (map.SetValue(path,value,useJson)) - return true; + { + if (map.StringSpace > m_maxStringSpace) + { + m_log.WarnFormat("[JsonStore] {0} exceeded string size; {1} bytes used of {2} limit", + storeID,map.StringSpace,m_maxStringSpace); + return false; + } + + return map.SetValue(path,value,useJson); + } } catch (Exception e) { - m_log.InfoFormat("[JsonStore] Unable to assign {0} to {1} in {2}; {3}",value,path,storeID,e.Message); + m_log.Error(string.Format("[JsonStore]: Unable to assign {0} to {1} in {2}", value, path, storeID), e); } return false; @@ -303,12 +427,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore try { lock (map) - if (map.RemoveValue(path)) - return true; + return map.RemoveValue(path); } catch (Exception e) { - m_log.InfoFormat("[JsonStore] Unable to remove {0} in {1}; {2}",path,storeID,e.Message); + m_log.Error(string.Format("[JsonStore]: Unable to remove {0} in {1}", path, storeID), e); } return false; @@ -319,6 +442,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- + public int GetArrayLength(UUID storeID, string path) + { + if (! m_enabled) return -1; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + return -1; + } + + try + { + lock (map) + { + return map.ArrayLength(path); + } + } + catch (Exception e) + { + m_log.Error("[JsonStore]: unable to retrieve value", e); + } + + return -1; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- public bool GetValue(UUID storeID, string path, bool useJson, out string value) { value = String.Empty; @@ -341,7 +495,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore } catch (Exception e) { - m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.Message); + m_log.Error("[JsonStore]: unable to retrieve value", e); } return false; @@ -380,7 +534,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore } catch (Exception e) { - m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); + m_log.Error("[JsonStore] unable to retrieve value", e); } cback(String.Empty); @@ -419,7 +573,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore } catch (Exception e) { - m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); + m_log.Error("[JsonStore]: unable to retrieve value", e); } cback(String.Empty); -- cgit v1.1