aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications')
-rw-r--r--OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs147
1 files changed, 105 insertions, 42 deletions
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
index b1ce3e7..4aed338 100644
--- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
+++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
@@ -39,16 +39,28 @@ namespace OpenSim.Framework.Communications.Cache
39 { 39 {
40 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 40 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41 41
42 /// <value>
43 /// Standard format for names.
44 /// </value>
45 public const string NAME_FORMAT = "{0} {1}";
46
42 /// <summary> 47 /// <summary>
43 /// The comms manager holds references to services (user, grid, inventory, etc.) 48 /// The comms manager holds references to services (user, grid, inventory, etc.)
44 /// </summary> 49 /// </summary>
45 private readonly CommunicationsManager m_commsManager; 50 private readonly CommunicationsManager m_commsManager;
46 51
47 /// <summary> 52 /// <summary>
48 /// Each user has a cached profile. 53 /// User profiles indexed by UUID
49 /// </summary> 54 /// </summary>
50 private readonly Dictionary<UUID, CachedUserInfo> m_userProfiles = new Dictionary<UUID, CachedUserInfo>(); 55 private readonly Dictionary<UUID, CachedUserInfo> m_userProfilesById
51 56 = new Dictionary<UUID, CachedUserInfo>();
57
58 /// <summary>
59 /// User profiles indexed by name
60 /// </summary>
61 private readonly Dictionary<string, CachedUserInfo> m_userProfilesByName
62 = new Dictionary<string, CachedUserInfo>();
63
52 /// <summary> 64 /// <summary>
53 /// The root library folder. 65 /// The root library folder.
54 /// </summary> 66 /// </summary>
@@ -89,25 +101,49 @@ namespace OpenSim.Framework.Communications.Cache
89 /// <returns>true if the user was successfully removed, false otherwise</returns> 101 /// <returns>true if the user was successfully removed, false otherwise</returns>
90 public bool RemoveUser(UUID userId) 102 public bool RemoveUser(UUID userId)
91 { 103 {
92 lock (m_userProfiles) 104 if (!RemoveFromCaches(userId))
93 { 105 {
94 if (m_userProfiles.ContainsKey(userId)) 106 m_log.WarnFormat(
95 { 107 "[USER CACHE]: Tried to remove the profile of user {0}, but this was not in the scene", userId);
96 m_userProfiles.Remove(userId); 108
97 return true; 109 return false;
98 }
99 } 110 }
100 111
101 m_log.WarnFormat( 112 return true;
102 "[USER CACHE]: Tried to remove the profile of user {0}, but this was not in the scene", userId);
103
104 return false;
105 } 113 }
106 114
107 /// <summary> 115 /// <summary>
108 /// Get cached details of the given user. If the user isn't in cache then the user is requested from the 116 /// Get details of the given user.
109 /// profile service.
110 /// </summary> 117 /// </summary>
118 /// If the user isn't in cache then the user is requested from the profile service.
119 /// <param name="userID"></param>
120 /// <returns>null if no user details are found</returns>
121 public CachedUserInfo GetUserDetails(string fname, string lname)
122 {
123 lock (m_userProfilesByName)
124 {
125 CachedUserInfo userInfo;
126
127 if (m_userProfilesByName.TryGetValue(string.Format(NAME_FORMAT, fname, lname), out userInfo))
128 {
129 return userInfo;
130 }
131 else
132 {
133 UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(fname, lname);
134
135 if (userProfile != null)
136 return AddToCaches(userProfile);
137 else
138 return null;
139 }
140 }
141 }
142
143 /// <summary>
144 /// Get details of the given user.
145 /// </summary>
146 /// If the user isn't in cache then the user is requested from the profile service.
111 /// <param name="userID"></param> 147 /// <param name="userID"></param>
112 /// <returns>null if no user details are found</returns> 148 /// <returns>null if no user details are found</returns>
113 public CachedUserInfo GetUserDetails(UUID userID) 149 public CachedUserInfo GetUserDetails(UUID userID)
@@ -115,51 +151,78 @@ namespace OpenSim.Framework.Communications.Cache
115 if (userID == UUID.Zero) 151 if (userID == UUID.Zero)
116 return null; 152 return null;
117 153
118 lock (m_userProfiles) 154 lock (m_userProfilesById)
119 { 155 {
120 if (m_userProfiles.ContainsKey(userID)) 156 if (m_userProfilesById.ContainsKey(userID))
121 { 157 {
122 return m_userProfiles[userID]; 158 return m_userProfilesById[userID];
123 } 159 }
124 else 160 else
125 { 161 {
126 UserProfileData userprofile = m_commsManager.UserService.GetUserProfile(userID); 162 UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(userID);
127 if (userprofile != null) 163 if (userProfile != null)
128 { 164 return AddToCaches(userProfile);
129 CachedUserInfo userinfo = new CachedUserInfo(m_commsManager, userprofile);
130 m_userProfiles.Add(userID, userinfo);
131 return userinfo;
132 }
133 else 165 else
134 {
135 return null; 166 return null;
136 }
137 } 167 }
138 } 168 }
139 } 169 }
140 170
141 /// <summary> 171 /// <summary>
142 /// Preloads User data into the region cache. Modules may use this service to add non-standard clients 172 /// Populate caches with the given user profile
143 /// </summary> 173 /// </summary>
144 /// <param name="userID"></param> 174 /// <param name="userProfile"></param>
145 /// <param name="userData"></param> 175 protected CachedUserInfo AddToCaches(UserProfileData userProfile)
146 public void PreloadUserCache(UUID userID, UserProfileData userData)
147 { 176 {
148 if (userID == UUID.Zero) 177 CachedUserInfo createdUserInfo = new CachedUserInfo(m_commsManager, userProfile);
149 return; 178
150 179 lock (m_userProfilesById)
151 lock (m_userProfiles)
152 { 180 {
153 if (m_userProfiles.ContainsKey(userID)) 181 m_userProfilesById[createdUserInfo.UserProfile.ID] = createdUserInfo;
182
183 lock (m_userProfilesByName)
154 { 184 {
155 return; 185 m_userProfilesByName[createdUserInfo.UserProfile.Name] = createdUserInfo;
156 } 186 }
157 else 187 }
188
189 return createdUserInfo;
190 }
191
192 /// <summary>
193 /// Remove profile belong to the given uuid from the caches
194 /// </summary>
195 /// <param name="userUuid"></param>
196 /// <returns>true if there was a profile to remove, false otherwise</returns>
197 protected bool RemoveFromCaches(UUID userId)
198 {
199 lock (m_userProfilesById)
200 {
201 if (m_userProfilesById.ContainsKey(userId))
158 { 202 {
159 CachedUserInfo userInfo = new CachedUserInfo(m_commsManager, userData); 203 CachedUserInfo userInfo = m_userProfilesById[userId];
160 m_userProfiles.Add(userID, userInfo); 204 m_userProfilesById.Remove(userId);
205
206 lock (m_userProfilesByName)
207 {
208 m_userProfilesByName.Remove(userInfo.UserProfile.Name);
209 }
210
211 return true;
161 } 212 }
162 } 213 }
214
215 return false;
216 }
217
218 /// <summary>
219 /// Preloads User data into the region cache. Modules may use this service to add non-standard clients
220 /// </summary>
221 /// <param name="userID"></param>
222 /// <param name="userData"></param>
223 public void PreloadUserCache(UUID userID, UserProfileData userData)
224 {
225 AddToCaches(userData);
163 } 226 }
164 } 227 }
165} 228}