30 using System.Reflection;
31 using System.Threading;
34 using System.Net.Sockets;
38 using OpenMetaverse.StructuredData;
39 using OpenSim.Framework;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
42 using System.Collections.Generic;
43 using System.Text.RegularExpressions;
45 namespace OpenSim.
Region.OptionalModules.Scripting.JsonStore
47 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"JsonStoreModule")]
51 private static readonly ILog m_log =
52 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 private IConfig m_config = null;
55 private bool m_enabled =
false;
56 private bool m_enableObjectStore =
false;
57 private int m_maxStringSpace = Int32.MaxValue;
59 private Scene m_scene = null;
61 private Dictionary<UUID,JsonStore> m_JsonValueStore;
63 private UUID m_sharedStore;
65 #region Region Module interface
74 get {
return this.GetType().Name; }
88 if ((m_config = config.Configs[
"JsonStore"]) == null)
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;
103 m_log.Error(
"[JsonStore]: initialization error: {0}", e);
108 m_log.DebugFormat(
"[JsonStore]: module is enabled");
140 m_sharedStore = UUID.Zero;
141 m_JsonValueStore =
new Dictionary<UUID,JsonStore>();
142 m_JsonValueStore.Add(m_sharedStore,
new JsonStore(
""));
144 scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene;
154 scene.EventManager.OnObjectBeingRemovedFromScene -= EventManagerOnObjectBeingRemovedFromScene;
177 public Type ReplaceableInterface
197 #region ScriptInvocationInteface
209 lock (m_JsonValueStore)
211 stats.StoreCount = m_JsonValueStore.Count;
224 if (! m_enabled)
return false;
225 if (! m_enableObjectStore)
return false;
230 m_log.ErrorFormat(
"[JsonStore] unable to attach to unknown object; {0}", objectID);
234 lock (m_JsonValueStore)
236 if (m_JsonValueStore.ContainsKey(objectID))
240 m_JsonValueStore.Add(objectID,map);
253 if (result ==
UUID.Zero)
254 result = UUID.Random();
258 if (! m_enabled)
return false;
267 m_log.ErrorFormat(
"[JsonStore]: Unable to initialize store from {0}", value);
271 lock (m_JsonValueStore)
272 m_JsonValueStore.Add(result,map);
284 if (! m_enabled)
return false;
286 lock (m_JsonValueStore)
287 return m_JsonValueStore.Remove(storeID);
297 if (! m_enabled)
return false;
299 lock (m_JsonValueStore)
300 return m_JsonValueStore.ContainsKey(storeID);
310 if (! m_enabled)
return JsonStoreNodeType.Undefined;
313 lock (m_JsonValueStore)
315 if (! m_JsonValueStore.TryGetValue(storeID,out map))
317 m_log.InfoFormat(
"[JsonStore] Missing store {0}",storeID);
318 return JsonStoreNodeType.Undefined;
325 return map.GetNodeType(path);
329 m_log.Error(string.Format(
"[JsonStore]: Path test failed for {0} in {1}", path, storeID), e);
332 return JsonStoreNodeType.Undefined;
342 if (! m_enabled)
return JsonStoreValueType.Undefined;
345 lock (m_JsonValueStore)
347 if (! m_JsonValueStore.TryGetValue(storeID,out map))
349 m_log.InfoFormat(
"[JsonStore] Missing store {0}",storeID);
350 return JsonStoreValueType.Undefined;
357 return map.GetValueType(path);
361 m_log.Error(string.Format(
"[JsonStore]: Path test failed for {0} in {1}", path, storeID), e);
364 return JsonStoreValueType.Undefined;
372 public bool SetValue(UUID storeID,
string path,
string value,
bool useJson)
374 if (! m_enabled)
return false;
377 lock (m_JsonValueStore)
379 if (! m_JsonValueStore.TryGetValue(storeID,out map))
381 m_log.InfoFormat(
"[JsonStore] Missing store {0}",storeID);
392 m_log.WarnFormat(
"[JsonStore] {0} exceeded string size; {1} bytes used of {2} limit",
393 storeID,map.StringSpace,m_maxStringSpace);
397 return map.SetValue(path,value,useJson);
402 m_log.Error(string.Format(
"[JsonStore]: Unable to assign {0} to {1} in {2}", value, path, storeID), e);
415 if (! m_enabled)
return false;
418 lock (m_JsonValueStore)
420 if (! m_JsonValueStore.TryGetValue(storeID,out map))
422 m_log.InfoFormat(
"[JsonStore] Missing store {0}",storeID);
430 return map.RemoveValue(path);
434 m_log.Error(string.Format(
"[JsonStore]: Unable to remove {0} in {1}", path, storeID), e);
447 if (! m_enabled)
return -1;
450 lock (m_JsonValueStore)
452 if (! m_JsonValueStore.TryGetValue(storeID,out map))
460 return map.ArrayLength(path);
465 m_log.Error(
"[JsonStore]: unable to retrieve value", e);
476 public bool GetValue(UUID storeID,
string path,
bool useJson, out
string value)
478 value = String.Empty;
480 if (! m_enabled)
return false;
483 lock (m_JsonValueStore)
485 if (! m_JsonValueStore.TryGetValue(storeID,out map))
493 return map.GetValue(path, out value, useJson);
498 m_log.Error(
"[JsonStore]: unable to retrieve value", e);
518 lock (m_JsonValueStore)
520 if (! m_JsonValueStore.TryGetValue(storeID,out map))
531 map.TakeValue(path, useJson, cback);
537 m_log.Error(
"[JsonStore] unable to retrieve value", e);
557 lock (m_JsonValueStore)
559 if (! m_JsonValueStore.TryGetValue(storeID,out map))
570 map.ReadValue(path, useJson, cback);
576 m_log.Error(
"[JsonStore]: unable to retrieve value", e);
void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback)
bool AttachObjectStore(UUID objectID)
void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback)
int GetArrayLength(UUID storeID, string path)
int StringSpace
This is a simple estimator for the size of the stored data, it is not precise, but should be close en...
bool TestStore(UUID storeID)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void PostInitialise()
everything is loaded, perform post load configuration
void EventManagerOnObjectBeingRemovedFromScene(SceneObjectGroup obj)
JsonStoreStats GetStoreStats()
delegate void TakeValueCallback(string s)
void Close()
Nothing to do on close
bool GetValue(UUID storeID, string path, bool useJson, out string value)
bool SetValue(UUID storeID, string path, string value, bool useJson)
bool DestroyStore(UUID storeID)
JsonStoreValueType GetValueType(UUID storeID, string path)
void Initialise(IConfigSource config)
Initialise this shared module
bool CreateStore(string value, ref UUID result)
bool RemoveValue(UUID storeID, string path)
void RemoveRegion(Scene scene)
JsonStoreNodeType GetNodeType(UUID storeID, string path)
void AddRegion(Scene scene)
void RegionLoaded(Scene scene)
Called when all modules have been added for a region. This is where we hook up events ...