aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs20
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs145
2 files changed, 43 insertions, 122 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
index e0a11cc..87d3d1c 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs
@@ -25,16 +25,20 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using Mono.Addins; 28using System;
29using System.Collections;
30using System.Reflection;
31using log4net;
29using Nini.Config; 32using Nini.Config;
33using Mono.Addins;
30using OpenMetaverse; 34using OpenMetaverse;
31using OpenSim.Capabilities.Handlers; 35using OpenSim.Framework;
32using OpenSim.Framework.Servers.HttpServer; 36using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Region.Framework.Interfaces; 37using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 38using OpenSim.Region.Framework.Scenes;
35using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
36using System;
37using Caps = OpenSim.Framework.Capabilities.Caps; 40using Caps = OpenSim.Framework.Capabilities.Caps;
41using OpenSim.Capabilities.Handlers;
38 42
39namespace OpenSim.Region.ClientStack.Linden 43namespace OpenSim.Region.ClientStack.Linden
40{ 44{
@@ -54,6 +58,8 @@ namespace OpenSim.Region.ClientStack.Linden
54 58
55 private string m_fetchInventory2Url; 59 private string m_fetchInventory2Url;
56 60
61 private FetchInventory2Handler m_fetchHandler;
62
57 #region ISharedRegionModule Members 63 #region ISharedRegionModule Members
58 64
59 public void Initialise(IConfigSource source) 65 public void Initialise(IConfigSource source)
@@ -92,6 +98,10 @@ namespace OpenSim.Region.ClientStack.Linden
92 98
93 m_inventoryService = m_scene.InventoryService; 99 m_inventoryService = m_scene.InventoryService;
94 100
101 // We'll reuse the same handler for all requests.
102 if (m_fetchInventory2Url == "localhost")
103 m_fetchHandler = new FetchInventory2Handler(m_inventoryService);
104
95 m_scene.EventManager.OnRegisterCaps += RegisterCaps; 105 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
96 } 106 }
97 107
@@ -121,11 +131,9 @@ namespace OpenSim.Region.ClientStack.Linden
121 { 131 {
122 capUrl = "/CAPS/" + UUID.Random(); 132 capUrl = "/CAPS/" + UUID.Random();
123 133
124 FetchInventory2Handler fetchHandler = new FetchInventory2Handler(m_inventoryService, agentID);
125
126 IRequestHandler reqHandler 134 IRequestHandler reqHandler
127 = new RestStreamHandler( 135 = new RestStreamHandler(
128 "POST", capUrl, fetchHandler.FetchInventoryRequest, capName, agentID.ToString()); 136 "POST", capUrl, m_fetchHandler.FetchInventoryRequest, capName, agentID.ToString());
129 137
130 caps.RegisterHandler(capName, reqHandler); 138 caps.RegisterHandler(capName, reqHandler);
131 } 139 }
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
index 2a252e1..5f3e66a 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
@@ -66,26 +66,7 @@ namespace OpenSim.Region.ClientStack.Linden
66 66
67 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 67 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
68 68
69 /// <summary> 69 private Scene m_scene;
70 /// Control whether requests will be processed asynchronously.
71 /// </summary>
72 /// <remarks>
73 /// Defaults to true. Can currently not be changed once a region has been added to the module.
74 /// </remarks>
75 public bool ProcessQueuedRequestsAsync { get; private set; }
76
77 /// <summary>
78 /// Number of inventory requests processed by this module.
79 /// </summary>
80 /// <remarks>
81 /// It's the PollServiceRequestManager that actually sends completed requests back to the requester.
82 /// </remarks>
83 public static int ProcessedRequestsCount { get; set; }
84
85 private static Stat s_queuedRequestsStat;
86 private static Stat s_processedRequestsStat;
87
88 public Scene Scene { get; private set; }
89 70
90 private IInventoryService m_InventoryService; 71 private IInventoryService m_InventoryService;
91 private ILibraryService m_LibraryService; 72 private ILibraryService m_LibraryService;
@@ -95,7 +76,7 @@ namespace OpenSim.Region.ClientStack.Linden
95 private string m_fetchInventoryDescendents2Url; 76 private string m_fetchInventoryDescendents2Url;
96 private string m_webFetchInventoryDescendentsUrl; 77 private string m_webFetchInventoryDescendentsUrl;
97 78
98 private static FetchInvDescHandler m_webFetchHandler; 79 private static WebFetchInvDescHandler m_webFetchHandler;
99 80
100 private static Thread[] m_workerThreads = null; 81 private static Thread[] m_workerThreads = null;
101 82
@@ -104,13 +85,6 @@ namespace OpenSim.Region.ClientStack.Linden
104 85
105 #region ISharedRegionModule Members 86 #region ISharedRegionModule Members
106 87
107 public WebFetchInvDescModule() : this(true) {}
108
109 public WebFetchInvDescModule(bool processQueuedResultsAsync)
110 {
111 ProcessQueuedRequestsAsync = processQueuedResultsAsync;
112 }
113
114 public void Initialise(IConfigSource source) 88 public void Initialise(IConfigSource source)
115 { 89 {
116 IConfig config = source.Configs["ClientStack.LindenCaps"]; 90 IConfig config = source.Configs["ClientStack.LindenCaps"];
@@ -118,9 +92,8 @@ namespace OpenSim.Region.ClientStack.Linden
118 return; 92 return;
119 93
120 m_fetchInventoryDescendents2Url = config.GetString("Cap_FetchInventoryDescendents2", string.Empty); 94 m_fetchInventoryDescendents2Url = config.GetString("Cap_FetchInventoryDescendents2", string.Empty);
121// m_webFetchInventoryDescendentsUrl = config.GetString("Cap_WebFetchInventoryDescendents", string.Empty); 95 m_webFetchInventoryDescendentsUrl = config.GetString("Cap_WebFetchInventoryDescendents", string.Empty);
122 96
123// if (m_fetchInventoryDescendents2Url != string.Empty || m_webFetchInventoryDescendentsUrl != string.Empty)
124 if (m_fetchInventoryDescendents2Url != string.Empty || m_webFetchInventoryDescendentsUrl != string.Empty) 97 if (m_fetchInventoryDescendents2Url != string.Empty || m_webFetchInventoryDescendentsUrl != string.Empty)
125 { 98 {
126 m_Enabled = true; 99 m_Enabled = true;
@@ -132,7 +105,7 @@ namespace OpenSim.Region.ClientStack.Linden
132 if (!m_Enabled) 105 if (!m_Enabled)
133 return; 106 return;
134 107
135 Scene = s; 108 m_scene = s;
136 } 109 }
137 110
138 public void RemoveRegion(Scene s) 111 public void RemoveRegion(Scene s)
@@ -140,23 +113,12 @@ namespace OpenSim.Region.ClientStack.Linden
140 if (!m_Enabled) 113 if (!m_Enabled)
141 return; 114 return;
142 115
143 Scene.EventManager.OnRegisterCaps -= RegisterCaps; 116 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
144 117
145 StatsManager.DeregisterStat(s_processedRequestsStat); 118 foreach (Thread t in m_workerThreads)
146 StatsManager.DeregisterStat(s_queuedRequestsStat); 119 Watchdog.AbortThread(t.ManagedThreadId);
147
148 if (ProcessQueuedRequestsAsync)
149 {
150 if (m_workerThreads != null)
151 {
152 foreach (Thread t in m_workerThreads)
153 Watchdog.AbortThread(t.ManagedThreadId);
154 120
155 m_workerThreads = null; 121 m_scene = null;
156 }
157 }
158
159 Scene = null;
160 } 122 }
161 123
162 public void RegionLoaded(Scene s) 124 public void RegionLoaded(Scene s)
@@ -164,51 +126,19 @@ namespace OpenSim.Region.ClientStack.Linden
164 if (!m_Enabled) 126 if (!m_Enabled)
165 return; 127 return;
166 128
167 if (s_processedRequestsStat == null) 129 m_InventoryService = m_scene.InventoryService;
168 s_processedRequestsStat = 130 m_LibraryService = m_scene.LibraryService;
169 new Stat(
170 "ProcessedFetchInventoryRequests",
171 "Number of processed fetch inventory requests",
172 "These have not necessarily yet been dispatched back to the requester.",
173 "",
174 "inventory",
175 "httpfetch",
176 StatType.Pull,
177 MeasuresOfInterest.AverageChangeOverTime,
178 stat => { stat.Value = ProcessedRequestsCount; },
179 StatVerbosity.Debug);
180
181 if (s_queuedRequestsStat == null)
182 s_queuedRequestsStat =
183 new Stat(
184 "QueuedFetchInventoryRequests",
185 "Number of fetch inventory requests queued for processing",
186 "",
187 "",
188 "inventory",
189 "httpfetch",
190 StatType.Pull,
191 MeasuresOfInterest.AverageChangeOverTime,
192 stat => { stat.Value = m_queue.Count; },
193 StatVerbosity.Debug);
194
195 StatsManager.RegisterStat(s_processedRequestsStat);
196 StatsManager.RegisterStat(s_queuedRequestsStat);
197
198 m_InventoryService = Scene.InventoryService;
199 m_LibraryService = Scene.LibraryService;
200 131
201 // We'll reuse the same handler for all requests. 132 // We'll reuse the same handler for all requests.
202 m_webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, Scene); 133 m_webFetchHandler = new WebFetchInvDescHandler(m_InventoryService, m_LibraryService);
203 134
204 Scene.EventManager.OnRegisterCaps += RegisterCaps; 135 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
205 136
206 int nworkers = 2; // was 2 137 if (m_workerThreads == null)
207 if (ProcessQueuedRequestsAsync && m_workerThreads == null)
208 { 138 {
209 m_workerThreads = new Thread[nworkers]; 139 m_workerThreads = new Thread[2];
210 140
211 for (uint i = 0; i < nworkers; i++) 141 for (uint i = 0; i < 2; i++)
212 { 142 {
213 m_workerThreads[i] = WorkManager.StartThread(DoInventoryRequests, 143 m_workerThreads[i] = WorkManager.StartThread(DoInventoryRequests,
214 String.Format("InventoryWorkerThread{0}", i), 144 String.Format("InventoryWorkerThread{0}", i),
@@ -243,12 +173,12 @@ namespace OpenSim.Region.ClientStack.Linden
243 private Dictionary<UUID, Hashtable> responses = 173 private Dictionary<UUID, Hashtable> responses =
244 new Dictionary<UUID, Hashtable>(); 174 new Dictionary<UUID, Hashtable>();
245 175
246 private WebFetchInvDescModule m_module; 176 private Scene m_scene;
247 177
248 public PollServiceInventoryEventArgs(WebFetchInvDescModule module, string url, UUID pId) : 178 public PollServiceInventoryEventArgs(Scene scene, string url, UUID pId) :
249 base(null, url, null, null, null, pId, int.MaxValue) 179 base(null, url, null, null, null, pId, int.MaxValue)
250 { 180 {
251 m_module = module; 181 m_scene = scene;
252 182
253 HasEvents = (x, y) => { lock (responses) return responses.ContainsKey(x); }; 183 HasEvents = (x, y) => { lock (responses) return responses.ContainsKey(x); };
254 GetEvents = (x, y) => 184 GetEvents = (x, y) =>
@@ -268,7 +198,12 @@ namespace OpenSim.Region.ClientStack.Linden
268 198
269 Request = (x, y) => 199 Request = (x, y) =>
270 { 200 {
271 ScenePresence sp = m_module.Scene.GetScenePresence(Id); 201 ScenePresence sp = m_scene.GetScenePresence(Id);
202 if (sp == null)
203 {
204 m_log.ErrorFormat("[INVENTORY]: Unable to find ScenePresence for {0}", Id);
205 return;
206 }
272 207
273 aPollRequest reqinfo = new aPollRequest(); 208 aPollRequest reqinfo = new aPollRequest();
274 reqinfo.thepoll = this; 209 reqinfo.thepoll = this;
@@ -363,13 +298,7 @@ namespace OpenSim.Region.ClientStack.Linden
363 requestinfo.request["body"].ToString(), String.Empty, String.Empty, null, null); 298 requestinfo.request["body"].ToString(), String.Empty, String.Empty, null, null);
364 299
365 lock (responses) 300 lock (responses)
366 {
367 if (responses.ContainsKey(requestID))
368 m_log.WarnFormat("[FETCH INVENTORY DESCENDENTS2 MODULE]: Caught in the act of loosing responses! Please report this on mantis #7054");
369 responses[requestID] = response; 301 responses[requestID] = response;
370 }
371
372 WebFetchInvDescModule.ProcessedRequestsCount++;
373 } 302 }
374 } 303 }
375 304
@@ -393,7 +322,7 @@ namespace OpenSim.Region.ClientStack.Linden
393 capUrl = "/CAPS/" + UUID.Random() + "/"; 322 capUrl = "/CAPS/" + UUID.Random() + "/";
394 323
395 // Register this as a poll service 324 // Register this as a poll service
396 PollServiceInventoryEventArgs args = new PollServiceInventoryEventArgs(this, capUrl, agentID); 325 PollServiceInventoryEventArgs args = new PollServiceInventoryEventArgs(m_scene, capUrl, agentID);
397 args.Type = PollServiceEventArgs.EventType.Inventory; 326 args.Type = PollServiceEventArgs.EventType.Inventory;
398 327
399 caps.RegisterPollHandler(capName, args); 328 caps.RegisterPollHandler(capName, args);
@@ -402,7 +331,7 @@ namespace OpenSim.Region.ClientStack.Linden
402 else 331 else
403 { 332 {
404 capUrl = url; 333 capUrl = url;
405 IExternalCapsModule handler = Scene.RequestModuleInterface<IExternalCapsModule>(); 334 IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>();
406 if (handler != null) 335 if (handler != null)
407 handler.RegisterExternalUserCapsHandler(agentID,caps,capName,capUrl); 336 handler.RegisterExternalUserCapsHandler(agentID,caps,capName,capUrl);
408 else 337 else
@@ -431,26 +360,10 @@ namespace OpenSim.Region.ClientStack.Linden
431 { 360 {
432 Watchdog.UpdateThread(); 361 Watchdog.UpdateThread();
433 362
434 WaitProcessQueuedInventoryRequest(); 363 aPollRequest poolreq = m_queue.Dequeue();
435 }
436 }
437
438 public void WaitProcessQueuedInventoryRequest()
439 {
440 aPollRequest poolreq = m_queue.Dequeue();
441 364
442 if (poolreq != null && poolreq.thepoll != null) 365 if (poolreq != null && poolreq.thepoll != null)
443 {
444 try
445 {
446 poolreq.thepoll.Process(poolreq); 366 poolreq.thepoll.Process(poolreq);
447 }
448 catch (Exception e)
449 {
450 m_log.ErrorFormat(
451 "[INVENTORY]: Failed to process queued inventory request {0} for {1} in {2}. Exception {3}",
452 poolreq.reqID, poolreq.presence != null ? poolreq.presence.Name : "unknown", Scene.Name, e);
453 }
454 } 367 }
455 } 368 }
456 } 369 }