diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs | 147 |
1 files changed, 60 insertions, 87 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index eb40eb1..ffb53af 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs | |||
@@ -65,6 +65,13 @@ namespace OpenSim.Region.ClientStack.Linden | |||
65 | /// </value> | 65 | /// </value> |
66 | public int DebugLevel { get; set; } | 66 | public int DebugLevel { get; set; } |
67 | 67 | ||
68 | // Viewer post requests timeout in 60 secs | ||
69 | // https://bitbucket.org/lindenlab/viewer-release/src/421c20423df93d650cc305dc115922bb30040999/indra/llmessage/llhttpclient.cpp?at=default#cl-44 | ||
70 | // | ||
71 | private const int VIEWER_TIMEOUT = 60 * 1000; | ||
72 | // Just to be safe, we work on a 10 sec shorter cycle | ||
73 | private const int SERVER_EQ_TIME_NO_EVENTS = VIEWER_TIMEOUT - (10 * 1000); | ||
74 | |||
68 | protected Scene m_scene; | 75 | protected Scene m_scene; |
69 | 76 | ||
70 | private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>(); | 77 | private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>(); |
@@ -84,7 +91,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
84 | scene.RegisterModuleInterface<IEventQueue>(this); | 91 | scene.RegisterModuleInterface<IEventQueue>(this); |
85 | 92 | ||
86 | scene.EventManager.OnClientClosed += ClientClosed; | 93 | scene.EventManager.OnClientClosed += ClientClosed; |
87 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; | ||
88 | scene.EventManager.OnRegisterCaps += OnRegisterCaps; | 94 | scene.EventManager.OnRegisterCaps += OnRegisterCaps; |
89 | 95 | ||
90 | MainConsole.Instance.Commands.AddCommand( | 96 | MainConsole.Instance.Commands.AddCommand( |
@@ -113,7 +119,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
113 | return; | 119 | return; |
114 | 120 | ||
115 | scene.EventManager.OnClientClosed -= ClientClosed; | 121 | scene.EventManager.OnClientClosed -= ClientClosed; |
116 | scene.EventManager.OnMakeChildAgent -= MakeChildAgent; | ||
117 | scene.EventManager.OnRegisterCaps -= OnRegisterCaps; | 122 | scene.EventManager.OnRegisterCaps -= OnRegisterCaps; |
118 | 123 | ||
119 | scene.UnregisterModuleInterface<IEventQueue>(this); | 124 | scene.UnregisterModuleInterface<IEventQueue>(this); |
@@ -182,14 +187,12 @@ namespace OpenSim.Region.ClientStack.Linden | |||
182 | { | 187 | { |
183 | if (!queues.ContainsKey(agentId)) | 188 | if (!queues.ContainsKey(agentId)) |
184 | { | 189 | { |
185 | /* | ||
186 | m_log.DebugFormat( | 190 | m_log.DebugFormat( |
187 | "[EVENTQUEUE]: Adding new queue for agent {0} in region {1}", | 191 | "[EVENTQUEUE]: Adding new queue for agent {0} in region {1}", |
188 | agentId, m_scene.RegionInfo.RegionName); | 192 | agentId, m_scene.RegionInfo.RegionName); |
189 | */ | ||
190 | queues[agentId] = new Queue<OSD>(); | 193 | queues[agentId] = new Queue<OSD>(); |
191 | } | 194 | } |
192 | 195 | ||
193 | return queues[agentId]; | 196 | return queues[agentId]; |
194 | } | 197 | } |
195 | } | 198 | } |
@@ -221,8 +224,17 @@ namespace OpenSim.Region.ClientStack.Linden | |||
221 | { | 224 | { |
222 | Queue<OSD> queue = GetQueue(avatarID); | 225 | Queue<OSD> queue = GetQueue(avatarID); |
223 | if (queue != null) | 226 | if (queue != null) |
227 | { | ||
224 | lock (queue) | 228 | lock (queue) |
225 | queue.Enqueue(ev); | 229 | queue.Enqueue(ev); |
230 | } | ||
231 | else | ||
232 | { | ||
233 | OSDMap evMap = (OSDMap)ev; | ||
234 | m_log.WarnFormat( | ||
235 | "[EVENTQUEUE]: (Enqueue) No queue found for agent {0} when placing message {1} in region {2}", | ||
236 | avatarID, evMap["message"], m_scene.Name); | ||
237 | } | ||
226 | } | 238 | } |
227 | catch (NullReferenceException e) | 239 | catch (NullReferenceException e) |
228 | { | 240 | { |
@@ -237,44 +249,14 @@ namespace OpenSim.Region.ClientStack.Linden | |||
237 | 249 | ||
238 | private void ClientClosed(UUID agentID, Scene scene) | 250 | private void ClientClosed(UUID agentID, Scene scene) |
239 | { | 251 | { |
240 | // m_log.DebugFormat("[EVENTQUEUE]: Closed client {0} in region {1}", agentID, m_scene.RegionInfo.RegionName); | 252 | //m_log.DebugFormat("[EVENTQUEUE]: Closed client {0} in region {1}", agentID, m_scene.RegionInfo.RegionName); |
241 | |||
242 | int count = 0; | ||
243 | while (queues.ContainsKey(agentID) && queues[agentID].Count > 0 && count++ < 5) | ||
244 | { | ||
245 | Thread.Sleep(1000); | ||
246 | } | ||
247 | 253 | ||
248 | lock (queues) | 254 | lock (queues) |
249 | { | ||
250 | queues.Remove(agentID); | 255 | queues.Remove(agentID); |
251 | } | ||
252 | 256 | ||
253 | List<UUID> removeitems = new List<UUID>(); | 257 | List<UUID> removeitems = new List<UUID>(); |
254 | lock (m_AvatarQueueUUIDMapping) | 258 | lock (m_AvatarQueueUUIDMapping) |
255 | { | 259 | m_AvatarQueueUUIDMapping.Remove(agentID); |
256 | foreach (UUID ky in m_AvatarQueueUUIDMapping.Keys) | ||
257 | { | ||
258 | // m_log.DebugFormat("[EVENTQUEUE]: Found key {0} in m_AvatarQueueUUIDMapping while looking for {1}", ky, AgentID); | ||
259 | if (ky == agentID) | ||
260 | { | ||
261 | removeitems.Add(ky); | ||
262 | } | ||
263 | } | ||
264 | |||
265 | foreach (UUID ky in removeitems) | ||
266 | { | ||
267 | UUID eventQueueGetUuid = m_AvatarQueueUUIDMapping[ky]; | ||
268 | m_AvatarQueueUUIDMapping.Remove(ky); | ||
269 | |||
270 | string eqgPath = GenerateEqgCapPath(eventQueueGetUuid); | ||
271 | MainServer.Instance.RemovePollServiceHTTPHandler("", eqgPath); | ||
272 | |||
273 | // m_log.DebugFormat( | ||
274 | // "[EVENT QUEUE GET MODULE]: Removed EQG handler {0} for {1} in {2}", | ||
275 | // eqgPath, agentID, m_scene.RegionInfo.RegionName); | ||
276 | } | ||
277 | } | ||
278 | 260 | ||
279 | UUID searchval = UUID.Zero; | 261 | UUID searchval = UUID.Zero; |
280 | 262 | ||
@@ -295,19 +277,9 @@ namespace OpenSim.Region.ClientStack.Linden | |||
295 | foreach (UUID ky in removeitems) | 277 | foreach (UUID ky in removeitems) |
296 | m_QueueUUIDAvatarMapping.Remove(ky); | 278 | m_QueueUUIDAvatarMapping.Remove(ky); |
297 | } | 279 | } |
298 | } | ||
299 | 280 | ||
300 | private void MakeChildAgent(ScenePresence avatar) | 281 | // m_log.DebugFormat("[EVENTQUEUE]: Deleted queues for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName); |
301 | { | 282 | |
302 | //m_log.DebugFormat("[EVENTQUEUE]: Make Child agent {0} in region {1}.", avatar.UUID, m_scene.RegionInfo.RegionName); | ||
303 | //lock (m_ids) | ||
304 | // { | ||
305 | //if (m_ids.ContainsKey(avatar.UUID)) | ||
306 | //{ | ||
307 | // close the event queue. | ||
308 | //m_ids[avatar.UUID] = -1; | ||
309 | //} | ||
310 | //} | ||
311 | } | 283 | } |
312 | 284 | ||
313 | /// <summary> | 285 | /// <summary> |
@@ -323,9 +295,9 @@ namespace OpenSim.Region.ClientStack.Linden | |||
323 | { | 295 | { |
324 | // Register an event queue for the client | 296 | // Register an event queue for the client |
325 | 297 | ||
326 | //m_log.DebugFormat( | 298 | m_log.DebugFormat( |
327 | // "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}", | 299 | "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}", |
328 | // agentID, caps, m_scene.RegionInfo.RegionName); | 300 | agentID, caps, m_scene.RegionInfo.RegionName); |
329 | 301 | ||
330 | // Let's instantiate a Queue for this agent right now | 302 | // Let's instantiate a Queue for this agent right now |
331 | TryGetQueue(agentID); | 303 | TryGetQueue(agentID); |
@@ -359,28 +331,9 @@ namespace OpenSim.Region.ClientStack.Linden | |||
359 | m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID); | 331 | m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID); |
360 | } | 332 | } |
361 | 333 | ||
362 | string eventQueueGetPath = GenerateEqgCapPath(eventQueueGetUUID); | 334 | caps.RegisterPollHandler( |
363 | 335 | "EventQueueGet", | |
364 | // Register this as a caps handler | 336 | new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, agentID, SERVER_EQ_TIME_NO_EVENTS)); |
365 | // FIXME: Confusingly, we need to register separate as a capability so that the client is told about | ||
366 | // EventQueueGet when it receive capability information, but then we replace the rest handler immediately | ||
367 | // afterwards with the poll service. So for now, we'll pass a null instead to simplify code reading, but | ||
368 | // really it should be possible to directly register the poll handler as a capability. | ||
369 | caps.RegisterHandler("EventQueueGet", new RestHTTPHandler("POST", eventQueueGetPath, null)); | ||
370 | // delegate(Hashtable m_dhttpMethod) | ||
371 | // { | ||
372 | // return ProcessQueue(m_dhttpMethod, agentID, caps); | ||
373 | // })); | ||
374 | |||
375 | // This will persist this beyond the expiry of the caps handlers | ||
376 | // TODO: Add EventQueueGet name/description for diagnostics | ||
377 | MainServer.Instance.AddPollServiceHTTPHandler( | ||
378 | eventQueueGetPath, | ||
379 | new PollServiceEventArgs(null, HasEvents, GetEvents, NoEvents, agentID, 40000)); | ||
380 | |||
381 | // m_log.DebugFormat( | ||
382 | // "[EVENT QUEUE GET MODULE]: Registered EQG handler {0} for {1} in {2}", | ||
383 | // eventQueueGetPath, agentID, m_scene.RegionInfo.RegionName); | ||
384 | 337 | ||
385 | Random rnd = new Random(Environment.TickCount); | 338 | Random rnd = new Random(Environment.TickCount); |
386 | lock (m_ids) | 339 | lock (m_ids) |
@@ -398,7 +351,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
398 | Queue<OSD> queue = GetQueue(agentID); | 351 | Queue<OSD> queue = GetQueue(agentID); |
399 | if (queue != null) | 352 | if (queue != null) |
400 | lock (queue) | 353 | lock (queue) |
354 | { | ||
355 | //m_log.WarnFormat("POLLED FOR EVENTS BY {0} in {1} -- {2}", agentID, m_scene.RegionInfo.RegionName, queue.Count); | ||
401 | return queue.Count > 0; | 356 | return queue.Count > 0; |
357 | } | ||
402 | 358 | ||
403 | return false; | 359 | return false; |
404 | } | 360 | } |
@@ -414,16 +370,21 @@ namespace OpenSim.Region.ClientStack.Linden | |||
414 | OSDMap ev = (OSDMap)element; | 370 | OSDMap ev = (OSDMap)element; |
415 | m_log.DebugFormat( | 371 | m_log.DebugFormat( |
416 | "Eq OUT {0,-30} to {1,-20} {2,-20}", | 372 | "Eq OUT {0,-30} to {1,-20} {2,-20}", |
417 | ev["message"], m_scene.GetScenePresence(agentId).Name, m_scene.RegionInfo.RegionName); | 373 | ev["message"], m_scene.GetScenePresence(agentId).Name, m_scene.Name); |
418 | } | 374 | } |
419 | } | 375 | } |
420 | 376 | ||
421 | public Hashtable GetEvents(UUID requestID, UUID pAgentId) | 377 | public Hashtable GetEvents(UUID requestID, UUID pAgentId) |
422 | { | 378 | { |
423 | if (DebugLevel >= 2) | 379 | if (DebugLevel >= 2) |
424 | m_log.DebugFormat("POLLED FOR EQ MESSAGES BY {0} in {1}", pAgentId, m_scene.RegionInfo.RegionName); | 380 | m_log.WarnFormat("POLLED FOR EQ MESSAGES BY {0} in {1}", pAgentId, m_scene.Name); |
381 | |||
382 | Queue<OSD> queue = GetQueue(pAgentId); | ||
383 | if (queue == null) | ||
384 | { | ||
385 | return NoEvents(requestID, pAgentId); | ||
386 | } | ||
425 | 387 | ||
426 | Queue<OSD> queue = TryGetQueue(pAgentId); | ||
427 | OSD element; | 388 | OSD element; |
428 | lock (queue) | 389 | lock (queue) |
429 | { | 390 | { |
@@ -750,34 +711,46 @@ namespace OpenSim.Region.ClientStack.Linden | |||
750 | Enqueue(item, avatarID); | 711 | Enqueue(item, avatarID); |
751 | } | 712 | } |
752 | 713 | ||
753 | public virtual void EnableSimulator(ulong handle, IPEndPoint endPoint, UUID avatarID) | 714 | public virtual void EnableSimulator(ulong handle, IPEndPoint endPoint, UUID avatarID, int regionSizeX, int regionSizeY) |
754 | { | 715 | { |
755 | OSD item = EventQueueHelper.EnableSimulator(handle, endPoint); | 716 | m_log.DebugFormat("{0} EnableSimulator. handle={1}, avatarID={2}, regionSize={3},{4}>", |
717 | "[EVENT QUEUE GET MODULE]", handle, avatarID, regionSizeX, regionSizeY); | ||
718 | |||
719 | OSD item = EventQueueHelper.EnableSimulator(handle, endPoint, regionSizeX, regionSizeY); | ||
756 | Enqueue(item, avatarID); | 720 | Enqueue(item, avatarID); |
757 | } | 721 | } |
758 | 722 | ||
759 | public virtual void EstablishAgentCommunication(UUID avatarID, IPEndPoint endPoint, string capsPath) | 723 | public virtual void EstablishAgentCommunication(UUID avatarID, IPEndPoint endPoint, string capsPath, |
724 | ulong regionHandle, int regionSizeX, int regionSizeY) | ||
760 | { | 725 | { |
761 | OSD item = EventQueueHelper.EstablishAgentCommunication(avatarID, endPoint.ToString(), capsPath); | 726 | m_log.DebugFormat("{0} EstablishAgentCommunication. handle={1}, avatarID={2}, regionSize={3},{4}>", |
727 | "[EVENT QUEUE GET MODULE]", regionHandle, avatarID, regionSizeX, regionSizeY); | ||
728 | OSD item = EventQueueHelper.EstablishAgentCommunication(avatarID, endPoint.ToString(), capsPath, regionHandle, regionSizeX, regionSizeY); | ||
762 | Enqueue(item, avatarID); | 729 | Enqueue(item, avatarID); |
763 | } | 730 | } |
764 | 731 | ||
765 | public virtual void TeleportFinishEvent(ulong regionHandle, byte simAccess, | 732 | public virtual void TeleportFinishEvent(ulong regionHandle, byte simAccess, |
766 | IPEndPoint regionExternalEndPoint, | 733 | IPEndPoint regionExternalEndPoint, |
767 | uint locationID, uint flags, string capsURL, | 734 | uint locationID, uint flags, string capsURL, |
768 | UUID avatarID) | 735 | UUID avatarID, int regionSizeX, int regionSizeY) |
769 | { | 736 | { |
737 | m_log.DebugFormat("{0} TeleportFinishEvent. handle={1}, avatarID={2}, regionSize={3},{4}>", | ||
738 | "[EVENT QUEUE GET MODULE]", regionHandle, avatarID, regionSizeX, regionSizeY); | ||
739 | |||
770 | OSD item = EventQueueHelper.TeleportFinishEvent(regionHandle, simAccess, regionExternalEndPoint, | 740 | OSD item = EventQueueHelper.TeleportFinishEvent(regionHandle, simAccess, regionExternalEndPoint, |
771 | locationID, flags, capsURL, avatarID); | 741 | locationID, flags, capsURL, avatarID, regionSizeX, regionSizeY); |
772 | Enqueue(item, avatarID); | 742 | Enqueue(item, avatarID); |
773 | } | 743 | } |
774 | 744 | ||
775 | public virtual void CrossRegion(ulong handle, Vector3 pos, Vector3 lookAt, | 745 | public virtual void CrossRegion(ulong handle, Vector3 pos, Vector3 lookAt, |
776 | IPEndPoint newRegionExternalEndPoint, | 746 | IPEndPoint newRegionExternalEndPoint, |
777 | string capsURL, UUID avatarID, UUID sessionID) | 747 | string capsURL, UUID avatarID, UUID sessionID, int regionSizeX, int regionSizeY) |
778 | { | 748 | { |
749 | m_log.DebugFormat("{0} CrossRegion. handle={1}, avatarID={2}, regionSize={3},{4}>", | ||
750 | "[EVENT QUEUE GET MODULE]", handle, avatarID, regionSizeX, regionSizeY); | ||
751 | |||
779 | OSD item = EventQueueHelper.CrossRegion(handle, pos, lookAt, newRegionExternalEndPoint, | 752 | OSD item = EventQueueHelper.CrossRegion(handle, pos, lookAt, newRegionExternalEndPoint, |
780 | capsURL, avatarID, sessionID); | 753 | capsURL, avatarID, sessionID, regionSizeX, regionSizeY); |
781 | Enqueue(item, avatarID); | 754 | Enqueue(item, avatarID); |
782 | } | 755 | } |
783 | 756 | ||
@@ -794,12 +767,12 @@ namespace OpenSim.Region.ClientStack.Linden | |||
794 | 767 | ||
795 | } | 768 | } |
796 | 769 | ||
797 | public void ChatterBoxSessionAgentListUpdates(UUID sessionID, UUID fromAgent, UUID toAgent, bool canVoiceChat, | 770 | public void ChatterBoxSessionAgentListUpdates(UUID sessionID, UUID fromAgent, UUID anotherAgent, bool canVoiceChat, |
798 | bool isModerator, bool textMute) | 771 | bool isModerator, bool textMute) |
799 | { | 772 | { |
800 | OSD item = EventQueueHelper.ChatterBoxSessionAgentListUpdates(sessionID, fromAgent, canVoiceChat, | 773 | OSD item = EventQueueHelper.ChatterBoxSessionAgentListUpdates(sessionID, fromAgent, canVoiceChat, |
801 | isModerator, textMute); | 774 | isModerator, textMute); |
802 | Enqueue(item, toAgent); | 775 | Enqueue(item, fromAgent); |
803 | //m_log.InfoFormat("########### eq ChatterBoxSessionAgentListUpdates #############\n{0}", item); | 776 | //m_log.InfoFormat("########### eq ChatterBoxSessionAgentListUpdates #############\n{0}", item); |
804 | } | 777 | } |
805 | 778 | ||