diff options
author | UbitUmarov | 2015-09-11 04:46:15 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-11 04:46:15 +0100 |
commit | 6a0465b70ad3ef64d6e71aab2e624bf3bfddf9b2 (patch) | |
tree | d30b14a253b15436d60d9647c993793066b7c34d /OpenSim/Services/Connectors | |
parent | add a few terminating / in LSLhttp uris as core (diff) | |
download | opensim-SC-6a0465b70ad3ef64d6e71aab2e624bf3bfddf9b2.zip opensim-SC-6a0465b70ad3ef64d6e71aab2e624bf3bfddf9b2.tar.gz opensim-SC-6a0465b70ad3ef64d6e71aab2e624bf3bfddf9b2.tar.bz2 opensim-SC-6a0465b70ad3ef64d6e71aab2e624bf3bfddf9b2.tar.xz |
remove diva's inventory cache since it seems to cause mantis 7720, broken items UUID. Guess it doesn't cover all paths
Diffstat (limited to 'OpenSim/Services/Connectors')
-rw-r--r-- | OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs | 285 |
1 files changed, 66 insertions, 219 deletions
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs index f235446..36d4ae2 100644 --- a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs | |||
@@ -33,37 +33,22 @@ using System.Reflection; | |||
33 | using Nini.Config; | 33 | using Nini.Config; |
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using OpenSim.Framework.Console; | 35 | using OpenSim.Framework.Console; |
36 | 36 | using OpenSim.Framework.Communications; | |
37 | using OpenSim.Framework.Monitoring; | ||
38 | using OpenSim.Services.Interfaces; | 37 | using OpenSim.Services.Interfaces; |
39 | using OpenSim.Server.Base; | 38 | using OpenSim.Server.Base; |
40 | using OpenMetaverse; | 39 | using OpenMetaverse; |
41 | 40 | ||
42 | namespace OpenSim.Services.Connectors | 41 | namespace OpenSim.Services.Connectors |
43 | { | 42 | { |
44 | public class XInventoryServicesConnector : BaseServiceConnector, IInventoryService | 43 | public class XInventoryServicesConnector : IInventoryService |
45 | { | 44 | { |
46 | private static readonly ILog m_log = | 45 | private static readonly ILog m_log = |
47 | LogManager.GetLogger( | 46 | LogManager.GetLogger( |
48 | MethodBase.GetCurrentMethod().DeclaringType); | 47 | MethodBase.GetCurrentMethod().DeclaringType); |
49 | 48 | ||
50 | /// <summary> | ||
51 | /// Number of requests made to the remote inventory service. | ||
52 | /// </summary> | ||
53 | public int RequestsMade { get; private set; } | ||
54 | |||
55 | private string m_ServerURI = String.Empty; | 49 | private string m_ServerURI = String.Empty; |
56 | 50 | ||
57 | /// <summary> | 51 | private object m_Lock = new object(); |
58 | /// Timeout for remote requests. | ||
59 | /// </summary> | ||
60 | /// <remarks> | ||
61 | /// In this case, -1 is default timeout (100 seconds), not infinite. | ||
62 | /// </remarks> | ||
63 | private int m_requestTimeoutSecs = -1; | ||
64 | |||
65 | private const double CACHE_EXPIRATION_SECONDS = 20.0; | ||
66 | private static ExpiringCache<UUID, InventoryItemBase> m_ItemCache = new ExpiringCache<UUID,InventoryItemBase>(); | ||
67 | 52 | ||
68 | public XInventoryServicesConnector() | 53 | public XInventoryServicesConnector() |
69 | { | 54 | { |
@@ -75,21 +60,20 @@ namespace OpenSim.Services.Connectors | |||
75 | } | 60 | } |
76 | 61 | ||
77 | public XInventoryServicesConnector(IConfigSource source) | 62 | public XInventoryServicesConnector(IConfigSource source) |
78 | : base(source, "InventoryService") | ||
79 | { | 63 | { |
80 | Initialise(source); | 64 | Initialise(source); |
81 | } | 65 | } |
82 | 66 | ||
83 | public virtual void Initialise(IConfigSource source) | 67 | public virtual void Initialise(IConfigSource source) |
84 | { | 68 | { |
85 | IConfig config = source.Configs["InventoryService"]; | 69 | IConfig assetConfig = source.Configs["InventoryService"]; |
86 | if (config == null) | 70 | if (assetConfig == null) |
87 | { | 71 | { |
88 | m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); | 72 | m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); |
89 | throw new Exception("Inventory connector init error"); | 73 | throw new Exception("Inventory connector init error"); |
90 | } | 74 | } |
91 | 75 | ||
92 | string serviceURI = config.GetString("InventoryServerURI", | 76 | string serviceURI = assetConfig.GetString("InventoryServerURI", |
93 | String.Empty); | 77 | String.Empty); |
94 | 78 | ||
95 | if (serviceURI == String.Empty) | 79 | if (serviceURI == String.Empty) |
@@ -98,21 +82,6 @@ namespace OpenSim.Services.Connectors | |||
98 | throw new Exception("Inventory connector init error"); | 82 | throw new Exception("Inventory connector init error"); |
99 | } | 83 | } |
100 | m_ServerURI = serviceURI; | 84 | m_ServerURI = serviceURI; |
101 | |||
102 | m_requestTimeoutSecs = config.GetInt("RemoteRequestTimeout", m_requestTimeoutSecs); | ||
103 | |||
104 | StatsManager.RegisterStat( | ||
105 | new Stat( | ||
106 | "RequestsMade", | ||
107 | "Requests made", | ||
108 | "Number of requests made to the remove inventory service", | ||
109 | "requests", | ||
110 | "inventory", | ||
111 | serviceURI, | ||
112 | StatType.Pull, | ||
113 | MeasuresOfInterest.AverageChangeOverTime, | ||
114 | s => s.Value = RequestsMade, | ||
115 | StatVerbosity.Debug)); | ||
116 | } | 85 | } |
117 | 86 | ||
118 | private bool CheckReturn(Dictionary<string, object> ret) | 87 | private bool CheckReturn(Dictionary<string, object> ret) |
@@ -189,7 +158,7 @@ namespace OpenSim.Services.Connectors | |||
189 | return BuildFolder((Dictionary<string, object>)ret["folder"]); | 158 | return BuildFolder((Dictionary<string, object>)ret["folder"]); |
190 | } | 159 | } |
191 | 160 | ||
192 | public InventoryFolderBase GetFolderForType(UUID principalID, FolderType type) | 161 | public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) |
193 | { | 162 | { |
194 | Dictionary<string,object> ret = MakeRequest("GETFOLDERFORTYPE", | 163 | Dictionary<string,object> ret = MakeRequest("GETFOLDERFORTYPE", |
195 | new Dictionary<string,object> { | 164 | new Dictionary<string,object> { |
@@ -208,7 +177,7 @@ namespace OpenSim.Services.Connectors | |||
208 | InventoryCollection inventory = new InventoryCollection(); | 177 | InventoryCollection inventory = new InventoryCollection(); |
209 | inventory.Folders = new List<InventoryFolderBase>(); | 178 | inventory.Folders = new List<InventoryFolderBase>(); |
210 | inventory.Items = new List<InventoryItemBase>(); | 179 | inventory.Items = new List<InventoryItemBase>(); |
211 | inventory.OwnerID = principalID; | 180 | inventory.UserID = principalID; |
212 | 181 | ||
213 | try | 182 | try |
214 | { | 183 | { |
@@ -221,17 +190,15 @@ namespace OpenSim.Services.Connectors | |||
221 | if (!CheckReturn(ret)) | 190 | if (!CheckReturn(ret)) |
222 | return null; | 191 | return null; |
223 | 192 | ||
224 | Dictionary<string,object> folders = ret.ContainsKey("FOLDERS") ? | 193 | Dictionary<string,object> folders = |
225 | (Dictionary<string,object>)ret["FOLDERS"] : null; | 194 | (Dictionary<string,object>)ret["FOLDERS"]; |
226 | Dictionary<string,object> items = ret.ContainsKey("ITEMS") ? | 195 | Dictionary<string,object> items = |
227 | (Dictionary<string, object>)ret["ITEMS"] : null; | 196 | (Dictionary<string,object>)ret["ITEMS"]; |
228 | 197 | ||
229 | if (folders != null) | 198 | foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i |
230 | foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i | 199 | inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o)); |
231 | inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o)); | 200 | foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i |
232 | if (items != null) | 201 | inventory.Items.Add(BuildItem((Dictionary<string, object>)o)); |
233 | foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i | ||
234 | inventory.Items.Add(BuildItem((Dictionary<string, object>)o)); | ||
235 | } | 202 | } |
236 | catch (Exception e) | 203 | catch (Exception e) |
237 | { | 204 | { |
@@ -240,87 +207,6 @@ namespace OpenSim.Services.Connectors | |||
240 | 207 | ||
241 | return inventory; | 208 | return inventory; |
242 | } | 209 | } |
243 | |||
244 | public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs) | ||
245 | { | ||
246 | InventoryCollection[] inventoryArr = new InventoryCollection[folderIDs.Length]; | ||
247 | // m_log.DebugFormat("[XXX]: In GetMultipleFoldersContent {0}", String.Join(",", folderIDs)); | ||
248 | try | ||
249 | { | ||
250 | Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEFOLDERSCONTENT", | ||
251 | new Dictionary<string, object> { | ||
252 | { "PRINCIPAL", principalID.ToString() }, | ||
253 | { "FOLDERS", String.Join(",", folderIDs) }, | ||
254 | { "COUNT", folderIDs.Length.ToString() } | ||
255 | }); | ||
256 | |||
257 | if (!CheckReturn(resultSet)) | ||
258 | return null; | ||
259 | |||
260 | int i = 0; | ||
261 | foreach (KeyValuePair<string, object> kvp in resultSet) | ||
262 | { | ||
263 | InventoryCollection inventory = new InventoryCollection(); | ||
264 | if (kvp.Key.StartsWith("F_")) | ||
265 | { | ||
266 | UUID fid = UUID.Zero; | ||
267 | if (UUID.TryParse(kvp.Key.Substring(2), out fid) && fid == folderIDs[i]) | ||
268 | { | ||
269 | inventory.Folders = new List<InventoryFolderBase>(); | ||
270 | inventory.Items = new List<InventoryItemBase>(); | ||
271 | |||
272 | Dictionary<string, object> ret = (Dictionary<string, object>)kvp.Value; | ||
273 | |||
274 | if (ret.ContainsKey("FID")) | ||
275 | { | ||
276 | if (!UUID.TryParse(ret["FID"].ToString(), out inventory.FolderID)) | ||
277 | m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Could not parse folder id {0}", ret["FID"].ToString()); | ||
278 | } | ||
279 | else | ||
280 | m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: FID key not present in response"); | ||
281 | |||
282 | inventory.Version = -1; | ||
283 | if (ret.ContainsKey("VERSION")) | ||
284 | Int32.TryParse(ret["VERSION"].ToString(), out inventory.Version); | ||
285 | if (ret.ContainsKey("OWNER")) | ||
286 | UUID.TryParse(ret["OWNER"].ToString(), out inventory.OwnerID); | ||
287 | |||
288 | //m_log.DebugFormat("[XXX]: Received {0} ({1}) {2} {3}", inventory.FolderID, fid, inventory.Version, inventory.OwnerID); | ||
289 | |||
290 | Dictionary<string, object> folders = | ||
291 | (Dictionary<string, object>)ret["FOLDERS"]; | ||
292 | Dictionary<string, object> items = | ||
293 | (Dictionary<string, object>)ret["ITEMS"]; | ||
294 | |||
295 | foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i | ||
296 | { | ||
297 | inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o)); | ||
298 | } | ||
299 | foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i | ||
300 | { | ||
301 | inventory.Items.Add(BuildItem((Dictionary<string, object>)o)); | ||
302 | } | ||
303 | |||
304 | inventoryArr[i] = inventory; | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Folder id does not match. Expected {0} got {1}", | ||
309 | folderIDs[i], fid); | ||
310 | m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: {0} {1}", String.Join(",", folderIDs), String.Join(",", resultSet.Keys)); | ||
311 | } | ||
312 | |||
313 | i += 1; | ||
314 | } | ||
315 | } | ||
316 | } | ||
317 | catch (Exception e) | ||
318 | { | ||
319 | m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleFoldersContent: {0}", e.Message); | ||
320 | } | ||
321 | |||
322 | return inventoryArr; | ||
323 | } | ||
324 | 210 | ||
325 | public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) | 211 | public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) |
326 | { | 212 | { |
@@ -411,13 +297,9 @@ namespace OpenSim.Services.Connectors | |||
411 | 297 | ||
412 | public bool AddItem(InventoryItemBase item) | 298 | public bool AddItem(InventoryItemBase item) |
413 | { | 299 | { |
414 | if (item.Description == null) | ||
415 | item.Description = String.Empty; | ||
416 | if (item.CreatorData == null) | 300 | if (item.CreatorData == null) |
417 | item.CreatorData = String.Empty; | 301 | item.CreatorData = String.Empty; |
418 | if (item.CreatorId == null) | 302 | Dictionary<string,object> ret = MakeRequest("ADDITEM", |
419 | item.CreatorId = String.Empty; | ||
420 | Dictionary<string, object> ret = MakeRequest("ADDITEM", | ||
421 | new Dictionary<string,object> { | 303 | new Dictionary<string,object> { |
422 | { "AssetID", item.AssetID.ToString() }, | 304 | { "AssetID", item.AssetID.ToString() }, |
423 | { "AssetType", item.AssetType.ToString() }, | 305 | { "AssetType", item.AssetType.ToString() }, |
@@ -516,10 +398,6 @@ namespace OpenSim.Services.Connectors | |||
516 | 398 | ||
517 | public InventoryItemBase GetItem(InventoryItemBase item) | 399 | public InventoryItemBase GetItem(InventoryItemBase item) |
518 | { | 400 | { |
519 | InventoryItemBase retrieved = null; | ||
520 | if (m_ItemCache.TryGetValue(item.ID, out retrieved)) | ||
521 | return retrieved; | ||
522 | |||
523 | try | 401 | try |
524 | { | 402 | { |
525 | Dictionary<string, object> ret = MakeRequest("GETITEM", | 403 | Dictionary<string, object> ret = MakeRequest("GETITEM", |
@@ -530,78 +408,14 @@ namespace OpenSim.Services.Connectors | |||
530 | if (!CheckReturn(ret)) | 408 | if (!CheckReturn(ret)) |
531 | return null; | 409 | return null; |
532 | 410 | ||
533 | retrieved = BuildItem((Dictionary<string, object>)ret["item"]); | 411 | return BuildItem((Dictionary<string, object>)ret["item"]); |
534 | } | 412 | } |
535 | catch (Exception e) | 413 | catch (Exception e) |
536 | { | 414 | { |
537 | m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e); | 415 | m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e); |
538 | } | 416 | } |
539 | 417 | ||
540 | m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS); | 418 | return null; |
541 | |||
542 | return retrieved; | ||
543 | } | ||
544 | |||
545 | public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs) | ||
546 | { | ||
547 | //m_log.DebugFormat("[XXX]: In GetMultipleItems {0}", String.Join(",", itemIDs)); | ||
548 | |||
549 | InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length]; | ||
550 | // Try to get them from the cache | ||
551 | List<UUID> pending = new List<UUID>(); | ||
552 | InventoryItemBase item = null; | ||
553 | int i = 0; | ||
554 | foreach (UUID id in itemIDs) | ||
555 | { | ||
556 | if (m_ItemCache.TryGetValue(id, out item)) | ||
557 | itemArr[i++] = item; | ||
558 | else | ||
559 | pending.Add(id); | ||
560 | } | ||
561 | |||
562 | if (pending.Count == 0) // we're done, everything was in the cache | ||
563 | return itemArr; | ||
564 | |||
565 | try | ||
566 | { | ||
567 | Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEITEMS", | ||
568 | new Dictionary<string, object> { | ||
569 | { "PRINCIPAL", principalID.ToString() }, | ||
570 | { "ITEMS", String.Join(",", pending.ToArray()) }, | ||
571 | { "COUNT", pending.Count.ToString() } | ||
572 | }); | ||
573 | |||
574 | if (!CheckReturn(resultSet)) | ||
575 | { | ||
576 | if (i == 0) | ||
577 | return null; | ||
578 | else | ||
579 | return itemArr; | ||
580 | } | ||
581 | |||
582 | // carry over index i where we left above | ||
583 | foreach (KeyValuePair<string, object> kvp in resultSet) | ||
584 | { | ||
585 | InventoryCollection inventory = new InventoryCollection(); | ||
586 | if (kvp.Key.StartsWith("item_")) | ||
587 | { | ||
588 | if (kvp.Value is Dictionary<string, object>) | ||
589 | { | ||
590 | item = BuildItem((Dictionary<string, object>)kvp.Value); | ||
591 | m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS); | ||
592 | itemArr[i++] = item; | ||
593 | } | ||
594 | else | ||
595 | itemArr[i++] = null; | ||
596 | } | ||
597 | } | ||
598 | } | ||
599 | catch (Exception e) | ||
600 | { | ||
601 | m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleItems: {0}", e.Message); | ||
602 | } | ||
603 | |||
604 | return itemArr; | ||
605 | } | 419 | } |
606 | 420 | ||
607 | public InventoryFolderBase GetFolder(InventoryFolderBase folder) | 421 | public InventoryFolderBase GetFolder(InventoryFolderBase folder) |
@@ -670,6 +484,45 @@ namespace OpenSim.Services.Connectors | |||
670 | return 0; | 484 | return 0; |
671 | } | 485 | } |
672 | 486 | ||
487 | public InventoryCollection GetUserInventory(UUID principalID) | ||
488 | { | ||
489 | InventoryCollection inventory = new InventoryCollection(); | ||
490 | inventory.Folders = new List<InventoryFolderBase>(); | ||
491 | inventory.Items = new List<InventoryItemBase>(); | ||
492 | inventory.UserID = principalID; | ||
493 | |||
494 | try | ||
495 | { | ||
496 | Dictionary<string, object> ret = MakeRequest("GETUSERINVENTORY", | ||
497 | new Dictionary<string, object> { | ||
498 | { "PRINCIPAL", principalID.ToString() } | ||
499 | }); | ||
500 | |||
501 | if (!CheckReturn(ret)) | ||
502 | return null; | ||
503 | |||
504 | Dictionary<string, object> folders = | ||
505 | (Dictionary<string, object>)ret["FOLDERS"]; | ||
506 | Dictionary<string, object> items = | ||
507 | (Dictionary<string, object>)ret["ITEMS"]; | ||
508 | |||
509 | foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i | ||
510 | inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o)); | ||
511 | foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i | ||
512 | inventory.Items.Add(BuildItem((Dictionary<string, object>)o)); | ||
513 | } | ||
514 | catch (Exception e) | ||
515 | { | ||
516 | m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetUserInventory: ", e); | ||
517 | } | ||
518 | |||
519 | return inventory; | ||
520 | } | ||
521 | |||
522 | public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback) | ||
523 | { | ||
524 | } | ||
525 | |||
673 | public bool HasInventoryForUser(UUID principalID) | 526 | public bool HasInventoryForUser(UUID principalID) |
674 | { | 527 | { |
675 | return false; | 528 | return false; |
@@ -680,19 +533,13 @@ namespace OpenSim.Services.Connectors | |||
680 | private Dictionary<string,object> MakeRequest(string method, | 533 | private Dictionary<string,object> MakeRequest(string method, |
681 | Dictionary<string,object> sendData) | 534 | Dictionary<string,object> sendData) |
682 | { | 535 | { |
683 | // Add "METHOD" as the first key in the dictionary. This ensures that it will be | 536 | sendData["METHOD"] = method; |
684 | // visible even when using partial logging ("debug http all 5"). | ||
685 | Dictionary<string, object> temp = sendData; | ||
686 | sendData = new Dictionary<string,object>{ { "METHOD", method } }; | ||
687 | foreach (KeyValuePair<string, object> kvp in temp) | ||
688 | sendData.Add(kvp.Key, kvp.Value); | ||
689 | |||
690 | RequestsMade++; | ||
691 | 537 | ||
692 | string reply | 538 | string reply = string.Empty; |
693 | = SynchronousRestFormsRequester.MakeRequest( | 539 | lock (m_Lock) |
694 | "POST", m_ServerURI + "/xinventory", | 540 | reply = SynchronousRestFormsRequester.MakeRequest("POST", |
695 | ServerUtils.BuildQueryString(sendData), m_requestTimeoutSecs, m_Auth); | 541 | m_ServerURI + "/xinventory", |
542 | ServerUtils.BuildQueryString(sendData)); | ||
696 | 543 | ||
697 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse( | 544 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse( |
698 | reply); | 545 | reply); |
@@ -760,4 +607,4 @@ namespace OpenSim.Services.Connectors | |||
760 | return item; | 607 | return item; |
761 | } | 608 | } |
762 | } | 609 | } |
763 | } | 610 | } \ No newline at end of file |