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 log4net;
using Nini.Config; using Nini.Config;
using OpenMetaverse; using OpenMetaverse;
using Mono.Addins;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Communications; using OpenSim.Framework.Communications;
using OpenSim.Region.DataSnapshot.Interfaces; using OpenSim.Region.DataSnapshot.Interfaces;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
[assembly: Addin("LindenCaps", "0.1")]
[assembly: AddinDependency("OpenSim", "0.5")]
namespace OpenSim.Region.DataSnapshot namespace OpenSim.Region.DataSnapshot
{ {
public class DataSnapshotManager : IRegionModule, IDataSnapshot [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class DataSnapshotManager : ISharedRegionModule, IDataSnapshot
{ {
#region Class members #region Class members
//Information from config //Information from config
@ -95,7 +100,7 @@ namespace OpenSim.Region.DataSnapshot
#region IRegionModule #region IRegionModule
public void Initialise(Scene scene, IConfigSource config) public void Initialise(IConfigSource config)
{ {
if (!m_configLoaded) if (!m_configLoaded)
{ {
@ -133,82 +138,121 @@ namespace OpenSim.Region.DataSnapshot
m_enabled = false; m_enabled = false;
return; 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."); if (pluginType.IsPublic)
m_snapStore.AddScene(scene);
m_scenes.Add(scene);
Assembly currentasm = Assembly.GetExecutingAssembly();
foreach (Type pluginType in currentasm.GetTypes())
{ {
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);
IDataSnapshotProvider module = (IDataSnapshotProvider)Activator.CreateInstance(pluginType); module.OnStale += MarkDataStale;
module.Initialize(scene, this);
module.OnStale += MarkDataStale;
m_dataproviders.Add(module); m_dataproviders.Add(module);
m_snapStore.AddProvider(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; public void RemoveRegion(Scene scene)
scene.EventManager.OnShutdown += delegate() { OnSimRestart(scene.RegionInfo); }; {
} if (!m_enabled)
else 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() public void Close()
{ {
if (!m_enabled)
return;
if (m_enabled && m_dataServices != "" && m_dataServices != "noservices") if (m_enabled && m_dataServices != "" && m_dataServices != "noservices")
NotifyDataServices(m_dataServices, "offline"); NotifyDataServices(m_dataServices, "offline");
} }
public bool IsSharedModule
{
get { return true; }
}
public string Name public string Name
{ {
get { return "External Data Generator"; } get { return "External Data Generator"; }
} }
public void PostInitialise() public Type ReplaceableInterface
{ {
get { return null; }
} }
#endregion #endregion
@ -399,35 +443,7 @@ namespace OpenSim.Region.DataSnapshot
m_snapStore.ForceSceneStale(scene); m_snapStore.ForceSceneStale(scene);
} }
} }
#endregion #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 public interface IDataSnapshot
{ {
XmlDocument GetSnapshot(string regionName); XmlDocument GetSnapshot(string regionName);
void MakeEverythingStale();
} }
} }