aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs277
1 files changed, 0 insertions, 277 deletions
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
deleted file mode 100644
index acae4b1..0000000
--- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
+++ /dev/null
@@ -1,277 +0,0 @@
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
28using System.Collections.Generic;
29using System.Reflection;
30using log4net;
31using OpenMetaverse;
32using OpenSim.Services.Interfaces;
33
34namespace OpenSim.Framework.Communications.Cache
35{
36 /// <summary>
37 /// Holds user profile information and retrieves it from backend services.
38 /// </summary>
39 public class UserProfileCacheService
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 /// <value>
44 /// Standard format for names.
45 /// </value>
46 public const string NAME_FORMAT = "{0} {1}";
47
48 /// <summary>
49 /// The comms manager holds references to services (user, grid, inventory, etc.)
50 /// </summary>
51 private readonly CommunicationsManager m_commsManager;
52
53 /// <summary>
54 /// User profiles indexed by UUID
55 /// </summary>
56 private readonly Dictionary<UUID, CachedUserInfo> m_userProfilesById
57 = new Dictionary<UUID, CachedUserInfo>();
58
59 /// <summary>
60 /// User profiles indexed by name
61 /// </summary>
62 private readonly Dictionary<string, CachedUserInfo> m_userProfilesByName
63 = new Dictionary<string, CachedUserInfo>();
64
65 /// <summary>
66 /// The root library folder.
67 /// </summary>
68 public readonly InventoryFolderImpl LibraryRoot;
69
70 private IInventoryService m_InventoryService;
71
72 /// <summary>
73 /// Constructor
74 /// </summary>
75 /// <param name="commsManager"></param>
76 /// <param name="libraryRootFolder"></param>
77 public UserProfileCacheService(CommunicationsManager commsManager, LibraryRootFolder libraryRootFolder)
78 {
79 m_commsManager = commsManager;
80 LibraryRoot = libraryRootFolder;
81 }
82
83 public void SetInventoryService(IInventoryService invService)
84 {
85 m_InventoryService = invService;
86 }
87
88 /// <summary>
89 /// A new user has moved into a region in this instance so retrieve their profile from the user service.
90 /// </summary>
91 ///
92 /// It isn't strictly necessary to make this call since user data can be lazily requested later on. However,
93 /// it might be helpful in order to avoid an initial response delay later on
94 ///
95 /// <param name="userID"></param>
96 public void AddNewUser(UUID userID)
97 {
98 if (userID == UUID.Zero)
99 return;
100
101 //m_log.DebugFormat("[USER CACHE]: Adding user profile for {0}", userID);
102 GetUserDetails(userID);
103 }
104
105 /// <summary>
106 /// Remove this user's profile cache.
107 /// </summary>
108 /// <param name="userID"></param>
109 /// <returns>true if the user was successfully removed, false otherwise</returns>
110 public bool RemoveUser(UUID userId)
111 {
112 if (!RemoveFromCaches(userId))
113 {
114 m_log.WarnFormat(
115 "[USER CACHE]: Tried to remove the profile of user {0}, but this was not in the scene", userId);
116
117 return false;
118 }
119
120 return true;
121 }
122
123 /// <summary>
124 /// Get details of the given user.
125 /// </summary>
126 /// If the user isn't in cache then the user is requested from the profile service.
127 /// <param name="userID"></param>
128 /// <returns>null if no user details are found</returns>
129 public CachedUserInfo GetUserDetails(string fname, string lname)
130 {
131 lock (m_userProfilesByName)
132 {
133 CachedUserInfo userInfo;
134
135 if (m_userProfilesByName.TryGetValue(string.Format(NAME_FORMAT, fname, lname), out userInfo))
136 {
137 return userInfo;
138 }
139 else
140 {
141 UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(fname, lname);
142
143 if (userProfile != null)
144 {
145
146 if ((userProfile.UserAssetURI == null || userProfile.UserAssetURI == "") && m_commsManager.NetworkServersInfo != null)
147 userProfile.UserAssetURI = m_commsManager.NetworkServersInfo.AssetURL;
148 if ((userProfile.UserInventoryURI == null || userProfile.UserInventoryURI == "") && m_commsManager.NetworkServersInfo != null)
149 userProfile.UserInventoryURI = m_commsManager.NetworkServersInfo.InventoryURL;
150
151 return AddToCaches(userProfile);
152 }
153 else
154 return null;
155 }
156 }
157 }
158
159 /// <summary>
160 /// Get details of the given user.
161 /// </summary>
162 /// If the user isn't in cache then the user is requested from the profile service.
163 /// <param name="userID"></param>
164 /// <returns>null if no user details are found</returns>
165 public CachedUserInfo GetUserDetails(UUID userID)
166 {
167 if (userID == UUID.Zero)
168 return null;
169
170 lock (m_userProfilesById)
171 {
172 if (m_userProfilesById.ContainsKey(userID))
173 {
174 return m_userProfilesById[userID];
175 }
176 else
177 {
178 UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(userID);
179 if (userProfile != null)
180 {
181
182 if ((userProfile.UserAssetURI == null || userProfile.UserAssetURI == "") && m_commsManager.NetworkServersInfo != null)
183 userProfile.UserAssetURI = m_commsManager.NetworkServersInfo.AssetURL;
184 if ((userProfile.UserInventoryURI == null || userProfile.UserInventoryURI == "") && m_commsManager.NetworkServersInfo != null)
185 userProfile.UserInventoryURI = m_commsManager.NetworkServersInfo.InventoryURL;
186
187 return AddToCaches(userProfile);
188 }
189 else
190 return null;
191 }
192 }
193 }
194
195 /// <summary>
196 /// Update an existing profile
197 /// </summary>
198 /// <param name="userProfile"></param>
199 /// <returns>true if a user profile was found to update, false otherwise</returns>
200 // Commented out for now. The implementation needs to be improved by protecting against race conditions,
201 // probably by making sure that the update doesn't use the UserCacheInfo.UserProfile directly (possibly via
202 // returning a read only class from the cache).
203// public bool StoreProfile(UserProfileData userProfile)
204// {
205// lock (m_userProfilesById)
206// {
207// CachedUserInfo userInfo = GetUserDetails(userProfile.ID);
208//
209// if (userInfo != null)
210// {
211// userInfo.m_userProfile = userProfile;
212// m_commsManager.UserService.UpdateUserProfile(userProfile);
213//
214// return true;
215// }
216// }
217//
218// return false;
219// }
220
221 /// <summary>
222 /// Populate caches with the given user profile
223 /// </summary>
224 /// <param name="userProfile"></param>
225 protected CachedUserInfo AddToCaches(UserProfileData userProfile)
226 {
227 CachedUserInfo createdUserInfo = new CachedUserInfo(m_InventoryService, userProfile);
228
229 lock (m_userProfilesById)
230 {
231 m_userProfilesById[createdUserInfo.UserProfile.ID] = createdUserInfo;
232
233 lock (m_userProfilesByName)
234 {
235 m_userProfilesByName[createdUserInfo.UserProfile.Name] = createdUserInfo;
236 }
237 }
238
239 return createdUserInfo;
240 }
241
242 /// <summary>
243 /// Remove profile belong to the given uuid from the caches
244 /// </summary>
245 /// <param name="userUuid"></param>
246 /// <returns>true if there was a profile to remove, false otherwise</returns>
247 protected bool RemoveFromCaches(UUID userId)
248 {
249 lock (m_userProfilesById)
250 {
251 if (m_userProfilesById.ContainsKey(userId))
252 {
253 CachedUserInfo userInfo = m_userProfilesById[userId];
254 m_userProfilesById.Remove(userId);
255
256 lock (m_userProfilesByName)
257 {
258 m_userProfilesByName.Remove(userInfo.UserProfile.Name);
259 }
260
261 return true;
262 }
263 }
264
265 return false;
266 }
267
268 /// <summary>
269 /// Preloads User data into the region cache. Modules may use this service to add non-standard clients
270 /// </summary>
271 /// <param name="userData"></param>
272 public void PreloadUserCache(UserProfileData userData)
273 {
274 AddToCaches(userData);
275 }
276 }
277}