29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Threading;
36 using OpenSim.Framework;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Framework.Monitoring;
39 using OpenSim.Region.Framework.Scenes;
42 namespace OpenSim.
Region.CoreModules.Framework
44 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"GridServiceThrottleModule")]
47 private static readonly ILog m_log = LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
50 private readonly List<Scene> m_scenes =
new List<Scene>();
51 private System.Timers.Timer m_timer =
new System.Timers.Timer();
53 private Queue<Action> m_RequestQueue =
new Queue<Action>();
54 private Dictionary<string, List<string>> m_Pending =
new Dictionary<string, List<string>>();
55 private int m_Interval;
57 #region ISharedRegionModule
61 m_Interval = Util.GetConfigVarFromSections<
int>(config,
"Interval",
new string[] {
"ServiceThrottle" }, 5000);
63 m_timer =
new System.Timers.Timer();
64 m_timer.AutoReset =
false;
65 m_timer.Enabled =
true;
66 m_timer.Interval = 15000;
67 m_timer.Elapsed += ProcessQueue;
84 scene.EventManager.OnNewClient += OnNewClient;
85 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
97 m_scenes.Remove(scene);
98 scene.EventManager.OnNewClient -= OnNewClient;
112 get {
return "ServiceThrottleModule"; }
115 public Type ReplaceableInterface
120 #endregion ISharedRegionMOdule
126 client.OnRegionHandleRequest += OnRegionHandleRequest;
133 if (!m_timer.Enabled)
135 m_timer.Interval = m_Interval;
136 m_timer.Enabled =
true;
146 if (IsLocalRegionHandle(regionID, out handle))
148 client.SendRegionHandle(regionID, handle);
152 Action action = delegate
154 GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, regionID);
156 if (r != null && r.RegionHandle != 0)
157 client.SendRegionHandle(regionID, r.RegionHandle);
160 Enqueue(
"region", regionID.ToString(), action);
165 #region IServiceThrottleModule
167 public void Enqueue(
string category,
string itemid, Action continuation)
169 lock (m_RequestQueue)
171 if (m_Pending.ContainsKey(category))
173 if (m_Pending[category].Contains(itemid))
178 m_Pending.Add(category,
new List<string>());
180 m_Pending[category].Add(itemid);
182 m_RequestQueue.Enqueue(delegate
184 lock (m_RequestQueue)
185 m_Pending[category].Remove(itemid);
192 #endregion IServiceThrottleModule
194 #region Process Continuation Queue
196 private void ProcessQueue(
object sender, System.Timers.ElapsedEventArgs e)
200 while (m_RequestQueue.Count > 0)
202 Action continuation = null;
203 lock (m_RequestQueue)
204 continuation = m_RequestQueue.Dequeue();
206 if (continuation != null)
210 if (AreThereRootAgents())
214 m_timer.Interval = 1000;
215 m_timer.Enabled =
true;
221 m_timer.Enabled = false;
225 #endregion Process Continuation Queue
229 private bool IsLocalRegionHandle(UUID regionID, out ulong regionHandle)
232 foreach (
Scene s
in m_scenes)
235 regionHandle = s.RegionInfo.RegionHandle;
241 private bool AreThereRootAgents()
243 foreach (
Scene s
in m_scenes)
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
OpenSim.Services.Interfaces.GridRegion GridRegion
void Enqueue(string category, string itemid, Action continuation)
Enqueue a continuation meant to get a resource from elsewhere. As usual with CPS, caller beware: if t...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
void OnRegionHandleRequest(IClientAPI client, UUID regionID)
List< ScenePresence > GetScenePresences()
Gets all the scene presences in this scene.
OpenSim.Services.Interfaces.GridRegion GridRegion
virtual RegionInfo RegionInfo
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...