diff options
Update svn properties. Minor formatting cleanup.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs | 496 |
1 files changed, 248 insertions, 248 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs index 4f63fd0..a450cdc 100644 --- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs +++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs | |||
@@ -1,249 +1,249 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Reflection; | 29 | using System.Reflection; |
30 | using libsecondlife; | 30 | using libsecondlife; |
31 | using log4net; | 31 | using log4net; |
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Framework.Communications.Limit; | 33 | using OpenSim.Framework.Communications.Limit; |
34 | using OpenSim.Region.Environment.Interfaces; | 34 | using OpenSim.Region.Environment.Interfaces; |
35 | using OpenSim.Region.Environment.Scenes; | 35 | using OpenSim.Region.Environment.Scenes; |
36 | 36 | ||
37 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | 37 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload |
38 | { | 38 | { |
39 | /// <summary> | 39 | /// <summary> |
40 | /// This module sets up texture senders in response to client texture requests, and places them on a | 40 | /// This module sets up texture senders in response to client texture requests, and places them on a |
41 | /// processing queue once those senders have the appropriate data (i.e. a texture retrieved from the | 41 | /// processing queue once those senders have the appropriate data (i.e. a texture retrieved from the |
42 | /// asset cache). | 42 | /// asset cache). |
43 | /// </summary> | 43 | /// </summary> |
44 | public class UserTextureDownloadService | 44 | public class UserTextureDownloadService |
45 | { | 45 | { |
46 | private static readonly ILog m_log | 46 | private static readonly ILog m_log |
47 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | /// <summary> | 49 | /// <summary> |
50 | /// We will allow the client to request the same texture n times before dropping further requests | 50 | /// We will allow the client to request the same texture n times before dropping further requests |
51 | /// | 51 | /// |
52 | /// This number includes repeated requests for the same texture at different resolutions (which we don't | 52 | /// This number includes repeated requests for the same texture at different resolutions (which we don't |
53 | /// currently handle properly as far as I know). However, this situation should be handled in a more | 53 | /// currently handle properly as far as I know). However, this situation should be handled in a more |
54 | /// sophisticated way. | 54 | /// sophisticated way. |
55 | /// </summary> | 55 | /// </summary> |
56 | private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 5; | 56 | private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 5; |
57 | 57 | ||
58 | /// <summary> | 58 | /// <summary> |
59 | /// XXX Also going to limit requests for found textures. | 59 | /// XXX Also going to limit requests for found textures. |
60 | /// </summary> | 60 | /// </summary> |
61 | private readonly IRequestLimitStrategy<LLUUID> foundTextureLimitStrategy | 61 | private readonly IRequestLimitStrategy<LLUUID> foundTextureLimitStrategy |
62 | = new RepeatLimitStrategy<LLUUID>(MAX_ALLOWED_TEXTURE_REQUESTS); | 62 | = new RepeatLimitStrategy<LLUUID>(MAX_ALLOWED_TEXTURE_REQUESTS); |
63 | 63 | ||
64 | private readonly IClientAPI m_client; | 64 | private readonly IClientAPI m_client; |
65 | private readonly Scene m_scene; | 65 | private readonly Scene m_scene; |
66 | 66 | ||
67 | /// <summary> | 67 | /// <summary> |
68 | /// Texture Senders are placed in this queue once they have received their texture from the asset | 68 | /// Texture Senders are placed in this queue once they have received their texture from the asset |
69 | /// cache. Another module actually invokes the send. | 69 | /// cache. Another module actually invokes the send. |
70 | /// </summary> | 70 | /// </summary> |
71 | private readonly BlockingQueue<ITextureSender> m_sharedSendersQueue; | 71 | private readonly BlockingQueue<ITextureSender> m_sharedSendersQueue; |
72 | 72 | ||
73 | /// <summary> | 73 | /// <summary> |
74 | /// Holds texture senders before they have received the appropriate texture from the asset cache. | 74 | /// Holds texture senders before they have received the appropriate texture from the asset cache. |
75 | /// </summary> | 75 | /// </summary> |
76 | private readonly Dictionary<LLUUID, TextureSender.TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender.TextureSender>(); | 76 | private readonly Dictionary<LLUUID, TextureSender.TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender.TextureSender>(); |
77 | 77 | ||
78 | /// <summary> | 78 | /// <summary> |
79 | /// We're going to limit requests for the same missing texture. | 79 | /// We're going to limit requests for the same missing texture. |
80 | /// XXX This is really a temporary solution to deal with the situation where a client continually requests | 80 | /// XXX This is really a temporary solution to deal with the situation where a client continually requests |
81 | /// the same missing textures | 81 | /// the same missing textures |
82 | /// </summary> | 82 | /// </summary> |
83 | private readonly IRequestLimitStrategy<LLUUID> missingTextureLimitStrategy | 83 | private readonly IRequestLimitStrategy<LLUUID> missingTextureLimitStrategy |
84 | = new RepeatLimitStrategy<LLUUID>(MAX_ALLOWED_TEXTURE_REQUESTS); | 84 | = new RepeatLimitStrategy<LLUUID>(MAX_ALLOWED_TEXTURE_REQUESTS); |
85 | 85 | ||
86 | public UserTextureDownloadService( | 86 | public UserTextureDownloadService( |
87 | IClientAPI client, Scene scene, BlockingQueue<ITextureSender> sharedQueue) | 87 | IClientAPI client, Scene scene, BlockingQueue<ITextureSender> sharedQueue) |
88 | { | 88 | { |
89 | m_client = client; | 89 | m_client = client; |
90 | m_scene = scene; | 90 | m_scene = scene; |
91 | m_sharedSendersQueue = sharedQueue; | 91 | m_sharedSendersQueue = sharedQueue; |
92 | } | 92 | } |
93 | 93 | ||
94 | /// <summary> | 94 | /// <summary> |
95 | /// Handle a texture request. This involves creating a texture sender and placing it on the | 95 | /// Handle a texture request. This involves creating a texture sender and placing it on the |
96 | /// previously passed in shared queue. | 96 | /// previously passed in shared queue. |
97 | /// </summary> | 97 | /// </summary> |
98 | /// <param name="e"></param> | 98 | /// <param name="e"></param> |
99 | public void HandleTextureRequest(TextureRequestArgs e) | 99 | public void HandleTextureRequest(TextureRequestArgs e) |
100 | { | 100 | { |
101 | TextureSender.TextureSender textureSender; | 101 | TextureSender.TextureSender textureSender; |
102 | 102 | ||
103 | //TODO: should be working out the data size/ number of packets to be sent for each discard level | 103 | //TODO: should be working out the data size/ number of packets to be sent for each discard level |
104 | if ((e.DiscardLevel >= 0) || (e.Priority != 0)) | 104 | if ((e.DiscardLevel >= 0) || (e.Priority != 0)) |
105 | { | 105 | { |
106 | lock (m_textureSenders) | 106 | lock (m_textureSenders) |
107 | { | 107 | { |
108 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | 108 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) |
109 | { | 109 | { |
110 | // If we've received new non UUID information for this request and it hasn't dispatched | 110 | // If we've received new non UUID information for this request and it hasn't dispatched |
111 | // yet, then update the request accordingly. | 111 | // yet, then update the request accordingly. |
112 | textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber); | 112 | textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber); |
113 | } | 113 | } |
114 | else | 114 | else |
115 | { | 115 | { |
116 | if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) | 116 | if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) |
117 | { | 117 | { |
118 | // m_log.DebugFormat( | 118 | // m_log.DebugFormat( |
119 | // "[USER TEXTURE DOWNLOAD SERVICE]: Refusing request for {0} from client {1}", | 119 | // "[USER TEXTURE DOWNLOAD SERVICE]: Refusing request for {0} from client {1}", |
120 | // e.RequestedAssetID, m_client.AgentId); | 120 | // e.RequestedAssetID, m_client.AgentId); |
121 | 121 | ||
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | else if (!missingTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) | 124 | else if (!missingTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) |
125 | { | 125 | { |
126 | if (missingTextureLimitStrategy.IsFirstRefusal(e.RequestedAssetID)) | 126 | if (missingTextureLimitStrategy.IsFirstRefusal(e.RequestedAssetID)) |
127 | { | 127 | { |
128 | // Commenting out this message for now as it causes too much noise with other | 128 | // Commenting out this message for now as it causes too much noise with other |
129 | // debug messages. | 129 | // debug messages. |
130 | // TODO: possibly record this as a statistic in the future | 130 | // TODO: possibly record this as a statistic in the future |
131 | // | 131 | // |
132 | // m_log.DebugFormat( | 132 | // m_log.DebugFormat( |
133 | // "[USER TEXTURE DOWNLOAD SERVICE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests", | 133 | // "[USER TEXTURE DOWNLOAD SERVICE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests", |
134 | // e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS); | 134 | // e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS); |
135 | } | 135 | } |
136 | 136 | ||
137 | return; | 137 | return; |
138 | } | 138 | } |
139 | 139 | ||
140 | m_scene.AddPendingDownloads(1); | 140 | m_scene.AddPendingDownloads(1); |
141 | 141 | ||
142 | TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber); | 142 | TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber); |
143 | m_textureSenders.Add(e.RequestedAssetID, requestHandler); | 143 | m_textureSenders.Add(e.RequestedAssetID, requestHandler); |
144 | 144 | ||
145 | m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true); | 145 | m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | } | 148 | } |
149 | else | 149 | else |
150 | { | 150 | { |
151 | lock (m_textureSenders) | 151 | lock (m_textureSenders) |
152 | { | 152 | { |
153 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | 153 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) |
154 | { | 154 | { |
155 | textureSender.Cancel = true; | 155 | textureSender.Cancel = true; |
156 | } | 156 | } |
157 | } | 157 | } |
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | /// <summary> | 161 | /// <summary> |
162 | /// The callback for the asset cache when a texture has been retrieved. This method queues the | 162 | /// The callback for the asset cache when a texture has been retrieved. This method queues the |
163 | /// texture sender for processing. | 163 | /// texture sender for processing. |
164 | /// </summary> | 164 | /// </summary> |
165 | /// <param name="textureID"></param> | 165 | /// <param name="textureID"></param> |
166 | /// <param name="texture"></param> | 166 | /// <param name="texture"></param> |
167 | public void TextureCallback(LLUUID textureID, AssetBase texture) | 167 | public void TextureCallback(LLUUID textureID, AssetBase texture) |
168 | { | 168 | { |
169 | //m_log.DebugFormat("[USER TEXTURE DOWNLOAD SERVICE]: Calling TextureCallback with {0}, texture == null is {1}", textureID, (texture == null ? true : false)); | 169 | //m_log.DebugFormat("[USER TEXTURE DOWNLOAD SERVICE]: Calling TextureCallback with {0}, texture == null is {1}", textureID, (texture == null ? true : false)); |
170 | 170 | ||
171 | lock (m_textureSenders) | 171 | lock (m_textureSenders) |
172 | { | 172 | { |
173 | TextureSender.TextureSender textureSender; | 173 | TextureSender.TextureSender textureSender; |
174 | 174 | ||
175 | if (m_textureSenders.TryGetValue(textureID, out textureSender)) | 175 | if (m_textureSenders.TryGetValue(textureID, out textureSender)) |
176 | { | 176 | { |
177 | // XXX It may be perfectly valid for a texture to have no data... but if we pass | 177 | // XXX It may be perfectly valid for a texture to have no data... but if we pass |
178 | // this on to the TextureSender it will blow up, so just discard for now. | 178 | // this on to the TextureSender it will blow up, so just discard for now. |
179 | // Needs investigation. | 179 | // Needs investigation. |
180 | if (texture == null || texture.Data == null) | 180 | if (texture == null || texture.Data == null) |
181 | { | 181 | { |
182 | if (!missingTextureLimitStrategy.IsMonitoringRequests(textureID)) | 182 | if (!missingTextureLimitStrategy.IsMonitoringRequests(textureID)) |
183 | { | 183 | { |
184 | missingTextureLimitStrategy.MonitorRequests(textureID); | 184 | missingTextureLimitStrategy.MonitorRequests(textureID); |
185 | 185 | ||
186 | m_log.DebugFormat( | 186 | m_log.DebugFormat( |
187 | "[USER TEXTURE DOWNLOAD SERVICE]: Queueing first TextureNotFoundSender for {0}, client {1}", | 187 | "[USER TEXTURE DOWNLOAD SERVICE]: Queueing first TextureNotFoundSender for {0}, client {1}", |
188 | textureID, m_client.AgentId); | 188 | textureID, m_client.AgentId); |
189 | } | 189 | } |
190 | 190 | ||
191 | ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID); | 191 | ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID); |
192 | EnqueueTextureSender(textureNotFoundSender); | 192 | EnqueueTextureSender(textureNotFoundSender); |
193 | } | 193 | } |
194 | else | 194 | else |
195 | { | 195 | { |
196 | if (!textureSender.ImageLoaded) | 196 | if (!textureSender.ImageLoaded) |
197 | { | 197 | { |
198 | textureSender.TextureReceived(texture); | 198 | textureSender.TextureReceived(texture); |
199 | EnqueueTextureSender(textureSender); | 199 | EnqueueTextureSender(textureSender); |
200 | 200 | ||
201 | foundTextureLimitStrategy.MonitorRequests(textureID); | 201 | foundTextureLimitStrategy.MonitorRequests(textureID); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | //m_log.InfoFormat("[TEXTURE SENDER] Removing texture sender with uuid {0}", textureID); | 205 | //m_log.InfoFormat("[TEXTURE SENDER] Removing texture sender with uuid {0}", textureID); |
206 | m_textureSenders.Remove(textureID); | 206 | m_textureSenders.Remove(textureID); |
207 | //m_log.InfoFormat("[TEXTURE SENDER] Current texture senders in dictionary: {0}", m_textureSenders.Count); | 207 | //m_log.InfoFormat("[TEXTURE SENDER] Current texture senders in dictionary: {0}", m_textureSenders.Count); |
208 | } | 208 | } |
209 | else | 209 | else |
210 | { | 210 | { |
211 | m_log.WarnFormat( | 211 | m_log.WarnFormat( |
212 | "Got a texture uuid {0} with no sender object to handle it, this shouldn't happen", | 212 | "Got a texture uuid {0} with no sender object to handle it, this shouldn't happen", |
213 | textureID); | 213 | textureID); |
214 | } | 214 | } |
215 | } | 215 | } |
216 | } | 216 | } |
217 | 217 | ||
218 | /// <summary> | 218 | /// <summary> |
219 | /// Place a ready texture sender on the processing queue. | 219 | /// Place a ready texture sender on the processing queue. |
220 | /// </summary> | 220 | /// </summary> |
221 | /// <param name="textureSender"></param> | 221 | /// <param name="textureSender"></param> |
222 | private void EnqueueTextureSender(ITextureSender textureSender) | 222 | private void EnqueueTextureSender(ITextureSender textureSender) |
223 | { | 223 | { |
224 | textureSender.Cancel = false; | 224 | textureSender.Cancel = false; |
225 | textureSender.Sending = true; | 225 | textureSender.Sending = true; |
226 | 226 | ||
227 | if (!m_sharedSendersQueue.Contains(textureSender)) | 227 | if (!m_sharedSendersQueue.Contains(textureSender)) |
228 | { | 228 | { |
229 | m_sharedSendersQueue.Enqueue(textureSender); | 229 | m_sharedSendersQueue.Enqueue(textureSender); |
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | /// <summary> | 233 | /// <summary> |
234 | /// Close this module. | 234 | /// Close this module. |
235 | /// </summary> | 235 | /// </summary> |
236 | internal void Close() | 236 | internal void Close() |
237 | { | 237 | { |
238 | lock (m_textureSenders) | 238 | lock (m_textureSenders) |
239 | { | 239 | { |
240 | foreach (TextureSender.TextureSender textureSender in m_textureSenders.Values) | 240 | foreach (TextureSender.TextureSender textureSender in m_textureSenders.Values) |
241 | { | 241 | { |
242 | textureSender.Cancel = true; | 242 | textureSender.Cancel = true; |
243 | } | 243 | } |
244 | 244 | ||
245 | m_textureSenders.Clear(); | 245 | m_textureSenders.Clear(); |
246 | } | 246 | } |
247 | } | 247 | } |
248 | } | 248 | } |
249 | } \ No newline at end of file | 249 | } \ No newline at end of file |