aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/DataSnapshot/DataSnapshotManager.cs')
-rw-r--r--OpenSim/Region/DataSnapshot/DataSnapshotManager.cs168
1 files changed, 96 insertions, 72 deletions
diff --git a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs
index 5540656..5e62f23 100644
--- a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs
+++ b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs
@@ -35,15 +35,20 @@ using System.Xml;
35using log4net; 35using log4net;
36using Nini.Config; 36using Nini.Config;
37using OpenMetaverse; 37using OpenMetaverse;
38using Mono.Addins;
38using OpenSim.Framework; 39using OpenSim.Framework;
39using OpenSim.Framework.Communications; 40using OpenSim.Framework.Communications;
40using OpenSim.Region.DataSnapshot.Interfaces; 41using OpenSim.Region.DataSnapshot.Interfaces;
41using OpenSim.Region.Framework.Interfaces; 42using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes; 43using OpenSim.Region.Framework.Scenes;
43 44
45[assembly: Addin("DataSnapshot", "0.1")]
46[assembly: AddinDependency("OpenSim", "0.5")]
47
44namespace OpenSim.Region.DataSnapshot 48namespace OpenSim.Region.DataSnapshot
45{ 49{
46 public class DataSnapshotManager : IRegionModule, IDataSnapshot 50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DataSnapshotManager")]
51 public class DataSnapshotManager : ISharedRegionModule, IDataSnapshot
47 { 52 {
48 #region Class members 53 #region Class members
49 //Information from config 54 //Information from config
@@ -67,6 +72,7 @@ namespace OpenSim.Region.DataSnapshot
67 public string m_listener_port = ConfigSettings.DefaultRegionHttpPort.ToString(); 72 public string m_listener_port = ConfigSettings.DefaultRegionHttpPort.ToString();
68 public string m_hostname = "127.0.0.1"; 73 public string m_hostname = "127.0.0.1";
69 private UUID m_Secret = UUID.Random(); 74 private UUID m_Secret = UUID.Random();
75 private bool m_servicesNotified = false;
70 76
71 //Update timers 77 //Update timers
72 private int m_period = 20; // in seconds 78 private int m_period = 20; // in seconds
@@ -93,9 +99,9 @@ namespace OpenSim.Region.DataSnapshot
93 99
94 #endregion 100 #endregion
95 101
96 #region IRegionModule 102 #region Region Module interface
97 103
98 public void Initialise(Scene scene, IConfigSource config) 104 public void Initialise(IConfigSource config)
99 { 105 {
100 if (!m_configLoaded) 106 if (!m_configLoaded)
101 { 107 {
@@ -133,82 +139,128 @@ namespace OpenSim.Region.DataSnapshot
133 m_enabled = false; 139 m_enabled = false;
134 return; 140 return;
135 } 141 }
136 }
137 142
138 if (m_enabled) 143 if (m_enabled)
139 { 144 m_snapStore = new SnapshotStore(m_snapsDir, m_gridinfo, m_listener_port, m_hostname);
140 //Hand it the first scene, assuming that all scenes have the same BaseHTTPServer 145 }
141 new DataRequestHandler(scene, this);
142 146
143 m_hostname = scene.RegionInfo.ExternalHostName; 147 }
144 m_snapStore = new SnapshotStore(m_snapsDir, m_gridinfo, m_listener_port, m_hostname);
145 148
146 MakeEverythingStale(); 149 }
147 150
148 if (m_dataServices != "" && m_dataServices != "noservices") 151 public void AddRegion(Scene scene)
149 NotifyDataServices(m_dataServices, "online"); 152 {
150 } 153 if (!m_enabled)
151 } 154 return;
152 155
153 if (m_enabled) 156 m_log.DebugFormat("[DATASNAPSHOT]: Module added to Scene {0}.", scene.RegionInfo.RegionName);
154 {
155 m_log.Info("[DATASNAPSHOT]: Scene added to module.");
156 157
157 m_snapStore.AddScene(scene); 158 m_snapStore.AddScene(scene);
158 m_scenes.Add(scene); 159 m_scenes.Add(scene);
159 160
160 Assembly currentasm = Assembly.GetExecutingAssembly(); 161 Assembly currentasm = Assembly.GetExecutingAssembly();
161 162
162 foreach (Type pluginType in currentasm.GetTypes()) 163 foreach (Type pluginType in currentasm.GetTypes())
164 {
165 if (pluginType.IsPublic)
163 { 166 {
164 if (pluginType.IsPublic) 167 if (!pluginType.IsAbstract)
165 { 168 {
166 if (!pluginType.IsAbstract) 169 if (pluginType.GetInterface("IDataSnapshotProvider") != null)
167 { 170 {
168 if (pluginType.GetInterface("IDataSnapshotProvider") != null) 171 IDataSnapshotProvider module = (IDataSnapshotProvider)Activator.CreateInstance(pluginType);
169 { 172 module.Initialize(scene, this);
170 IDataSnapshotProvider module = (IDataSnapshotProvider)Activator.CreateInstance(pluginType); 173 module.OnStale += MarkDataStale;
171 module.Initialize(scene, this);
172 module.OnStale += MarkDataStale;
173 174
174 m_dataproviders.Add(module); 175 m_dataproviders.Add(module);
175 m_snapStore.AddProvider(module); 176 m_snapStore.AddProvider(module);
176 177
177 m_log.Info("[DATASNAPSHOT]: Added new data provider type: " + pluginType.Name); 178 m_log.Debug("[DATASNAPSHOT]: Added new data provider type: " + pluginType.Name);
178 }
179 } 179 }
180 } 180 }
181 } 181 }
182 }
183
184 // Must be done here because on shared modules, PostInitialise() will run
185 // BEFORE any scenes are registered. There is no "all scenes have been loaded"
186 // kind of callback because scenes may be created dynamically, so we cannot
187 // have that info, ever.
188 if (!m_servicesNotified)
189 {
190 //Hand it the first scene, assuming that all scenes have the same BaseHTTPServer
191 new DataRequestHandler(m_scenes[0], this);
192
193 m_hostname = m_scenes[0].RegionInfo.ExternalHostName;
182 194
183 //scene.OnRestart += OnSimRestart; 195 if (m_dataServices != "" && m_dataServices != "noservices")
184 scene.EventManager.OnShutdown += delegate() { OnSimRestart(scene.RegionInfo); }; 196 NotifyDataServices(m_dataServices, "online");
197
198 m_servicesNotified = true;
185 } 199 }
186 else 200 }
201
202 public void RemoveRegion(Scene scene)
203 {
204 if (!m_enabled)
205 return;
206
207 m_log.Info("[DATASNAPSHOT]: Region " + scene.RegionInfo.RegionName + " is being removed, removing from indexing");
208 Scene restartedScene = SceneForUUID(scene.RegionInfo.RegionID);
209
210 m_scenes.Remove(restartedScene);
211 m_snapStore.RemoveScene(restartedScene);
212
213 //Getting around the fact that we can't remove objects from a collection we are enumerating over
214 List<IDataSnapshotProvider> providersToRemove = new List<IDataSnapshotProvider>();
215
216 foreach (IDataSnapshotProvider provider in m_dataproviders)
217 {
218 if (provider.GetParentScene == restartedScene)
219 {
220 providersToRemove.Add(provider);
221 }
222 }
223
224 foreach (IDataSnapshotProvider provider in providersToRemove)
187 { 225 {
188 //m_log.Debug("[DATASNAPSHOT]: Data snapshot disabled, not adding scene to module (or anything else)."); 226 m_dataproviders.Remove(provider);
227 m_snapStore.RemoveProvider(provider);
189 } 228 }
229
230 m_snapStore.RemoveScene(restartedScene);
190 } 231 }
191 232
192 public void Close() 233 public void PostInitialise()
193 { 234 {
194 if (m_enabled && m_dataServices != "" && m_dataServices != "noservices")
195 NotifyDataServices(m_dataServices, "offline");
196 } 235 }
197 236
237 public void RegionLoaded(Scene scene)
238 {
239 if (!m_enabled)
240 return;
241
242 m_log.DebugFormat("[DATASNAPSHOT]: Marking scene {0} as stale.", scene.RegionInfo.RegionName);
243 m_snapStore.ForceSceneStale(scene);
244 }
198 245
199 public bool IsSharedModule 246 public void Close()
200 { 247 {
201 get { return true; } 248 if (!m_enabled)
249 return;
250
251 if (m_enabled && m_dataServices != "" && m_dataServices != "noservices")
252 NotifyDataServices(m_dataServices, "offline");
202 } 253 }
203 254
255
204 public string Name 256 public string Name
205 { 257 {
206 get { return "External Data Generator"; } 258 get { return "External Data Generator"; }
207 } 259 }
208 260
209 public void PostInitialise() 261 public Type ReplaceableInterface
210 { 262 {
211 263 get { return null; }
212 } 264 }
213 265
214 #endregion 266 #endregion
@@ -399,35 +451,7 @@ namespace OpenSim.Region.DataSnapshot
399 m_snapStore.ForceSceneStale(scene); 451 m_snapStore.ForceSceneStale(scene);
400 } 452 }
401 } 453 }
402
403 #endregion 454 #endregion
404 455
405 public void OnSimRestart(RegionInfo thisRegion)
406 {
407 m_log.Info("[DATASNAPSHOT]: Region " + thisRegion.RegionName + " is restarting, removing from indexing");
408 Scene restartedScene = SceneForUUID(thisRegion.RegionID);
409
410 m_scenes.Remove(restartedScene);
411 m_snapStore.RemoveScene(restartedScene);
412
413 //Getting around the fact that we can't remove objects from a collection we are enumerating over
414 List<IDataSnapshotProvider> providersToRemove = new List<IDataSnapshotProvider>();
415
416 foreach (IDataSnapshotProvider provider in m_dataproviders)
417 {
418 if (provider.GetParentScene == restartedScene)
419 {
420 providersToRemove.Add(provider);
421 }
422 }
423
424 foreach (IDataSnapshotProvider provider in providersToRemove)
425 {
426 m_dataproviders.Remove(provider);
427 m_snapStore.RemoveProvider(provider);
428 }
429
430 m_snapStore.RemoveScene(restartedScene);
431 }
432 } 456 }
433} 457}