diff options
author | lbsa71 | 2007-10-31 20:39:52 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-31 20:39:52 +0000 |
commit | b3aa6e616bbea8ee579070608888f2b43e818626 (patch) | |
tree | 310c77f18630540baaaa46c4143e0281c4ee9419 /OpenSim/Framework | |
parent | Improved logging, to identify which asset fetch caused an execption during re... (diff) | |
download | opensim-SC-b3aa6e616bbea8ee579070608888f2b43e818626.zip opensim-SC-b3aa6e616bbea8ee579070608888f2b43e818626.tar.gz opensim-SC-b3aa6e616bbea8ee579070608888f2b43e818626.tar.bz2 opensim-SC-b3aa6e616bbea8ee579070608888f2b43e818626.tar.xz |
* Took a stab at #500 by making sure there is only one place stuff gets added, and that that place is thread-aware.
* Refactored it to TryGetValue instead of Contains
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/UserProfileCache.cs | 114 |
1 files changed, 37 insertions, 77 deletions
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs index fe943b0..ccf5024 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs | |||
@@ -33,8 +33,8 @@ namespace OpenSim.Framework.Communications.Cache | |||
33 | public class UserProfileCache | 33 | public class UserProfileCache |
34 | { | 34 | { |
35 | // Fields | 35 | // Fields |
36 | private CommunicationsManager m_parent; | 36 | private readonly CommunicationsManager m_parent; |
37 | public Dictionary<LLUUID, CachedUserInfo> UserProfiles = new Dictionary<LLUUID, CachedUserInfo>(); | 37 | private readonly Dictionary<LLUUID, CachedUserInfo> m_userProfiles = new Dictionary<LLUUID, CachedUserInfo>(); |
38 | 38 | ||
39 | public LibraryRootFolder libraryRoot = new LibraryRootFolder(); | 39 | public LibraryRootFolder libraryRoot = new LibraryRootFolder(); |
40 | 40 | ||
@@ -52,16 +52,17 @@ namespace OpenSim.Framework.Communications.Cache | |||
52 | public void AddNewUser(LLUUID userID) | 52 | public void AddNewUser(LLUUID userID) |
53 | { | 53 | { |
54 | // Potential fix - Multithreading issue. | 54 | // Potential fix - Multithreading issue. |
55 | lock (UserProfiles) | 55 | lock (m_userProfiles) |
56 | { | 56 | { |
57 | if (!UserProfiles.ContainsKey(userID)) | 57 | if (!m_userProfiles.ContainsKey(userID)) |
58 | { | 58 | { |
59 | CachedUserInfo userInfo = new CachedUserInfo(m_parent); | 59 | CachedUserInfo userInfo = new CachedUserInfo(m_parent); |
60 | userInfo.UserProfile = RequestUserProfileForUser(userID); | 60 | userInfo.UserProfile = m_parent.UserService.GetUserProfile(userID); |
61 | |||
61 | if (userInfo.UserProfile != null) | 62 | if (userInfo.UserProfile != null) |
62 | { | 63 | { |
63 | RequestInventoryForUser(userID, userInfo); | 64 | RequestInventoryForUser(userID, userInfo); |
64 | UserProfiles.Add(userID, userInfo); | 65 | m_userProfiles.Add(userID, userInfo); |
65 | } | 66 | } |
66 | else | 67 | else |
67 | { | 68 | { |
@@ -71,37 +72,25 @@ namespace OpenSim.Framework.Communications.Cache | |||
71 | } | 72 | } |
72 | } | 73 | } |
73 | 74 | ||
74 | /// <summary> | ||
75 | /// A new user has moved into a region in this instance | ||
76 | /// so get info from servers | ||
77 | /// </summary> | ||
78 | /// <param name="firstName"></param> | ||
79 | /// <param name="lastName"></param> | ||
80 | public void AddNewUser(string firstName, string lastName) | ||
81 | { | ||
82 | } | ||
83 | |||
84 | public CachedUserInfo GetUserDetails(LLUUID userID) | 75 | public CachedUserInfo GetUserDetails(LLUUID userID) |
85 | { | 76 | { |
86 | if (UserProfiles.ContainsKey(userID)) | 77 | return m_userProfiles[userID]; |
87 | { | ||
88 | return UserProfiles[userID]; | ||
89 | } | ||
90 | return null; | ||
91 | } | 78 | } |
92 | 79 | ||
93 | public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, | 80 | public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, |
94 | string folderName, LLUUID parentID) | 81 | string folderName, LLUUID parentID) |
95 | { | 82 | { |
96 | if (UserProfiles.ContainsKey(remoteClient.AgentId)) | 83 | CachedUserInfo userProfile; |
84 | |||
85 | if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) | ||
97 | { | 86 | { |
98 | if (UserProfiles[remoteClient.AgentId].RootFolder != null) | 87 | if (userProfile.RootFolder != null) |
99 | { | 88 | { |
100 | CachedUserInfo info = UserProfiles[remoteClient.AgentId]; | 89 | if (userProfile.RootFolder.folderID == parentID) |
101 | if (info.RootFolder.folderID == parentID) | ||
102 | { | 90 | { |
103 | InventoryFolderImpl createdFolder = | 91 | InventoryFolderImpl createdFolder = |
104 | info.RootFolder.CreateNewSubFolder(folderID, folderName, folderType); | 92 | userProfile.RootFolder.CreateNewSubFolder(folderID, folderName, folderType); |
93 | |||
105 | if (createdFolder != null) | 94 | if (createdFolder != null) |
106 | { | 95 | { |
107 | m_parent.InventoryService.AddNewInventoryFolder(remoteClient.AgentId, createdFolder); | 96 | m_parent.InventoryService.AddNewInventoryFolder(remoteClient.AgentId, createdFolder); |
@@ -109,7 +98,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
109 | } | 98 | } |
110 | else | 99 | else |
111 | { | 100 | { |
112 | InventoryFolderImpl folder = info.RootFolder.HasSubFolder(parentID); | 101 | InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(parentID); |
113 | if (folder != null) | 102 | if (folder != null) |
114 | { | 103 | { |
115 | folder.CreateNewSubFolder(folderID, folderName, folderType); | 104 | folder.CreateNewSubFolder(folderID, folderName, folderType); |
@@ -127,27 +116,33 @@ namespace OpenSim.Framework.Communications.Cache | |||
127 | { | 116 | { |
128 | remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, libraryRoot.folderID, | 117 | remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, libraryRoot.folderID, |
129 | libraryRoot.RequestListOfItems()); | 118 | libraryRoot.RequestListOfItems()); |
119 | |||
120 | return; | ||
130 | } | 121 | } |
131 | else if ((fold = libraryRoot.HasSubFolder(folderID)) != null) | 122 | |
123 | if ((fold = libraryRoot.HasSubFolder(folderID)) != null) | ||
132 | { | 124 | { |
133 | remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, folderID, fold.RequestListOfItems()); | 125 | remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, folderID, fold.RequestListOfItems()); |
126 | |||
127 | return; | ||
134 | } | 128 | } |
135 | else if (UserProfiles.ContainsKey(remoteClient.AgentId)) | 129 | |
136 | { | 130 | CachedUserInfo userProfile; |
137 | if (UserProfiles[remoteClient.AgentId].RootFolder != null) | 131 | if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) |
132 | { | ||
133 | if (userProfile.RootFolder != null) | ||
138 | { | 134 | { |
139 | CachedUserInfo info = UserProfiles[remoteClient.AgentId]; | 135 | if (userProfile.RootFolder.folderID == folderID) |
140 | if (info.RootFolder.folderID == folderID) | ||
141 | { | 136 | { |
142 | if (fetchItems) | 137 | if (fetchItems) |
143 | { | 138 | { |
144 | remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, | 139 | remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, |
145 | info.RootFolder.RequestListOfItems()); | 140 | userProfile.RootFolder.RequestListOfItems()); |
146 | } | 141 | } |
147 | } | 142 | } |
148 | else | 143 | else |
149 | { | 144 | { |
150 | InventoryFolderImpl folder = info.RootFolder.HasSubFolder(folderID); | 145 | InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(folderID); |
151 | if ((folder != null) && fetchItems) | 146 | if ((folder != null) && fetchItems) |
152 | { | 147 | { |
153 | remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, | 148 | remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, |
@@ -163,12 +158,16 @@ namespace OpenSim.Framework.Communications.Cache | |||
163 | if (ownerID == libraryRoot.agentID) | 158 | if (ownerID == libraryRoot.agentID) |
164 | { | 159 | { |
165 | //Console.WriteLine("request info for library item"); | 160 | //Console.WriteLine("request info for library item"); |
161 | |||
162 | return; | ||
166 | } | 163 | } |
167 | else if (UserProfiles.ContainsKey(remoteClient.AgentId)) | 164 | |
165 | CachedUserInfo userProfile; | ||
166 | if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) | ||
168 | { | 167 | { |
169 | if (UserProfiles[remoteClient.AgentId].RootFolder != null) | 168 | if (userProfile.RootFolder != null) |
170 | { | 169 | { |
171 | InventoryItemBase item = UserProfiles[remoteClient.AgentId].RootFolder.HasItem(itemID); | 170 | InventoryItemBase item = userProfile.RootFolder.HasItem(itemID); |
172 | if (item != null) | 171 | if (item != null) |
173 | { | 172 | { |
174 | remoteClient.SendInventoryItemDetails(ownerID, item); | 173 | remoteClient.SendInventoryItemDetails(ownerID, item); |
@@ -177,48 +176,9 @@ namespace OpenSim.Framework.Communications.Cache | |||
177 | } | 176 | } |
178 | } | 177 | } |
179 | 178 | ||
180 | /// <summary> | ||
181 | /// Request Iventory Info from Inventory server | ||
182 | /// </summary> | ||
183 | /// <param name="userID"></param> | ||
184 | private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo) | 179 | private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo) |
185 | { | 180 | { |
186 | m_parent.InventoryService.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive); | 181 | m_parent.InventoryService.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive); |
187 | } | 182 | } |
188 | |||
189 | /// <summary> | ||
190 | /// Request the user profile from User server | ||
191 | /// </summary> | ||
192 | /// <param name="userID"></param> | ||
193 | private UserProfileData RequestUserProfileForUser(LLUUID userID) | ||
194 | { | ||
195 | return m_parent.UserService.GetUserProfile(userID); | ||
196 | } | ||
197 | |||
198 | /// <summary> | ||
199 | /// Update Inventory data to Inventory server | ||
200 | /// </summary> | ||
201 | /// <param name="userID"></param> | ||
202 | private void UpdateInventoryToServer(LLUUID userID) | ||
203 | { | ||
204 | } | ||
205 | |||
206 | /// <summary> | ||
207 | /// Make sure UserProfile is updated on user server | ||
208 | /// </summary> | ||
209 | /// <param name="userID"></param> | ||
210 | private void UpdateUserProfileToServer(LLUUID userID) | ||
211 | { | ||
212 | } | ||
213 | |||
214 | /// <summary> | ||
215 | /// A user has left this instance | ||
216 | /// so make sure servers have been updated | ||
217 | /// Then remove cached info | ||
218 | /// </summary> | ||
219 | /// <param name="userID"></param> | ||
220 | public void UserLogOut(LLUUID userID) | ||
221 | { | ||
222 | } | ||
223 | } | 183 | } |
224 | } \ No newline at end of file | 184 | } \ No newline at end of file |