opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 OpenSimulator 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 using System;
28 using System.Reflection;
29 using System.Collections.Generic;
30 using OpenSim.Framework;
31 using OpenSim.Services.Interfaces;
32 using OpenMetaverse;
33 using log4net;
34 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
35  
36 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
37 {
38 public class RegionInfoCache
39 {
40 private const double CACHE_EXPIRATION_SECONDS = 300.0; // 5 minutes
41  
42 // private static readonly ILog m_log =
43 // LogManager.GetLogger(
44 // MethodBase.GetCurrentMethod().DeclaringType);
45  
46 internal struct ScopedRegionUUID
47 {
48 public UUID m_scopeID;
49 public UUID m_regionID;
50 public ScopedRegionUUID(UUID scopeID, UUID regionID)
51 {
52 m_scopeID = scopeID;
53 m_regionID = regionID;
54 }
55 }
56  
57 internal struct ScopedRegionName
58 {
59 public UUID m_scopeID;
60 public string m_name;
61 public ScopedRegionName(UUID scopeID, string name)
62 {
63 m_scopeID = scopeID;
64 m_name = name;
65 }
66 }
67  
68 internal struct ScopedRegionPosition
69 {
70 public UUID m_scopeID;
71 public ulong m_regionHandle;
72 public ScopedRegionPosition(UUID scopeID, ulong handle)
73 {
74 m_scopeID = scopeID;
75 m_regionHandle = handle;
76 }
77 }
78  
79 private ExpiringCache<ScopedRegionUUID, GridRegion> m_UUIDCache;
80 private ExpiringCache<ScopedRegionName, ScopedRegionUUID> m_NameCache;
81 private ExpiringCache<ScopedRegionPosition, GridRegion> m_PositionCache;
82  
83 public RegionInfoCache()
84 {
85 m_UUIDCache = new ExpiringCache<ScopedRegionUUID, GridRegion>();
86 m_NameCache = new ExpiringCache<ScopedRegionName, ScopedRegionUUID>();
87 m_PositionCache = new ExpiringCache<ScopedRegionPosition, GridRegion>();
88 }
89  
90 public void Cache(GridRegion rinfo)
91 {
92 if (rinfo != null)
93 this.Cache(rinfo.ScopeID,rinfo.RegionID,rinfo);
94 }
95  
96 public void Cache(UUID scopeID, UUID regionID, GridRegion rinfo)
97 {
98 // for now, do not cache negative results; this is because
99 // we need to figure out how to handle regions coming online
100 // in a timely way
101 if (rinfo == null)
102 return;
103  
104 ScopedRegionUUID id = new ScopedRegionUUID(scopeID,regionID);
105  
106 // Cache even null accounts
107 m_UUIDCache.AddOrUpdate(id, rinfo, CACHE_EXPIRATION_SECONDS);
108 if (rinfo != null)
109 {
110 ScopedRegionName name = new ScopedRegionName(scopeID,rinfo.RegionName);
111 m_NameCache.AddOrUpdate(name, id, CACHE_EXPIRATION_SECONDS);
112  
113 ScopedRegionPosition pos = new ScopedRegionPosition(scopeID, rinfo.RegionHandle);
114 m_PositionCache.AddOrUpdate(pos, rinfo, CACHE_EXPIRATION_SECONDS);
115 }
116 }
117  
118 public GridRegion Get(UUID scopeID, UUID regionID, out bool inCache)
119 {
120 inCache = false;
121  
122 GridRegion rinfo = null;
123 ScopedRegionUUID id = new ScopedRegionUUID(scopeID,regionID);
124 if (m_UUIDCache.TryGetValue(id, out rinfo))
125 {
126 inCache = true;
127 return rinfo;
128 }
129  
130 return null;
131 }
132  
133 public GridRegion Get(UUID scopeID, ulong handle, out bool inCache)
134 {
135 inCache = false;
136  
137 GridRegion rinfo = null;
138 ScopedRegionPosition pos = new ScopedRegionPosition(scopeID, handle);
139 if (m_PositionCache.TryGetValue(pos, out rinfo))
140 {
141 inCache = true;
142 return rinfo;
143 }
144  
145 return null;
146 }
147  
148  
149 public GridRegion Get(UUID scopeID, string name, out bool inCache)
150 {
151 inCache = false;
152  
153 ScopedRegionName sname = new ScopedRegionName(scopeID,name);
154  
155 ScopedRegionUUID id;
156 if (m_NameCache.TryGetValue(sname, out id))
157 {
158 GridRegion rinfo = null;
159 if (m_UUIDCache.TryGetValue(id, out rinfo))
160 {
161 inCache = true;
162 return rinfo;
163 }
164 }
165  
166 return null;
167 }
168 }
169 }