OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
JsonStoreCommands.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSim Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 using Mono.Addins;
28 
29 using System;
30 using System.Reflection;
31 using System.Threading;
32 using System.Text;
33 using System.Net;
34 using System.Net.Sockets;
35 using log4net;
36 using Nini.Config;
37 using OpenMetaverse;
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;
44 
45 namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
46 {
47  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreCommandsModule")]
48 
50  {
51  private static readonly ILog m_log =
52  LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 
54  private IConfig m_config = null;
55  private bool m_enabled = false;
56 
57  private Scene m_scene = null;
58  //private IJsonStoreModule m_store;
59  private JsonStoreModule m_store;
60 
61 #region Region Module interface
62 
63  // -----------------------------------------------------------------
67  // -----------------------------------------------------------------
68  public string Name
69  {
70  get { return this.GetType().Name; }
71  }
72 
73  // -----------------------------------------------------------------
79  // -----------------------------------------------------------------
80  public void Initialise(IConfigSource config)
81  {
82  try
83  {
84  if ((m_config = config.Configs["JsonStore"]) == null)
85  {
86  // There is no configuration, the module is disabled
87  // m_log.InfoFormat("[JsonStore] no configuration info");
88  return;
89  }
90 
91  m_enabled = m_config.GetBoolean("Enabled", m_enabled);
92  }
93  catch (Exception e)
94  {
95  m_log.Error("[JsonStore]: initialization error: {0}", e);
96  return;
97  }
98 
99  if (m_enabled)
100  m_log.DebugFormat("[JsonStore]: module is enabled");
101  }
102 
103  // -----------------------------------------------------------------
107  // -----------------------------------------------------------------
108  public void PostInitialise()
109  {
110  }
111 
112  // -----------------------------------------------------------------
116  // -----------------------------------------------------------------
117  public void Close()
118  {
119  }
120 
121  // -----------------------------------------------------------------
124  // -----------------------------------------------------------------
125  public void AddRegion(Scene scene)
126  {
127  if (m_enabled)
128  {
129  m_scene = scene;
130 
131  }
132  }
133 
134  // -----------------------------------------------------------------
137  // -----------------------------------------------------------------
138  public void RemoveRegion(Scene scene)
139  {
140  // need to remove all references to the scene in the subscription
141  // list to enable full garbage collection of the scene object
142  }
143 
144  // -----------------------------------------------------------------
149  // -----------------------------------------------------------------
150  public void RegionLoaded(Scene scene)
151  {
152  if (m_enabled)
153  {
154  m_scene = scene;
155 
156  m_store = (JsonStoreModule) m_scene.RequestModuleInterface<IJsonStoreModule>();
157  if (m_store == null)
158  {
159  m_log.ErrorFormat("[JsonStoreCommands]: JsonModule interface not defined");
160  m_enabled = false;
161  return;
162  }
163 
164  scene.AddCommand("JsonStore", this, "jsonstore stats", "jsonstore stats",
165  "Display statistics about the state of the JsonStore module", "",
166  CmdStats);
167  }
168  }
169 
173  // -----------------------------------------------------------------
174  public Type ReplaceableInterface
175  {
176  get { return null; }
177  }
178 
179 #endregion
180 
181 #region Commands
182 
183  private void CmdStats(string module, string[] cmd)
184  {
186  return;
187 
188  JsonStoreStats stats = m_store.GetStoreStats();
189  MainConsole.Instance.OutputFormat("{0}\t{1}",m_scene.RegionInfo.RegionName,stats.StoreCount);
190  }
191 
192 #endregion
193 
194  }
195 }
void Initialise(IConfigSource config)
Initialise this shared module
void PostInitialise()
everything is loaded, perform post load configuration
static ICommandConsole Instance
Definition: MainConsole.cs:35
void RegionLoaded(Scene scene)
Called when all modules have been added for a region. This is where we hook up events ...