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