aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs267
1 files changed, 0 insertions, 267 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
deleted file mode 100644
index 38d96db..0000000
--- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
+++ /dev/null
@@ -1,267 +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 OpenSim 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 OpenMetaverse;
31using log4net;
32using OpenSim.Framework;
33using OpenSim.Framework.Communications.Limit;
34using OpenSim.Framework.Statistics;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37
38namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
39{
40 /// <summary>
41 /// This module sets up texture senders in response to client texture requests, and places them on a
42 /// processing queue once those senders have the appropriate data (i.e. a texture retrieved from the
43 /// asset cache).
44 /// </summary>
45 public class UserTextureDownloadService
46 {
47 private static readonly ILog m_log
48 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 /// <summary>
51 /// True if the service has been closed, probably because a user with texture requests still queued
52 /// logged out.
53 /// </summary>
54 private bool closed;
55
56 /// <summary>
57 /// We will allow the client to request the same texture n times before dropping further requests
58 ///
59 /// This number includes repeated requests for the same texture at different resolutions (which we don't
60 /// currently handle properly as far as I know). However, this situation should be handled in a more
61 /// sophisticated way.
62 /// </summary>
63 private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 5;
64
65 /// <summary>
66 /// XXX Also going to limit requests for found textures.
67 /// </summary>
68 private readonly IRequestLimitStrategy<UUID> foundTextureLimitStrategy
69 = new RepeatLimitStrategy<UUID>(MAX_ALLOWED_TEXTURE_REQUESTS);
70
71 private readonly IClientAPI m_client;
72 private readonly Scene m_scene;
73
74 /// <summary>
75 /// Texture Senders are placed in this queue once they have received their texture from the asset
76 /// cache. Another module actually invokes the send.
77 /// </summary>
78 private readonly OpenSim.Framework.BlockingQueue<ITextureSender> m_sharedSendersQueue;
79
80 /// <summary>
81 /// Holds texture senders before they have received the appropriate texture from the asset cache.
82 /// </summary>
83 private readonly Dictionary<UUID, TextureSender.TextureSender> m_textureSenders = new Dictionary<UUID, TextureSender.TextureSender>();
84
85 /// <summary>
86 /// We're going to limit requests for the same missing texture.
87 /// XXX This is really a temporary solution to deal with the situation where a client continually requests
88 /// the same missing textures
89 /// </summary>
90 private readonly IRequestLimitStrategy<UUID> missingTextureLimitStrategy
91 = new RepeatLimitStrategy<UUID>(MAX_ALLOWED_TEXTURE_REQUESTS);
92
93 public UserTextureDownloadService(
94 IClientAPI client, Scene scene, OpenSim.Framework.BlockingQueue<ITextureSender> sharedQueue)
95 {
96 m_client = client;
97 m_scene = scene;
98 m_sharedSendersQueue = sharedQueue;
99 }
100
101 /// <summary>
102 /// Handle a texture request. This involves creating a texture sender and placing it on the
103 /// previously passed in shared queue.
104 /// </summary>
105 /// <param name="e"></param>
106 public void HandleTextureRequest(TextureRequestArgs e)
107 {
108 TextureSender.TextureSender textureSender;
109
110 //TODO: should be working out the data size/ number of packets to be sent for each discard level
111 if ((e.DiscardLevel >= 0) || (e.Priority != 0))
112 {
113 lock (m_textureSenders)
114 {
115 if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender))
116 {
117 // If we've received new non UUID information for this request and it hasn't dispatched
118 // yet, then update the request accordingly.
119 textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber);
120 }
121 else
122 {
123 // m_log.DebugFormat("[TEXTURE]: Received a request for texture {0}", e.RequestedAssetID);
124
125 if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID))
126 {
127 // m_log.DebugFormat(
128 // "[TEXTURE]: Refusing request for {0} from client {1}",
129 // e.RequestedAssetID, m_client.AgentId);
130
131 return;
132 }
133 else if (!missingTextureLimitStrategy.AllowRequest(e.RequestedAssetID))
134 {
135 if (missingTextureLimitStrategy.IsFirstRefusal(e.RequestedAssetID))
136 {
137 if (StatsManager.SimExtraStats != null)
138 StatsManager.SimExtraStats.AddBlockedMissingTextureRequest();
139
140 // Commenting out this message for now as it causes too much noise with other
141 // debug messages.
142 // m_log.DebugFormat(
143 // "[TEXTURE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests",
144 // e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS);
145 }
146
147 return;
148 }
149
150 m_scene.AddPendingDownloads(1);
151
152 TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber);
153 m_textureSenders.Add(e.RequestedAssetID, requestHandler);
154
155 m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true);
156 }
157 }
158 }
159 else
160 {
161 lock (m_textureSenders)
162 {
163 if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender))
164 {
165 textureSender.Cancel = true;
166 }
167 }
168 }
169 }
170
171 /// <summary>
172 /// The callback for the asset cache when a texture has been retrieved. This method queues the
173 /// texture sender for processing.
174 /// </summary>
175 /// <param name="textureID"></param>
176 /// <param name="texture"></param>
177 public void TextureCallback(UUID textureID, AssetBase texture)
178 {
179 //m_log.DebugFormat("[USER TEXTURE DOWNLOAD SERVICE]: Calling TextureCallback with {0}, texture == null is {1}", textureID, (texture == null ? true : false));
180
181 // There may still be texture requests pending for a logged out client
182 if (closed)
183 return;
184
185 lock (m_textureSenders)
186 {
187 TextureSender.TextureSender textureSender;
188 if (m_textureSenders.TryGetValue(textureID, out textureSender))
189 {
190 // XXX It may be perfectly valid for a texture to have no data... but if we pass
191 // this on to the TextureSender it will blow up, so just discard for now.
192 // Needs investigation.
193 if (texture == null || texture.Data == null)
194 {
195 if (!missingTextureLimitStrategy.IsMonitoringRequests(textureID))
196 {
197 missingTextureLimitStrategy.MonitorRequests(textureID);
198
199 // m_log.DebugFormat(
200 // "[TEXTURE]: Queueing first TextureNotFoundSender for {0}, client {1}",
201 // textureID, m_client.AgentId);
202 }
203
204 ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID);
205 EnqueueTextureSender(textureNotFoundSender);
206 }
207 else
208 {
209 if (!textureSender.ImageLoaded)
210 {
211 textureSender.TextureReceived(texture);
212 EnqueueTextureSender(textureSender);
213
214 foundTextureLimitStrategy.MonitorRequests(textureID);
215 }
216 }
217
218 //m_log.InfoFormat("[TEXTURE] Removing texture sender with uuid {0}", textureID);
219 m_textureSenders.Remove(textureID);
220 //m_log.InfoFormat("[TEXTURE] Current texture senders in dictionary: {0}", m_textureSenders.Count);
221 }
222 else
223 {
224 m_log.WarnFormat(
225 "[TEXTURE]: Got a texture uuid {0} with no sender object to handle it, this shouldn't happen",
226 textureID);
227 }
228 }
229 }
230
231 /// <summary>
232 /// Place a ready texture sender on the processing queue.
233 /// </summary>
234 /// <param name="textureSender"></param>
235 private void EnqueueTextureSender(ITextureSender textureSender)
236 {
237 textureSender.Cancel = false;
238 textureSender.Sending = true;
239
240 if (!m_sharedSendersQueue.Contains(textureSender))
241 {
242 m_sharedSendersQueue.Enqueue(textureSender);
243 }
244 }
245
246 /// <summary>
247 /// Close this module.
248 /// </summary>
249 internal void Close()
250 {
251 closed = true;
252
253 lock (m_textureSenders)
254 {
255 foreach (TextureSender.TextureSender textureSender in m_textureSenders.Values)
256 {
257 textureSender.Cancel = true;
258 }
259
260 m_textureSenders.Clear();
261 }
262
263 // XXX: It might be possible to also remove pending texture requests from the asset cache queues,
264 // though this might also be more trouble than it's worth.
265 }
266 }
267}