aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs370
1 files changed, 320 insertions, 50 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
index fff86d5..3d5ed4f 100644
--- a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Linq;
31using System.Reflection; 32using System.Reflection;
32using System.Text; 33using System.Text;
33using log4net; 34using log4net;
@@ -37,6 +38,7 @@ using OpenMetaverse;
37using OpenSim.Framework; 38using OpenSim.Framework;
38using OpenSim.Framework.Console; 39using OpenSim.Framework.Console;
39using OpenSim.Framework.Servers; 40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Servers.HttpServer;
40using OpenSim.Region.Framework.Interfaces; 42using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes; 43using OpenSim.Region.Framework.Scenes;
42using Caps=OpenSim.Framework.Capabilities.Caps; 44using Caps=OpenSim.Framework.Capabilities.Caps;
@@ -57,8 +59,9 @@ namespace OpenSim.Region.CoreModules.Framework
57 /// </summary> 59 /// </summary>
58 protected Dictionary<uint, Caps> m_capsObjects = new Dictionary<uint, Caps>(); 60 protected Dictionary<uint, Caps> m_capsObjects = new Dictionary<uint, Caps>();
59 61
60 protected Dictionary<UUID, string> capsPaths = new Dictionary<UUID, string>(); 62 protected Dictionary<UUID, string> m_capsPaths = new Dictionary<UUID, string>();
61 protected Dictionary<UUID, Dictionary<ulong, string>> childrenSeeds 63
64 protected Dictionary<UUID, Dictionary<ulong, string>> m_childrenSeeds
62 = new Dictionary<UUID, Dictionary<ulong, string>>(); 65 = new Dictionary<UUID, Dictionary<ulong, string>>();
63 66
64 public void Initialise(IConfigSource source) 67 public void Initialise(IConfigSource source)
@@ -70,9 +73,24 @@ namespace OpenSim.Region.CoreModules.Framework
70 m_scene = scene; 73 m_scene = scene;
71 m_scene.RegisterModuleInterface<ICapabilitiesModule>(this); 74 m_scene.RegisterModuleInterface<ICapabilitiesModule>(this);
72 75
73 MainConsole.Instance.Commands.AddCommand("Comms", false, "show caps", 76 MainConsole.Instance.Commands.AddCommand(
74 "show caps", 77 "Comms", false, "show caps list",
75 "Shows all registered capabilities for users", HandleShowCapsCommand); 78 "show caps list",
79 "Shows list of registered capabilities for users.", HandleShowCapsListCommand);
80
81 MainConsole.Instance.Commands.AddCommand(
82 "Comms", false, "show caps stats by user",
83 "show caps stats [<first-name> <last-name>]",
84 "Shows statistics on capabilities use by user.",
85 "If a user name is given, then prints a detailed breakdown of caps use ordered by number of requests received.",
86 HandleShowCapsStatsByUserCommand);
87
88 MainConsole.Instance.Commands.AddCommand(
89 "Comms", false, "show caps stats by cap",
90 "show caps stats by cap [<cap-name>]",
91 "Shows statistics on capabilities use by capability.",
92 "If a capability name is given, then prints a detailed breakdown of use by each user.",
93 HandleShowCapsStatsByCapCommand);
76 } 94 }
77 95
78 public void RegionLoaded(Scene scene) 96 public void RegionLoaded(Scene scene)
@@ -106,35 +124,42 @@ namespace OpenSim.Region.CoreModules.Framework
106 if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId, flags)) 124 if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId, flags))
107 return; 125 return;
108 126
127 Caps caps;
109 String capsObjectPath = GetCapsPath(agentId); 128 String capsObjectPath = GetCapsPath(agentId);
110 129
111 if (m_capsObjects.ContainsKey(circuitCode)) 130 lock (m_capsObjects)
112 { 131 {
113 Caps oldCaps = m_capsObjects[circuitCode]; 132 if (m_capsObjects.ContainsKey(circuitCode))
114 133 {
115 m_log.DebugFormat( 134 Caps oldCaps = m_capsObjects[circuitCode];
116 "[CAPS]: Recreating caps for agent {0}. Old caps path {1}, new caps path {2}. ", 135
117 agentId, oldCaps.CapsObjectPath, capsObjectPath); 136 m_log.DebugFormat(
118 // This should not happen. The caller code is confused. We need to fix that. 137 "[CAPS]: Recreating caps for agent {0}. Old caps path {1}, new caps path {2}. ",
119 // CAPs can never be reregistered, or the client will be confused. 138 agentId, oldCaps.CapsObjectPath, capsObjectPath);
120 // Hence this return here. 139 // This should not happen. The caller code is confused. We need to fix that.
121 //return; 140 // CAPs can never be reregistered, or the client will be confused.
122 } 141 // Hence this return here.
142 //return;
143 }
123 144
124 Caps caps = new Caps(MainServer.Instance, m_scene.RegionInfo.ExternalHostName, 145 caps = new Caps(MainServer.Instance, m_scene.RegionInfo.ExternalHostName,
125 (MainServer.Instance == null) ? 0: MainServer.Instance.Port, 146 (MainServer.Instance == null) ? 0: MainServer.Instance.Port,
126 capsObjectPath, agentId, m_scene.RegionInfo.RegionName); 147 capsObjectPath, agentId, m_scene.RegionInfo.RegionName);
127 148
128 m_capsObjects[circuitCode] = caps; 149 m_capsObjects[circuitCode] = caps;
150 }
129 151
130 m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps); 152 m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps);
131 } 153 }
132 154
133 public void RemoveCaps(UUID agentId, uint circuitCode) 155 public void RemoveCaps(UUID agentId, uint circuitCode)
134 { 156 {
135 if (childrenSeeds.ContainsKey(agentId)) 157 lock (m_childrenSeeds)
136 { 158 {
137 childrenSeeds.Remove(agentId); 159 if (m_childrenSeeds.ContainsKey(agentId))
160 {
161 m_childrenSeeds.Remove(agentId);
162 }
138 } 163 }
139 164
140 lock (m_capsObjects) 165 lock (m_capsObjects)
@@ -180,16 +205,22 @@ namespace OpenSim.Region.CoreModules.Framework
180 205
181 public void SetAgentCapsSeeds(AgentCircuitData agent) 206 public void SetAgentCapsSeeds(AgentCircuitData agent)
182 { 207 {
183 capsPaths[agent.AgentID] = agent.CapsPath; 208 lock (m_capsPaths)
184 childrenSeeds[agent.AgentID] 209 m_capsPaths[agent.AgentID] = agent.CapsPath;
185 = ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds); 210
211 lock (m_childrenSeeds)
212 m_childrenSeeds[agent.AgentID]
213 = ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds);
186 } 214 }
187 215
188 public string GetCapsPath(UUID agentId) 216 public string GetCapsPath(UUID agentId)
189 { 217 {
190 if (capsPaths.ContainsKey(agentId)) 218 lock (m_capsPaths)
191 { 219 {
192 return capsPaths[agentId]; 220 if (m_capsPaths.ContainsKey(agentId))
221 {
222 return m_capsPaths[agentId];
223 }
193 } 224 }
194 225
195 return null; 226 return null;
@@ -198,17 +229,24 @@ namespace OpenSim.Region.CoreModules.Framework
198 public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID) 229 public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID)
199 { 230 {
200 Dictionary<ulong, string> seeds = null; 231 Dictionary<ulong, string> seeds = null;
201 if (childrenSeeds.TryGetValue(agentID, out seeds)) 232
202 return seeds; 233 lock (m_childrenSeeds)
234 if (m_childrenSeeds.TryGetValue(agentID, out seeds))
235 return seeds;
236
203 return new Dictionary<ulong, string>(); 237 return new Dictionary<ulong, string>();
204 } 238 }
205 239
206 public void DropChildSeed(UUID agentID, ulong handle) 240 public void DropChildSeed(UUID agentID, ulong handle)
207 { 241 {
208 Dictionary<ulong, string> seeds; 242 Dictionary<ulong, string> seeds;
209 if (childrenSeeds.TryGetValue(agentID, out seeds)) 243
244 lock (m_childrenSeeds)
210 { 245 {
211 seeds.Remove(handle); 246 if (m_childrenSeeds.TryGetValue(agentID, out seeds))
247 {
248 seeds.Remove(handle);
249 }
212 } 250 }
213 } 251 }
214 252
@@ -216,53 +254,285 @@ namespace OpenSim.Region.CoreModules.Framework
216 { 254 {
217 Dictionary<ulong, string> seeds; 255 Dictionary<ulong, string> seeds;
218 string returnval; 256 string returnval;
219 if (childrenSeeds.TryGetValue(agentID, out seeds)) 257
258 lock (m_childrenSeeds)
220 { 259 {
221 if (seeds.TryGetValue(handle, out returnval)) 260 if (m_childrenSeeds.TryGetValue(agentID, out seeds))
222 return returnval; 261 {
262 if (seeds.TryGetValue(handle, out returnval))
263 return returnval;
264 }
223 } 265 }
266
224 return null; 267 return null;
225 } 268 }
226 269
227 public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds) 270 public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds)
228 { 271 {
229 //m_log.DebugFormat(" !!! Setting child seeds in {0} to {1}", m_scene.RegionInfo.RegionName, seeds.Count); 272 //m_log.DebugFormat(" !!! Setting child seeds in {0} to {1}", m_scene.RegionInfo.RegionName, seeds.Count);
230 childrenSeeds[agentID] = seeds; 273
274 lock (m_childrenSeeds)
275 m_childrenSeeds[agentID] = seeds;
231 } 276 }
232 277
233 public void DumpChildrenSeeds(UUID agentID) 278 public void DumpChildrenSeeds(UUID agentID)
234 { 279 {
235 m_log.Info("================ ChildrenSeed "+m_scene.RegionInfo.RegionName+" ================"); 280 m_log.Info("================ ChildrenSeed "+m_scene.RegionInfo.RegionName+" ================");
236 foreach (KeyValuePair<ulong, string> kvp in childrenSeeds[agentID]) 281
282 lock (m_childrenSeeds)
237 { 283 {
238 uint x, y; 284 foreach (KeyValuePair<ulong, string> kvp in m_childrenSeeds[agentID])
239 Utils.LongToUInts(kvp.Key, out x, out y); 285 {
240 x = x / Constants.RegionSize; 286 uint x, y;
241 y = y / Constants.RegionSize; 287 Utils.LongToUInts(kvp.Key, out x, out y);
242 m_log.Info(" >> "+x+", "+y+": "+kvp.Value); 288 x = x / Constants.RegionSize;
289 y = y / Constants.RegionSize;
290 m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
291 }
243 } 292 }
244 } 293 }
245 294
246 private void HandleShowCapsCommand(string module, string[] cmdparams) 295 private void HandleShowCapsListCommand(string module, string[] cmdParams)
247 { 296 {
297 if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene)
298 return;
299
248 StringBuilder caps = new StringBuilder(); 300 StringBuilder caps = new StringBuilder();
249 caps.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName); 301 caps.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName);
250 302
251 foreach (KeyValuePair<uint, Caps> kvp in m_capsObjects) 303 lock (m_capsObjects)
252 { 304 {
253 caps.AppendFormat("** Circuit {0}:\n", kvp.Key); 305 foreach (KeyValuePair<uint, Caps> kvp in m_capsObjects)
306 {
307 caps.AppendFormat("** Circuit {0}:\n", kvp.Key);
308
309 for (IDictionaryEnumerator kvp2 = kvp.Value.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); )
310 {
311 Uri uri = new Uri(kvp2.Value.ToString());
312 caps.AppendFormat(m_showCapsCommandFormat, kvp2.Key, uri.PathAndQuery);
313 }
314
315 foreach (KeyValuePair<string, string> kvp3 in kvp.Value.ExternalCapsHandlers)
316 caps.AppendFormat(m_showCapsCommandFormat, kvp3.Key, kvp3.Value);
317 }
318 }
254 319
255 for (IDictionaryEnumerator kvp2 = kvp.Value.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); ) 320 MainConsole.Instance.Output(caps.ToString());
321 }
322
323 private void HandleShowCapsStatsByCapCommand(string module, string[] cmdParams)
324 {
325 if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene)
326 return;
327
328 if (cmdParams.Length != 5 && cmdParams.Length != 6)
329 {
330 MainConsole.Instance.Output("Usage: show caps stats by cap [<cap-name>]");
331 return;
332 }
333
334 StringBuilder sb = new StringBuilder();
335 sb.AppendFormat("Region {0}:\n", m_scene.Name);
336
337 if (cmdParams.Length == 5)
338 {
339 BuildSummaryStatsByCapReport(sb);
340 }
341 else if (cmdParams.Length == 6)
342 {
343 BuildDetailedStatsByCapReport(sb, cmdParams[5]);
344 }
345
346 MainConsole.Instance.Output(sb.ToString());
347 }
348
349 private void BuildDetailedStatsByCapReport(StringBuilder sb, string capName)
350 {
351 /*
352 sb.AppendFormat("Capability name {0}\n", capName);
353
354 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
355 cdt.AddColumn("User Name", 34);
356 cdt.AddColumn("Req Received", 12);
357 cdt.AddColumn("Req Handled", 12);
358 cdt.Indent = 2;
359
360 Dictionary<string, int> receivedStats = new Dictionary<string, int>();
361 Dictionary<string, int> handledStats = new Dictionary<string, int>();
362
363 m_scene.ForEachScenePresence(
364 sp =>
256 { 365 {
257 Uri uri = new Uri(kvp2.Value.ToString()); 366 Caps caps = m_scene.CapsModule.GetCapsForUser(sp.UUID);
258 caps.AppendFormat(m_showCapsCommandFormat, kvp2.Key, uri.PathAndQuery); 367
368 if (caps == null)
369 return;
370
371 Dictionary<string, IRequestHandler> capsHandlers = caps.CapsHandlers.GetCapsHandlers();
372
373 IRequestHandler reqHandler;
374 if (capsHandlers.TryGetValue(capName, out reqHandler))
375 {
376 receivedStats[sp.Name] = reqHandler.RequestsReceived;
377 handledStats[sp.Name] = reqHandler.RequestsHandled;
378 }
259 } 379 }
380 );
260 381
261 foreach (KeyValuePair<string, string> kvp3 in kvp.Value.ExternalCapsHandlers) 382 foreach (KeyValuePair<string, int> kvp in receivedStats.OrderByDescending(kp => kp.Value))
262 caps.AppendFormat(m_showCapsCommandFormat, kvp3.Key, kvp3.Value); 383 {
384 cdt.AddRow(kvp.Key, kvp.Value, handledStats[kvp.Key]);
263 } 385 }
264 386
265 MainConsole.Instance.Output(caps.ToString()); 387 sb.Append(cdt.ToString());
388 */
389 }
390
391 private void BuildSummaryStatsByCapReport(StringBuilder sb)
392 {
393 /*
394 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
395 cdt.AddColumn("Name", 34);
396 cdt.AddColumn("Req Received", 12);
397 cdt.AddColumn("Req Handled", 12);
398 cdt.Indent = 2;
399
400 Dictionary<string, int> receivedStats = new Dictionary<string, int>();
401 Dictionary<string, int> handledStats = new Dictionary<string, int>();
402
403 m_scene.ForEachScenePresence(
404 sp =>
405 {
406 Caps caps = m_scene.CapsModule.GetCapsForUser(sp.UUID);
407
408 if (caps == null)
409 return;
410
411 Dictionary<string, IRequestHandler> capsHandlers = caps.CapsHandlers.GetCapsHandlers();
412
413 foreach (IRequestHandler reqHandler in capsHandlers.Values)
414 {
415 string reqName = reqHandler.Name ?? "";
416
417 if (!receivedStats.ContainsKey(reqName))
418 {
419 receivedStats[reqName] = reqHandler.RequestsReceived;
420 handledStats[reqName] = reqHandler.RequestsHandled;
421 }
422 else
423 {
424 receivedStats[reqName] += reqHandler.RequestsReceived;
425 handledStats[reqName] += reqHandler.RequestsHandled;
426 }
427 }
428 }
429 );
430
431 foreach (KeyValuePair<string, int> kvp in receivedStats.OrderByDescending(kp => kp.Value))
432 cdt.AddRow(kvp.Key, kvp.Value, handledStats[kvp.Key]);
433
434 sb.Append(cdt.ToString());
435 */
436 }
437
438 private void HandleShowCapsStatsByUserCommand(string module, string[] cmdParams)
439 {
440 /*
441 if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene)
442 return;
443
444 if (cmdParams.Length != 5 && cmdParams.Length != 7)
445 {
446 MainConsole.Instance.Output("Usage: show caps stats by user [<first-name> <last-name>]");
447 return;
448 }
449
450 StringBuilder sb = new StringBuilder();
451 sb.AppendFormat("Region {0}:\n", m_scene.Name);
452
453 if (cmdParams.Length == 5)
454 {
455 BuildSummaryStatsByUserReport(sb);
456 }
457 else if (cmdParams.Length == 7)
458 {
459 string firstName = cmdParams[5];
460 string lastName = cmdParams[6];
461
462 ScenePresence sp = m_scene.GetScenePresence(firstName, lastName);
463
464 if (sp == null)
465 return;
466
467 BuildDetailedStatsByUserReport(sb, sp);
468 }
469
470 MainConsole.Instance.Output(sb.ToString());
471 */
472 }
473
474 private void BuildDetailedStatsByUserReport(StringBuilder sb, ScenePresence sp)
475 {
476 /*
477 sb.AppendFormat("Avatar name {0}, type {1}\n", sp.Name, sp.IsChildAgent ? "child" : "root");
478
479 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
480 cdt.AddColumn("Cap Name", 34);
481 cdt.AddColumn("Req Received", 12);
482 cdt.AddColumn("Req Handled", 12);
483 cdt.Indent = 2;
484
485 Caps caps = m_scene.CapsModule.GetCapsForUser(sp.UUID);
486
487 if (caps == null)
488 return;
489
490 Dictionary<string, IRequestHandler> capsHandlers = caps.CapsHandlers.GetCapsHandlers();
491
492 foreach (IRequestHandler reqHandler in capsHandlers.Values.OrderByDescending(rh => rh.RequestsReceived))
493 {
494 cdt.AddRow(reqHandler.Name, reqHandler.RequestsReceived, reqHandler.RequestsHandled);
495 }
496
497 sb.Append(cdt.ToString());
498 */
499 }
500
501 private void BuildSummaryStatsByUserReport(StringBuilder sb)
502 {
503 /*
504 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
505 cdt.AddColumn("Name", 32);
506 cdt.AddColumn("Type", 5);
507 cdt.AddColumn("Req Received", 12);
508 cdt.AddColumn("Req Handled", 12);
509 cdt.Indent = 2;
510
511 m_scene.ForEachScenePresence(
512 sp =>
513 {
514 Caps caps = m_scene.CapsModule.GetCapsForUser(sp.UUID);
515
516 if (caps == null)
517 return;
518
519 Dictionary<string, IRequestHandler> capsHandlers = caps.CapsHandlers.GetCapsHandlers();
520
521 int totalRequestsReceived = 0;
522 int totalRequestsHandled = 0;
523
524 foreach (IRequestHandler reqHandler in capsHandlers.Values)
525 {
526 totalRequestsReceived += reqHandler.RequestsReceived;
527 totalRequestsHandled += reqHandler.RequestsHandled;
528 }
529
530 cdt.AddRow(sp.Name, sp.IsChildAgent ? "child" : "root", totalRequestsReceived, totalRequestsHandled);
531 }
532 );
533
534 sb.Append(cdt.ToString());
535 */
266 } 536 }
267 } 537 }
268} 538}