aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs66
1 files changed, 33 insertions, 33 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
index 5eb525b..84e52f7 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
@@ -44,7 +44,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
44// private static readonly ILog m_log = 44// private static readonly ILog m_log =
45// LogManager.GetLogger( 45// LogManager.GetLogger(
46// MethodBase.GetCurrentMethod().DeclaringType); 46// MethodBase.GetCurrentMethod().DeclaringType);
47 47
48 private static RegionsExpiringCache m_Cache; 48 private static RegionsExpiringCache m_Cache;
49 private int numberInstances; 49 private int numberInstances;
50 50
@@ -60,12 +60,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
60 if (rinfo != null) 60 if (rinfo != null)
61 this.Cache(rinfo.ScopeID, rinfo); 61 this.Cache(rinfo.ScopeID, rinfo);
62 } 62 }
63 63
64 public void Cache(UUID scopeID, GridRegion rinfo) 64 public void Cache(UUID scopeID, GridRegion rinfo)
65 { 65 {
66 if (rinfo == null) 66 if (rinfo == null)
67 return; 67 return;
68 68
69 m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); 69 m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS);
70 } 70 }
71 71
@@ -73,7 +73,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
73 { 73 {
74 if (rinfo == null) 74 if (rinfo == null)
75 return; 75 return;
76 76
77 m_Cache.AddOrUpdate(rinfo.ScopeID, rinfo, 1e7f); 77 m_Cache.AddOrUpdate(rinfo.ScopeID, rinfo, 1e7f);
78 } 78 }
79 79
@@ -81,7 +81,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
81 { 81 {
82 if (rinfo == null) 82 if (rinfo == null)
83 return; 83 return;
84 84
85 m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS); 85 m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS);
86 } 86 }
87 87
@@ -89,7 +89,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
89 { 89 {
90 if (rinfo == null) 90 if (rinfo == null)
91 return; 91 return;
92 92
93 m_Cache.AddOrUpdate(scopeID, rinfo, expireSeconds); 93 m_Cache.AddOrUpdate(scopeID, rinfo, expireSeconds);
94 } 94 }
95 95
@@ -141,7 +141,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
141 inCache = true; 141 inCache = true;
142 return rinfo; 142 return rinfo;
143 } 143 }
144 144
145 return null; 145 return null;
146 } 146 }
147 147
@@ -155,7 +155,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
155 inCache = true; 155 inCache = true;
156 return rinfo; 156 return rinfo;
157 } 157 }
158 158
159 return null; 159 return null;
160 } 160 }
161 } 161 }
@@ -300,7 +300,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
300 private Dictionary<string, ulong> byname; 300 private Dictionary<string, ulong> byname;
301 private Dictionary<UUID, ulong> byuuid; 301 private Dictionary<UUID, ulong> byuuid;
302 // includes handles to the inside of large regions 302 // includes handles to the inside of large regions
303 private Dictionary<ulong, ulong> innerHandles = new Dictionary<ulong, ulong>(); 303 private Dictionary<ulong, ulong> innerHandles = new Dictionary<ulong, ulong>();
304 304
305 public RegionInfoForScope() 305 public RegionInfoForScope()
306 { 306 {
@@ -342,7 +342,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
342 byuuid = new Dictionary<UUID, ulong>(); 342 byuuid = new Dictionary<UUID, ulong>();
343 343
344 storage[handle] = region; 344 storage[handle] = region;
345 expires[handle] = expire; 345 expires[handle] = expire;
346 byname[region.RegionName] = handle; 346 byname[region.RegionName] = handle;
347 byuuid[region.RegionID] = handle; 347 byuuid[region.RegionID] = handle;
348 348
@@ -385,7 +385,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
385 storage[handle] = region; 385 storage[handle] = region;
386 byname[region.RegionName] = handle; 386 byname[region.RegionName] = handle;
387 byuuid[region.RegionID] = handle; 387 byuuid[region.RegionID] = handle;
388 388
389 } 389 }
390 390
391 public void Remove(GridRegion region) 391 public void Remove(GridRegion region)
@@ -483,7 +483,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
483 483
484 if(!innerHandles.ContainsKey(handle)) 484 if(!innerHandles.ContainsKey(handle))
485 return null; 485 return null;
486 486
487 ulong rhandle = innerHandles[handle]; 487 ulong rhandle = innerHandles[handle];
488 if(storage.ContainsKey(rhandle)) 488 if(storage.ContainsKey(rhandle))
489 return storage[rhandle]; 489 return storage[rhandle];
@@ -495,7 +495,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
495 { 495 {
496 if(byname == null || !byname.ContainsKey(name)) 496 if(byname == null || !byname.ContainsKey(name))
497 return null; 497 return null;
498 498
499 ulong handle = byname[name]; 499 ulong handle = byname[name];
500 if(storage.ContainsKey(handle)) 500 if(storage.ContainsKey(handle))
501 return storage[handle]; 501 return storage[handle];
@@ -528,7 +528,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
528 528
529 if(!innerHandles.ContainsKey(handle)) 529 if(!innerHandles.ContainsKey(handle))
530 return null; 530 return null;
531 531
532 ulong rhandle = innerHandles[handle]; 532 ulong rhandle = innerHandles[handle];
533 if(!storage.ContainsKey(rhandle)) 533 if(!storage.ContainsKey(rhandle))
534 return null; 534 return null;
@@ -536,7 +536,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
536 GridRegion r = storage[rhandle]; 536 GridRegion r = storage[rhandle];
537 if(r == null) 537 if(r == null)
538 return null; 538 return null;
539 539
540 // extra check, possible redundant 540 // extra check, possible redundant
541 541
542 int test = r.RegionLocX; 542 int test = r.RegionLocX;
@@ -552,7 +552,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
552 if (y < test) 552 if (y < test)
553 return r; 553 return r;
554 554
555/* 555/*
556 // next do the harder work 556 // next do the harder work
557 foreach(KeyValuePair<ulong, GridRegion> kvp in storage) 557 foreach(KeyValuePair<ulong, GridRegion> kvp in storage)
558 { 558 {
@@ -588,7 +588,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
588 if(kvp.Value < now) 588 if(kvp.Value < now)
589 toexpire.Add(kvp.Key); 589 toexpire.Add(kvp.Key);
590 } 590 }
591 591
592 if(toexpire.Count == 0) 592 if(toexpire.Count == 0)
593 return expires.Count; 593 return expires.Count;
594 594
@@ -597,7 +597,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
597 Clear(); 597 Clear();
598 return 0; 598 return 0;
599 } 599 }
600 600
601 foreach(ulong h in toexpire) 601 foreach(ulong h in toexpire)
602 { 602 {
603 if(storage != null) 603 if(storage != null)
@@ -658,7 +658,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
658 innerHandles[fh.toHandle()] = handle; 658 innerHandles[fh.toHandle()] = handle;
659 fh.y += 256; 659 fh.y += 256;
660 } 660 }
661 661
662 fh.y = startY; 662 fh.y = startY;
663 fh.x += 256; 663 fh.x += 256;
664 } 664 }
@@ -684,18 +684,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
684 innerHandles.Remove(fh.toHandle()); 684 innerHandles.Remove(fh.toHandle());
685 fh.y += 256; 685 fh.y += 256;
686 } 686 }
687 687
688 fh.y = startY; 688 fh.y = startY;
689 fh.x += 256; 689 fh.x += 256;
690 } 690 }
691 } 691 }
692 } 692 }
693 693
694 public class RegionsExpiringCache 694 public class RegionsExpiringCache
695 { 695 {
696 const double CACHE_PURGE_HZ = 60; // seconds 696 const double CACHE_PURGE_HZ = 60; // seconds
697 const int MAX_LOCK_WAIT = 10000; // milliseconds 697 const int MAX_LOCK_WAIT = 10000; // milliseconds
698 698
699 /// <summary>For thread safety</summary> 699 /// <summary>For thread safety</summary>
700 object syncRoot = new object(); 700 object syncRoot = new object();
701 /// <summary>For thread safety</summary> 701 /// <summary>For thread safety</summary>
@@ -728,7 +728,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
728 ris = new RegionInfoForScope(region, expire); 728 ris = new RegionInfoForScope(region, expire);
729 InfobyScope[scope] = ris; 729 InfobyScope[scope] = ris;
730 } 730 }
731 else 731 else
732 ris.AddUpdate(region, expire); 732 ris.AddUpdate(region, expire);
733 733
734 return true; 734 return true;
@@ -748,7 +748,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
748 } 748 }
749 finally { Monitor.Exit(syncRoot); } 749 finally { Monitor.Exit(syncRoot); }
750 } 750 }
751 751
752 public bool Contains(UUID scope, GridRegion region) 752 public bool Contains(UUID scope, GridRegion region)
753 { 753 {
754 if(region == null) 754 if(region == null)
@@ -758,11 +758,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
758 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); 758 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
759 759
760 try 760 try
761 { 761 {
762 RegionInfoForScope ris = null; 762 RegionInfoForScope ris = null;
763 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null) 763 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
764 return false; 764 return false;
765 765
766 return ris.Contains(region); 766 return ris.Contains(region);
767 } 767 }
768 finally { Monitor.Exit(syncRoot); } 768 finally { Monitor.Exit(syncRoot); }
@@ -774,11 +774,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
774 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); 774 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
775 775
776 try 776 try
777 { 777 {
778 RegionInfoForScope ris = null; 778 RegionInfoForScope ris = null;
779 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null) 779 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
780 return false; 780 return false;
781 781
782 return ris.Contains(handle); 782 return ris.Contains(handle);
783 } 783 }
784 finally { Monitor.Exit(syncRoot); } 784 finally { Monitor.Exit(syncRoot); }
@@ -790,7 +790,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
790 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); 790 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
791 791
792 try 792 try
793 { 793 {
794 int count = 0; 794 int count = 0;
795 foreach(RegionInfoForScope ris in InfobyScope.Values) 795 foreach(RegionInfoForScope ris in InfobyScope.Values)
796 count += ris.Count(); 796 count += ris.Count();
@@ -804,7 +804,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
804 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) 804 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
805 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); 805 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
806 try 806 try
807 { 807 {
808 RegionInfoForScope ris = null; 808 RegionInfoForScope ris = null;
809 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null) 809 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
810 return false; 810 return false;
@@ -825,7 +825,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
825 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT)) 825 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
826 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); 826 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
827 try 827 try
828 { 828 {
829 RegionInfoForScope ris = null; 829 RegionInfoForScope ris = null;
830 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null) 830 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
831 return false; 831 return false;
@@ -940,7 +940,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
940 private void PurgeCache(object sender, System.Timers.ElapsedEventArgs e) 940 private void PurgeCache(object sender, System.Timers.ElapsedEventArgs e)
941 { 941 {
942 // Only let one thread purge at once - a buildup could cause a crash 942 // Only let one thread purge at once - a buildup could cause a crash
943 // This could cause the purge to be delayed while there are lots of read/write ops 943 // This could cause the purge to be delayed while there are lots of read/write ops
944 // happening on the cache 944 // happening on the cache
945 if (!Monitor.TryEnter(isPurging)) 945 if (!Monitor.TryEnter(isPurging))
946 return; 946 return;
@@ -961,7 +961,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
961 if (kvp.Value.expire(now) == 0) 961 if (kvp.Value.expire(now) == 0)
962 expiredscopes.Add(kvp.Key); 962 expiredscopes.Add(kvp.Key);
963 } 963 }
964 964
965 if (expiredscopes.Count > 0) 965 if (expiredscopes.Count > 0)
966 { 966 {
967 foreach (UUID sid in expiredscopes) 967 foreach (UUID sid in expiredscopes)