aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorHomer Horwitz2008-09-27 18:33:54 +0000
committerHomer Horwitz2008-09-27 18:33:54 +0000
commit0e10c8561790517a66a095d467fc65a0d2071461 (patch)
tree09b78bb43e554ebcc67ad3c7526e32eecbad8cb8 /OpenSim/Region
parent- adding Dequeue with a timeout to the BlockingQueue (diff)
downloadopensim-SC_OLD-0e10c8561790517a66a095d467fc65a0d2071461.zip
opensim-SC_OLD-0e10c8561790517a66a095d467fc65a0d2071461.tar.gz
opensim-SC_OLD-0e10c8561790517a66a095d467fc65a0d2071461.tar.bz2
opensim-SC_OLD-0e10c8561790517a66a095d467fc65a0d2071461.tar.xz
Continue working on the new EventQueueGetModule. Not finished (or even working)
yet. This shouldn't break anything, but is work in progress, so be careful. Contains a new file; do your runprebuilds.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs131
-rw-r--r--OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs59
-rw-r--r--OpenSim/Region/Interfaces/IEventQueue.cs3
3 files changed, 164 insertions, 29 deletions
diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs
index ea6c663..d60e15a 100644
--- a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs
+++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs
@@ -1,3 +1,29 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
1using System; 27using System;
2using System.Collections; 28using System.Collections;
3using System.Collections.Generic; 29using System.Collections.Generic;
@@ -22,15 +48,18 @@ using LLSD = OpenMetaverse.StructuredData.LLSD;
22using LLSDMap = OpenMetaverse.StructuredData.LLSDMap; 48using LLSDMap = OpenMetaverse.StructuredData.LLSDMap;
23using LLSDArray = OpenMetaverse.StructuredData.LLSDArray; 49using LLSDArray = OpenMetaverse.StructuredData.LLSDArray;
24using Caps = OpenSim.Framework.Communications.Capabilities.Caps; 50using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
51using BlockingLLSDQueue = OpenSim.Framework.BlockingQueue<OpenMetaverse.StructuredData.LLSD>;
25 52
26namespace OpenSim.Region.Environment.Modules.Framework 53namespace OpenSim.Region.Environment.Modules.Framework
27{ 54{
28 public class EventQueueGetModule : IEventQueue, IRegionModule 55 public class EventQueueGetModule : IEventQueue, IRegionModule
29 { 56 {
30 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
31 Scene m_scene = null; 58 private Scene m_scene = null;
32 IConfigSource m_gConfig; 59 private IConfigSource m_gConfig;
33 60
61 private Dictionary<UUID, BlockingLLSDQueue> queues = new Dictionary<UUID, BlockingLLSDQueue>();
62
34 #region IRegionModule methods 63 #region IRegionModule methods
35 public void Initialise(Scene scene, IConfigSource config) 64 public void Initialise(Scene scene, IConfigSource config)
36 { 65 {
@@ -48,20 +77,14 @@ namespace OpenSim.Region.Environment.Modules.Framework
48 scene.EventManager.OnClientClosed += ClientClosed; 77 scene.EventManager.OnClientClosed += ClientClosed;
49 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; 78 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
50 scene.EventManager.OnMakeChildAgent += MakeChildAgent; 79 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
51 scene.EventManager.OnClientClosed += ClientLoggedOut;
52 scene.EventManager.OnRegisterCaps += OnRegisterCaps; 80 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
53 81
54 } 82 }
55 83
56 private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string p) 84 private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string p)
57 { 85 {
58
59 } 86 }
60 87
61
62
63
64
65 public void PostInitialise() 88 public void PostInitialise()
66 { 89 {
67 } 90 }
@@ -81,43 +104,56 @@ namespace OpenSim.Region.Environment.Modules.Framework
81 } 104 }
82 #endregion 105 #endregion
83 106
84 #region IEventQueue Members 107 private BlockingLLSDQueue GetQueue(UUID agentId)
85 public bool Enqueue(object o, UUID avatarID)
86 { 108 {
109 if (!queues.ContainsKey(agentId))
110 {
111 m_log.DebugFormat("[EVENTQUEUE]: Adding new queue for agent {0}", agentId);
112 queues[agentId] = new BlockingLLSDQueue();
113 }
114 return queues[agentId];
115 }
87 116
88 return false; 117
118 #region IEventQueue Members
119 public bool Enqueue(LLSD ev, UUID avatarID)
120 {
121 m_log.DebugFormat("[EVENTQUEUE]: Enqueuing event for {0}", avatarID);
122 BlockingLLSDQueue queue = GetQueue(avatarID);
123 queue.Enqueue(ev);
124 return true;
89 } 125 }
90 #endregion 126 #endregion
91 127
92 private void OnNewClient(IClientAPI client) 128 private void OnNewClient(IClientAPI client)
93 { 129 {
94 130 m_log.DebugFormat("[EVENTQUEUE]: New client {0} detected.", client.AgentId);
95 client.OnLogout += ClientClosed; 131 client.OnLogout += ClientClosed;
96 } 132 }
97 133
98 134
99 public void ClientClosed(IClientAPI client) 135 private void ClientClosed(IClientAPI client)
100 { 136 {
101 ClientClosed(client.AgentId); 137 ClientClosed(client.AgentId);
102 } 138 }
103 139
104 private void ClientLoggedOut(UUID AgentId) 140 private void ClientClosed(UUID AgentID)
105 { 141 {
106 142 queues.Remove(AgentID);
143 m_log.DebugFormat("[EVENTQUEUE]: Client {0} deregistered.", AgentID);
107 } 144 }
108 145
109 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID) 146 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
110 { 147 {
111 148 m_log.DebugFormat("[EVENTQUEUE]: Avatar {0} entering parcel {1} in region {2}.",
149 avatar.UUID, localLandID, regionID);
112 } 150 }
113 151
114 public void ClientClosed(UUID AgentID)
115 {
116
117 }
118 private void MakeChildAgent(ScenePresence avatar) 152 private void MakeChildAgent(ScenePresence avatar)
119 { 153 {
154 m_log.DebugFormat("[EVENTQUEUE]: Make Child agent {0}.", avatar.UUID);
120 } 155 }
156
121 public void OnRegisterCaps(UUID agentID, Caps caps) 157 public void OnRegisterCaps(UUID agentID, Caps caps)
122 { 158 {
123 m_log.DebugFormat("[EVENTQUEUE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 159 m_log.DebugFormat("[EVENTQUEUE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
@@ -129,14 +165,54 @@ namespace OpenSim.Region.Environment.Modules.Framework
129 return ProcessQueue(m_dhttpMethod,agentID, caps); 165 return ProcessQueue(m_dhttpMethod,agentID, caps);
130 })); 166 }));
131 } 167 }
168
132 public Hashtable ProcessQueue(Hashtable request,UUID agentID, Caps caps) 169 public Hashtable ProcessQueue(Hashtable request,UUID agentID, Caps caps)
133 { 170 {
134 171 // TODO: this has to be redone to not busy-wait (and block the thread),
135 Hashtable responsedata = new Hashtable(); 172 // TODO: as soon as we have a non-blocking way to handle HTTP-requests.
136 responsedata["int_response_code"] = 502; 173 BlockingLLSDQueue queue = GetQueue(agentID);
137 responsedata["str_response_string"] = "Upstream error:"; 174 LLSD element = queue.Dequeue(15000); // 15s timeout
138 responsedata["content_type"] = "text/plain"; 175
139 responsedata["keepalive"] = true; 176 String debug = "[EVENTQUEUE]: Got request for agent {0}: [ ";
177 foreach(object key in request.Keys)
178 {
179 debug += key.ToString() + "=" + request[key].ToString() + " ";
180 }
181 m_log.DebugFormat(debug, agentID);
182
183 if (element == null) // didn't have an event in 15s
184 {
185 Hashtable responsedata = new Hashtable();
186 responsedata["int_response_code"] = 502;
187 responsedata["str_response_string"] = "Upstream error:";
188 responsedata["content_type"] = "text/plain";
189 responsedata["keepalive"] = true;
190 return responsedata;
191 }
192 else
193 {
194 ScenePresence avatar;
195 m_scene.TryGetAvatar(agentID, out avatar);
196
197 LLSDArray array = new LLSDArray();
198 array.Add(element);
199 while (queue.Count() > 0)
200 {
201 array.Add(queue.Dequeue(1));
202 }
203 LLSDMap events = new LLSDMap();
204 events.Add("events", array);
205 events.Add("id", new LLSDInteger(1)); // TODO: this seems to be a event sequence-numeber to be ack'd by the client?
206
207 Hashtable responsedata = new Hashtable();
208 responsedata["int_response_code"] = 200;
209 responsedata["content_type"] = "application/llsd+xml";
210 responsedata["keepalive"] = true;
211 responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events);
212 m_log.DebugFormat("[EVENTQUEUE]: sending response for {0}: {1}", agentID, responsedata["str_response_string"]);
213
214 return responsedata;
215 }
140 216
141 /* 217 /*
142 responsedata["int_response_code"] = 200; 218 responsedata["int_response_code"] = 200;
@@ -157,7 +233,6 @@ namespace OpenSim.Region.Environment.Modules.Framework
157 //string requestbody = (string)request["requestbody"]; 233 //string requestbody = (string)request["requestbody"];
158 //LLSD llsdRequest = LLSDParser.DeserializeXml(request); 234 //LLSD llsdRequest = LLSDParser.DeserializeXml(request);
159 //System.Console.WriteLine(requestbody); 235 //System.Console.WriteLine(requestbody);
160 return responsedata;
161 236
162 } 237 }
163 } 238 }
diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs
new file mode 100644
index 0000000..7241cb3
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs
@@ -0,0 +1,59 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Net;
30
31using OpenMetaverse.StructuredData;
32
33namespace OpenSim.Region.Environment
34{
35 public class EventQueueHelper
36 {
37 private EventQueueHelper() {} // no construction possible, it's an utility class
38
39 public static LLSD EnableSimulator(ulong regionHandle, IPEndPoint endPoint)
40 {
41 LLSDMap llsdSimInfo = new LLSDMap(3);
42 llsdSimInfo.Add("Handle", new LLSDBinary(regionHandle));
43 llsdSimInfo.Add("IP", new LLSDBinary(endPoint.Address.GetAddressBytes()));
44 llsdSimInfo.Add("Port", new LLSDInteger(endPoint.Port));
45
46 LLSDArray arr = new LLSDArray(1);
47 arr.Add(llsdSimInfo);
48
49 LLSDMap llsdBody = new LLSDMap(1);
50 llsdBody.Add("SimulatorInfo", arr);
51
52 LLSDMap llsdMessage = new LLSDMap(2);
53 llsdMessage.Add("message", new LLSDString("EnableSimulator"));
54 llsdMessage.Add("body", llsdBody);
55
56 return llsdMessage;
57 }
58 }
59}
diff --git a/OpenSim/Region/Interfaces/IEventQueue.cs b/OpenSim/Region/Interfaces/IEventQueue.cs
index a11eebe..42fdcae 100644
--- a/OpenSim/Region/Interfaces/IEventQueue.cs
+++ b/OpenSim/Region/Interfaces/IEventQueue.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using OpenSim.Framework; 29using OpenSim.Framework;
30using OpenMetaverse; 30using OpenMetaverse;
31using OpenMetaverse.StructuredData;
31using System.Collections.Generic; 32using System.Collections.Generic;
32using System.Text; 33using System.Text;
33 34
@@ -35,6 +36,6 @@ namespace OpenSim.Region.Interfaces
35{ 36{
36 public interface IEventQueue 37 public interface IEventQueue
37 { 38 {
38 bool Enqueue(object o, UUID avatarID); 39 bool Enqueue(LLSD o, UUID avatarID);
39 } 40 }
40} 41}