One more module converted: DataSnapshot.

integration
Diva Canto 2012-11-10 11:26:03 -08:00
parent 3a5e317f65
commit b3574d23e4
2 changed files with 91 additions and 76 deletions

View File

@ -35,15 +35,20 @@ using System.Xml;
using log4net;
using Nini.Config;
using OpenMetaverse;
using Mono.Addins;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Region.DataSnapshot.Interfaces;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
[assembly: Addin("LindenCaps", "0.1")]
[assembly: AddinDependency("OpenSim", "0.5")]
namespace OpenSim.Region.DataSnapshot
{
public class DataSnapshotManager : IRegionModule, IDataSnapshot
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class DataSnapshotManager : ISharedRegionModule, IDataSnapshot
{
#region Class members
//Information from config
@ -95,7 +100,7 @@ namespace OpenSim.Region.DataSnapshot
#region IRegionModule
public void Initialise(Scene scene, IConfigSource config)
public void Initialise(IConfigSource config)
{
if (!m_configLoaded)
{
@ -133,82 +138,121 @@ namespace OpenSim.Region.DataSnapshot
m_enabled = false;
return;
}
if (m_enabled)
m_snapStore = new SnapshotStore(m_snapsDir, m_gridinfo, m_listener_port, m_hostname);
}
if (m_enabled)
{
//Hand it the first scene, assuming that all scenes have the same BaseHTTPServer
new DataRequestHandler(scene, this);
m_hostname = scene.RegionInfo.ExternalHostName;
m_snapStore = new SnapshotStore(m_snapsDir, m_gridinfo, m_listener_port, m_hostname);
MakeEverythingStale();
if (m_dataServices != "" && m_dataServices != "noservices")
NotifyDataServices(m_dataServices, "online");
}
}
if (m_enabled)
}
public void AddRegion(Scene scene)
{
if (!m_enabled)
return;
m_log.DebugFormat("[DATASNAPSHOT]: Module added to Scene {0}.", scene.RegionInfo.RegionName);
m_snapStore.AddScene(scene);
m_scenes.Add(scene);
Assembly currentasm = Assembly.GetExecutingAssembly();
foreach (Type pluginType in currentasm.GetTypes())
{
m_log.Info("[DATASNAPSHOT]: Scene added to module.");
m_snapStore.AddScene(scene);
m_scenes.Add(scene);
Assembly currentasm = Assembly.GetExecutingAssembly();
foreach (Type pluginType in currentasm.GetTypes())
if (pluginType.IsPublic)
{
if (pluginType.IsPublic)
if (!pluginType.IsAbstract)
{
if (!pluginType.IsAbstract)
if (pluginType.GetInterface("IDataSnapshotProvider") != null)
{
if (pluginType.GetInterface("IDataSnapshotProvider") != null)
{
IDataSnapshotProvider module = (IDataSnapshotProvider)Activator.CreateInstance(pluginType);
module.Initialize(scene, this);
module.OnStale += MarkDataStale;
IDataSnapshotProvider module = (IDataSnapshotProvider)Activator.CreateInstance(pluginType);
module.Initialize(scene, this);
module.OnStale += MarkDataStale;
m_dataproviders.Add(module);
m_snapStore.AddProvider(module);
m_dataproviders.Add(module);
m_snapStore.AddProvider(module);
m_log.Info("[DATASNAPSHOT]: Added new data provider type: " + pluginType.Name);
}
m_log.Debug("[DATASNAPSHOT]: Added new data provider type: " + pluginType.Name);
}
}
}
}
}
//scene.OnRestart += OnSimRestart;
scene.EventManager.OnShutdown += delegate() { OnSimRestart(scene.RegionInfo); };
}
else
public void RemoveRegion(Scene scene)
{
if (!m_enabled)
return;
m_log.Info("[DATASNAPSHOT]: Region " + scene.RegionInfo.RegionName + " is being removed, removing from indexing");
Scene restartedScene = SceneForUUID(scene.RegionInfo.RegionID);
m_scenes.Remove(restartedScene);
m_snapStore.RemoveScene(restartedScene);
//Getting around the fact that we can't remove objects from a collection we are enumerating over
List<IDataSnapshotProvider> providersToRemove = new List<IDataSnapshotProvider>();
foreach (IDataSnapshotProvider provider in m_dataproviders)
{
//m_log.Debug("[DATASNAPSHOT]: Data snapshot disabled, not adding scene to module (or anything else).");
if (provider.GetParentScene == restartedScene)
{
providersToRemove.Add(provider);
}
}
foreach (IDataSnapshotProvider provider in providersToRemove)
{
m_dataproviders.Remove(provider);
m_snapStore.RemoveProvider(provider);
}
m_snapStore.RemoveScene(restartedScene);
}
public void PostInitialise()
{
if (!m_enabled)
return;
//Hand it the first scene, assuming that all scenes have the same BaseHTTPServer
new DataRequestHandler(m_scenes[0], this);
m_hostname = m_scenes[0].RegionInfo.ExternalHostName;
if (m_dataServices != "" && m_dataServices != "noservices")
NotifyDataServices(m_dataServices, "online");
}
public void RegionLoaded(Scene scene)
{
if (!m_enabled)
return;
m_log.DebugFormat("[DATASNAPSHOT]: Marking scene {0} as stale.", scene.RegionInfo.RegionName);
m_snapStore.ForceSceneStale(scene);
}
public void Close()
{
if (!m_enabled)
return;
if (m_enabled && m_dataServices != "" && m_dataServices != "noservices")
NotifyDataServices(m_dataServices, "offline");
}
public bool IsSharedModule
{
get { return true; }
}
public string Name
{
get { return "External Data Generator"; }
}
public void PostInitialise()
public Type ReplaceableInterface
{
get { return null; }
}
#endregion
@ -399,35 +443,7 @@ namespace OpenSim.Region.DataSnapshot
m_snapStore.ForceSceneStale(scene);
}
}
#endregion
public void OnSimRestart(RegionInfo thisRegion)
{
m_log.Info("[DATASNAPSHOT]: Region " + thisRegion.RegionName + " is restarting, removing from indexing");
Scene restartedScene = SceneForUUID(thisRegion.RegionID);
m_scenes.Remove(restartedScene);
m_snapStore.RemoveScene(restartedScene);
//Getting around the fact that we can't remove objects from a collection we are enumerating over
List<IDataSnapshotProvider> providersToRemove = new List<IDataSnapshotProvider>();
foreach (IDataSnapshotProvider provider in m_dataproviders)
{
if (provider.GetParentScene == restartedScene)
{
providersToRemove.Add(provider);
}
}
foreach (IDataSnapshotProvider provider in providersToRemove)
{
m_dataproviders.Remove(provider);
m_snapStore.RemoveProvider(provider);
}
m_snapStore.RemoveScene(restartedScene);
}
}
}

View File

@ -32,6 +32,5 @@ namespace OpenSim.Region.DataSnapshot.Interfaces
public interface IDataSnapshot
{
XmlDocument GetSnapshot(string regionName);
void MakeEverythingStale();
}
}