From 98632ee594670625fbebc0faa49795fdccb9218a Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 27 Sep 2008 22:05:36 +0000 Subject: * Event queue is now polling.. * returns FAKEEVENT instead of the connection returning a 502. It doesn't like our 502's for some reason.. so, in leau of this.. send it a fake event. * Once again, this is still 'really early' code, so please don't blame us if you have no more threads left. --- .../Modules/Framework/EventQueueGetModule.cs | 65 +++++++++++++++++++--- .../Modules/Framework/EventQueueHelper.cs | 9 +++ 2 files changed, 67 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/Environment/Modules') diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs index d60e15a..ebaa406 100644 --- a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs +++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs @@ -52,11 +52,19 @@ using BlockingLLSDQueue = OpenSim.Framework.BlockingQueue m_ids = new Dictionary(); private Dictionary queues = new Dictionary(); @@ -83,6 +91,7 @@ namespace OpenSim.Region.Environment.Modules.Framework private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string p) { + } public void PostInitialise() @@ -147,6 +156,7 @@ namespace OpenSim.Region.Environment.Modules.Framework { m_log.DebugFormat("[EVENTQUEUE]: Avatar {0} entering parcel {1} in region {2}.", avatar.UUID, localLandID, regionID); + } private void MakeChildAgent(ScenePresence avatar) @@ -164,29 +174,64 @@ namespace OpenSim.Region.Environment.Modules.Framework { return ProcessQueue(m_dhttpMethod,agentID, caps); })); + Random rnd = new Random(System.Environment.TickCount); + lock (m_ids) + { + if (!m_ids.ContainsKey(agentID)) + m_ids.Add(agentID, rnd.Next(30000000)); + } + + + } public Hashtable ProcessQueue(Hashtable request,UUID agentID, Caps caps) { // TODO: this has to be redone to not busy-wait (and block the thread), // TODO: as soon as we have a non-blocking way to handle HTTP-requests. + BlockingLLSDQueue queue = GetQueue(agentID); LLSD element = queue.Dequeue(15000); // 15s timeout + String debug = "[EVENTQUEUE]: Got request for agent {0}: [ "; foreach(object key in request.Keys) { debug += key.ToString() + "=" + request[key].ToString() + " "; } - m_log.DebugFormat(debug, agentID); - + //m_log.DebugFormat(debug, agentID); + if (element == null) // didn't have an event in 15s { + // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say! + element = EventQueueHelper.KeepAliveEvent(); + + ScenePresence avatar; + m_scene.TryGetAvatar(agentID, out avatar); + + LLSDArray array = new LLSDArray(); + array.Add(element); + int thisID = m_ids[agentID]; + while (queue.Count() > 0) + { + array.Add(queue.Dequeue(1)); + thisID++; + } + LLSDMap events = new LLSDMap(); + events.Add("events", array); + + events.Add("id", new LLSDInteger(thisID)); + lock (m_ids) + { + m_ids[agentID] = thisID + 1; + } Hashtable responsedata = new Hashtable(); - responsedata["int_response_code"] = 502; - responsedata["str_response_string"] = "Upstream error:"; - responsedata["content_type"] = "text/plain"; + responsedata["int_response_code"] = 200; + responsedata["content_type"] = "application/llsd+xml"; responsedata["keepalive"] = true; + responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events); + //m_log.DebugFormat("[EVENTQUEUE]: sending fake response for {0}: {1}", agentID, responsedata["str_response_string"]); + return responsedata; } else @@ -196,14 +241,20 @@ namespace OpenSim.Region.Environment.Modules.Framework LLSDArray array = new LLSDArray(); array.Add(element); + int thisID = m_ids[agentID]; while (queue.Count() > 0) { array.Add(queue.Dequeue(1)); + thisID++; } LLSDMap events = new LLSDMap(); events.Add("events", array); - events.Add("id", new LLSDInteger(1)); // TODO: this seems to be a event sequence-numeber to be ack'd by the client? - + + events.Add("id", new LLSDInteger(thisID)); + lock (m_ids) + { + m_ids[agentID] = thisID + 1; + } Hashtable responsedata = new Hashtable(); responsedata["int_response_code"] = 200; responsedata["content_type"] = "application/llsd+xml"; diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs index 7241cb3..46f7a3f 100644 --- a/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs +++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs @@ -54,6 +54,15 @@ namespace OpenSim.Region.Environment llsdMessage.Add("body", llsdBody); return llsdMessage; + } + public static LLSD KeepAliveEvent() + { + LLSDMap llsdSimInfo = new LLSDMap(); + LLSDMap llsdMessage = new LLSDMap(2); + llsdMessage.Add("message", new LLSDString("FAKEEVENT")); + llsdMessage.Add("body", llsdSimInfo); + + return llsdMessage; } } } -- cgit v1.1