aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs55
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs61
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs103
3 files changed, 186 insertions, 33 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
index 6d4ac39..77fd70b 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
@@ -59,7 +59,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
59 59
60 #region ISharedRegionModule 60 #region ISharedRegionModule
61 61
62 public Type ReplaceableInterface 62 public Type ReplaceableInterface
63 { 63 {
64 get { return null; } 64 get { return null; }
65 } 65 }
@@ -129,6 +129,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
129 // FIXME: Why do we bother setting this module and caching up if we just end up registering the inner 129 // FIXME: Why do we bother setting this module and caching up if we just end up registering the inner
130 // user account service?! 130 // user account service?!
131 scene.RegisterModuleInterface<IUserAccountService>(UserAccountService); 131 scene.RegisterModuleInterface<IUserAccountService>(UserAccountService);
132 scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
132 } 133 }
133 134
134 public void RemoveRegion(Scene scene) 135 public void RemoveRegion(Scene scene)
@@ -152,7 +153,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
152 public UserAccount GetUserAccount(UUID scopeID, UUID userID) 153 public UserAccount GetUserAccount(UUID scopeID, UUID userID)
153 { 154 {
154 bool inCache = false; 155 bool inCache = false;
155 UserAccount account = m_Cache.Get(userID, out inCache); 156 UserAccount account;
157 account = m_Cache.Get(userID, out inCache);
156 if (inCache) 158 if (inCache)
157 return account; 159 return account;
158 160
@@ -165,7 +167,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
165 public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) 167 public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
166 { 168 {
167 bool inCache = false; 169 bool inCache = false;
168 UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache); 170 UserAccount account;
171 account = m_Cache.Get(firstName + " " + lastName, out inCache);
169 if (inCache) 172 if (inCache)
170 return account; 173 return account;
171 174
@@ -181,6 +184,50 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
181 return UserAccountService.GetUserAccount(scopeID, Email); 184 return UserAccountService.GetUserAccount(scopeID, Email);
182 } 185 }
183 186
187 public List<UserAccount> GetUserAccounts(UUID scopeID, List<string> IDs)
188 {
189 List<UserAccount> ret = new List<UserAccount>();
190 List<string> missing = new List<string>();
191
192 // still another cache..
193 bool inCache = false;
194 UUID uuid = UUID.Zero;
195 UserAccount account;
196 foreach(string id in IDs)
197 {
198 if(UUID.TryParse(id, out uuid))
199 {
200 account = m_Cache.Get(uuid, out inCache);
201 if (inCache)
202 ret.Add(account);
203 else
204 missing.Add(id);
205 }
206 }
207
208 if(missing.Count == 0)
209 return ret;
210
211 List<UserAccount> ext = UserAccountService.GetUserAccounts(scopeID, missing);
212 if(ext != null && ext.Count > 0)
213 {
214 foreach(UserAccount acc in ext)
215 {
216 if(acc != null)
217 {
218 ret.Add(acc);
219 m_Cache.Cache(acc.PrincipalID, acc);
220 }
221 }
222 }
223 return ret;
224 }
225
226 public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string query)
227 {
228 return null;
229 }
230
184 public List<UserAccount> GetUserAccounts(UUID scopeID, string query) 231 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
185 { 232 {
186 return UserAccountService.GetUserAccounts(scopeID, query); 233 return UserAccountService.GetUserAccounts(scopeID, query);
@@ -203,4 +250,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
203 250
204 #endregion 251 #endregion
205 } 252 }
206} \ No newline at end of file 253}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
index 5aa87d3..b510d0a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
@@ -26,6 +26,8 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
30using System.Collections.Generic;
29using Nini.Config; 31using Nini.Config;
30using log4net; 32using log4net;
31using Mono.Addins; 33using Mono.Addins;
@@ -34,6 +36,7 @@ using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
35using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
36using OpenSim.Services.Connectors; 38using OpenSim.Services.Connectors;
39using OpenSim.Framework;
37 40
38using OpenMetaverse; 41using OpenMetaverse;
39 42
@@ -50,7 +53,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
50 private bool m_Enabled = false; 53 private bool m_Enabled = false;
51 private UserAccountCache m_Cache; 54 private UserAccountCache m_Cache;
52 55
53 public Type ReplaceableInterface 56 public Type ReplaceableInterface
54 { 57 {
55 get { return null; } 58 get { return null; }
56 } 59 }
@@ -103,6 +106,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
103 return; 106 return;
104 107
105 scene.RegisterModuleInterface<IUserAccountService>(this); 108 scene.RegisterModuleInterface<IUserAccountService>(this);
109 scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
110
111 scene.EventManager.OnNewClient += OnNewClient;
106 } 112 }
107 113
108 public void RemoveRegion(Scene scene) 114 public void RemoveRegion(Scene scene)
@@ -117,12 +123,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
117 return; 123 return;
118 } 124 }
119 125
126 // When a user actually enters the sim, clear them from
127 // cache so the sim will have the current values for
128 // flags, title, etc. And country, don't forget country!
129 private void OnNewClient(IClientAPI client)
130 {
131 m_Cache.Remove(client.Name);
132 }
133
120 #region Overwritten methods from IUserAccountService 134 #region Overwritten methods from IUserAccountService
121 135
122 public override UserAccount GetUserAccount(UUID scopeID, UUID userID) 136 public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
123 { 137 {
124 bool inCache = false; 138 bool inCache = false;
125 UserAccount account = m_Cache.Get(userID, out inCache); 139 UserAccount account;
140 account = m_Cache.Get(userID, out inCache);
126 if (inCache) 141 if (inCache)
127 return account; 142 return account;
128 143
@@ -135,7 +150,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
135 public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) 150 public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
136 { 151 {
137 bool inCache = false; 152 bool inCache = false;
138 UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache); 153 UserAccount account;
154 account = m_Cache.Get(firstName + " " + lastName, out inCache);
139 if (inCache) 155 if (inCache)
140 return account; 156 return account;
141 157
@@ -146,6 +162,45 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
146 return account; 162 return account;
147 } 163 }
148 164
165 public override List<UserAccount> GetUserAccounts(UUID scopeID, List<string> IDs)
166 {
167 List<UserAccount> accs = new List<UserAccount>();
168 List<string> missing = new List<string>();
169
170 UUID uuid = UUID.Zero;
171 UserAccount account;
172 bool inCache = false;
173
174 foreach(string id in IDs)
175 {
176 if(UUID.TryParse(id, out uuid))
177 {
178 account = m_Cache.Get(uuid, out inCache);
179 if (inCache)
180 accs.Add(account);
181 else
182 missing.Add(id);
183 }
184 }
185
186 if(missing.Count > 0)
187 {
188 List<UserAccount> ext = base.GetUserAccounts(scopeID, missing);
189 if(ext != null && ext.Count >0 )
190 {
191 foreach(UserAccount acc in ext)
192 {
193 if(acc != null)
194 {
195 accs.Add(acc);
196 m_Cache.Cache(acc.PrincipalID, acc);
197 }
198 }
199 }
200 }
201 return accs;
202 }
203
149 public override bool StoreUserAccount(UserAccount data) 204 public override bool StoreUserAccount(UserAccount data)
150 { 205 {
151 // This remote connector refuses to serve this method 206 // This remote connector refuses to serve this method
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
index ed52e48..f3572a2 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
@@ -34,68 +34,119 @@ using log4net;
34 34
35namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts 35namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
36{ 36{
37 public class UserAccountCache 37 public class UserAccountCache : IUserAccountCacheModule
38 { 38 {
39 private const double CACHE_EXPIRATION_SECONDS = 120000.0; // 33 hours! 39 private const double CACHE_ALIEN_EXPIRATION_SECONDS = 172800; // 48 hours
40 private const double CACHE_EXPIRATION_SECONDS = 3600.0; // 1 hour!
41 private const double CACHE_NULL_EXPIRATION_SECONDS = 600; // 10minutes
40 42
41// private static readonly ILog m_log = 43// private static readonly ILog m_log =
42// LogManager.GetLogger( 44// LogManager.GetLogger(
43// MethodBase.GetCurrentMethod().DeclaringType); 45// MethodBase.GetCurrentMethod().DeclaringType);
44 46
45 private ExpiringCache<UUID, UserAccount> m_UUIDCache; 47 private ExpiringCache<UUID, UserAccount> m_UUIDCache;
46 private ExpiringCache<string, UUID> m_NameCache; 48 private ExpiringCache<string, UUID> m_NameCache;
49 private object accessLock = new object();
47 50
48 public UserAccountCache() 51 public UserAccountCache()
49 { 52 {
50 m_UUIDCache = new ExpiringCache<UUID, UserAccount>(); 53 m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
51 m_NameCache = new ExpiringCache<string, UUID>(); 54 m_NameCache = new ExpiringCache<string, UUID>();
52 } 55 }
53 56
54 public void Cache(UUID userID, UserAccount account) 57 public void Cache(UUID userID, UserAccount account)
55 { 58 {
56 // Cache even null accounts 59 // Cache even null accounts
57 m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS); 60 lock(accessLock)
58 if (account != null) 61 {
59 m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS); 62 if (account == null)
60 63 m_UUIDCache.AddOrUpdate(userID, null, CACHE_NULL_EXPIRATION_SECONDS);
64 else if(account.LocalToGrid)
65 {
66 m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
67 m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
68 }
69 else
70 {
71 m_UUIDCache.AddOrUpdate(userID, account, CACHE_ALIEN_EXPIRATION_SECONDS);
72 m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_ALIEN_EXPIRATION_SECONDS);
73 }
61 //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID); 74 //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
75 }
62 } 76 }
63 77
64 public void Invalidate(UUID userID)
65 {
66 m_UUIDCache.Remove(userID);
67 }
68 78
69 public UserAccount Get(UUID userID, out bool inCache) 79 public UserAccount Get(UUID userID, out bool inCache)
70 { 80 {
71 UserAccount account = null; 81 UserAccount account = null;
72 inCache = false; 82 inCache = false;
73 if (m_UUIDCache.TryGetValue(userID, out account)) 83 lock(accessLock)
74 { 84 {
75 //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); 85 if (m_UUIDCache.TryGetValue(userID, out account))
76 inCache = true; 86 {
77 return account; 87 //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
88 inCache = true;
89 return account;
90 }
78 } 91 }
79
80 return null; 92 return null;
81 } 93 }
82 94
83 public UserAccount Get(string name, out bool inCache) 95 public UserAccount Get(string name, out bool inCache)
84 { 96 {
85 inCache = false; 97 inCache = false;
86 if (!m_NameCache.Contains(name)) 98 lock(accessLock)
87 return null; 99 {
100 if (!m_NameCache.Contains(name))
101 return null;
88 102
89 UserAccount account = null; 103 UserAccount account = null;
90 UUID uuid = UUID.Zero; 104 UUID uuid = UUID.Zero;
91 if (m_NameCache.TryGetValue(name, out uuid)) 105 if (m_NameCache.TryGetValue(name, out uuid))
92 if (m_UUIDCache.TryGetValue(uuid, out account))
93 { 106 {
94 inCache = true; 107 if (m_UUIDCache.TryGetValue(uuid, out account))
95 return account; 108 {
109 inCache = true;
110 return account;
111 }
96 } 112 }
97 113 }
98 return null; 114 return null;
99 } 115 }
116
117 public void Invalidate(UUID userID)
118 {
119 m_UUIDCache.Remove(userID);
120 }
121
122 public void Remove(UUID id)
123 {
124 lock(accessLock)
125 {
126 if (!m_UUIDCache.Contains(id))
127 return;
128
129 UserAccount account = null;
130 if (m_UUIDCache.TryGetValue(id, out account) && account != null)
131 m_NameCache.Remove(account.Name);
132 m_UUIDCache.Remove(id);
133 }
134 }
135
136 public void Remove(string name)
137 {
138 lock(accessLock)
139 {
140 if (!m_NameCache.Contains(name))
141 return;
142
143 UUID uuid = UUID.Zero;
144 if (m_NameCache.TryGetValue(name, out uuid))
145 {
146 m_NameCache.Remove(name);
147 m_UUIDCache.Remove(uuid);
148 }
149 }
150 }
100 } 151 }
101} 152}