diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent/TextureDownload/UserTextureDownloadService.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/TextureDownload/UserTextureDownloadService.cs | 265 |
1 files changed, 0 insertions, 265 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/TextureDownload/UserTextureDownloadService.cs b/OpenSim/Region/CoreModules/Agent/TextureDownload/UserTextureDownloadService.cs deleted file mode 100644 index 19f0f90..0000000 --- a/OpenSim/Region/CoreModules/Agent/TextureDownload/UserTextureDownloadService.cs +++ /dev/null | |||
@@ -1,265 +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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications.Limit; | ||
35 | using OpenSim.Framework.Statistics; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | |||
39 | namespace OpenSim.Region.CoreModules.Agent.TextureDownload | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// This module sets up texture senders in response to client texture requests, and places them on a | ||
43 | /// processing queue once those senders have the appropriate data (i.e. a texture retrieved from the | ||
44 | /// asset cache). | ||
45 | /// </summary> | ||
46 | public class UserTextureDownloadService | ||
47 | { | ||
48 | // private static readonly ILog m_log = 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 | |||
109 | //TextureSender.TextureSender textureSender; | ||
110 | |||
111 | //TODO: should be working out the data size/ number of packets to be sent for each discard level | ||
112 | //if ((e.DiscardLevel >= 0) || (e.Priority != 0)) | ||
113 | //{ | ||
114 | //lock (m_textureSenders) | ||
115 | //{ | ||
116 | //if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | ||
117 | //{ | ||
118 | // If we've received new non UUID information for this request and it hasn't dispatched | ||
119 | // yet, then update the request accordingly. | ||
120 | // textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber); | ||
121 | //} | ||
122 | //else | ||
123 | //{ | ||
124 | // m_log.DebugFormat("[TEXTURE]: Received a request for texture {0}", e.RequestedAssetID); | ||
125 | |||
126 | //if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) | ||
127 | //{ | ||
128 | // m_log.DebugFormat( | ||
129 | // "[TEXTURE]: Refusing request for {0} from client {1}", | ||
130 | // e.RequestedAssetID, m_client.AgentId); | ||
131 | |||
132 | //return; | ||
133 | //} | ||
134 | //else if (!missingTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) | ||
135 | //{ | ||
136 | // if (missingTextureLimitStrategy.IsFirstRefusal(e.RequestedAssetID)) | ||
137 | // { | ||
138 | // if (StatsManager.SimExtraStats != null) | ||
139 | // StatsManager.SimExtraStats.AddBlockedMissingTextureRequest(); | ||
140 | |||
141 | // Commenting out this message for now as it causes too much noise with other | ||
142 | // debug messages. | ||
143 | // m_log.DebugFormat( | ||
144 | // "[TEXTURE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests", | ||
145 | // e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS); | ||
146 | // } | ||
147 | |||
148 | // return; | ||
149 | //} | ||
150 | |||
151 | m_scene.StatsReporter.AddPendingDownloads(1); | ||
152 | |||
153 | //TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber); | ||
154 | //m_textureSenders.Add(e.RequestedAssetID, null); | ||
155 | |||
156 | m_scene.AssetService.Get(e.RequestedAssetID.ToString(), this, TextureReceived); | ||
157 | |||
158 | |||
159 | } | ||
160 | |||
161 | protected void TextureReceived(string id, Object sender, AssetBase asset) | ||
162 | { | ||
163 | if (asset != null) | ||
164 | TextureCallback(asset.FullID, asset); | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// The callback for the asset cache when a texture has been retrieved. This method queues the | ||
169 | /// texture sender for processing. | ||
170 | /// </summary> | ||
171 | /// <param name="textureID"></param> | ||
172 | /// <param name="texture"></param> | ||
173 | public void TextureCallback(UUID textureID, AssetBase texture) | ||
174 | { | ||
175 | //m_log.DebugFormat("[USER TEXTURE DOWNLOAD SERVICE]: Calling TextureCallback with {0}, texture == null is {1}", textureID, (texture == null ? true : false)); | ||
176 | |||
177 | // There may still be texture requests pending for a logged out client | ||
178 | if (closed) | ||
179 | return; | ||
180 | |||
181 | /* | ||
182 | lock (m_textureSenders) | ||
183 | { | ||
184 | TextureSender.TextureSender textureSender; | ||
185 | if (m_textureSenders.TryGetValue(textureID, out textureSender)) | ||
186 | { | ||
187 | // XXX It may be perfectly valid for a texture to have no data... but if we pass | ||
188 | // this on to the TextureSender it will blow up, so just discard for now. | ||
189 | // Needs investigation. | ||
190 | if (texture == null || texture.Data == null) | ||
191 | { | ||
192 | if (!missingTextureLimitStrategy.IsMonitoringRequests(textureID)) | ||
193 | { | ||
194 | missingTextureLimitStrategy.MonitorRequests(textureID); | ||
195 | |||
196 | // m_log.DebugFormat( | ||
197 | // "[TEXTURE]: Queueing first TextureNotFoundSender for {0}, client {1}", | ||
198 | // textureID, m_client.AgentId); | ||
199 | } | ||
200 | |||
201 | ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID); | ||
202 | EnqueueTextureSender(textureNotFoundSender); | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | if (!textureSender.ImageLoaded) | ||
207 | { | ||
208 | textureSender.TextureReceived(texture); | ||
209 | EnqueueTextureSender(textureSender); | ||
210 | |||
211 | foundTextureLimitStrategy.MonitorRequests(textureID); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | //m_log.InfoFormat("[TEXTURE] Removing texture sender with uuid {0}", textureID); | ||
216 | m_textureSenders.Remove(textureID); | ||
217 | //m_log.InfoFormat("[TEXTURE] Current texture senders in dictionary: {0}", m_textureSenders.Count); | ||
218 | } | ||
219 | else | ||
220 | { | ||
221 | m_log.WarnFormat( | ||
222 | "[TEXTURE]: Got a texture uuid {0} with no sender object to handle it, this shouldn't happen", | ||
223 | textureID); | ||
224 | } | ||
225 | } | ||
226 | */ | ||
227 | } | ||
228 | |||
229 | /// <summary> | ||
230 | /// Place a ready texture sender on the processing queue. | ||
231 | /// </summary> | ||
232 | /// <param name="textureSender"></param> | ||
233 | // private void EnqueueTextureSender(ITextureSender textureSender) | ||
234 | // { | ||
235 | // textureSender.Cancel = false; | ||
236 | // textureSender.Sending = true; | ||
237 | // | ||
238 | // if (!m_sharedSendersQueue.Contains(textureSender)) | ||
239 | // { | ||
240 | // m_sharedSendersQueue.Enqueue(textureSender); | ||
241 | // } | ||
242 | // } | ||
243 | |||
244 | /// <summary> | ||
245 | /// Close this module. | ||
246 | /// </summary> | ||
247 | internal void Close() | ||
248 | { | ||
249 | closed = true; | ||
250 | |||
251 | lock (m_textureSenders) | ||
252 | { | ||
253 | foreach (TextureSender.TextureSender textureSender in m_textureSenders.Values) | ||
254 | { | ||
255 | textureSender.Cancel = true; | ||
256 | } | ||
257 | |||
258 | m_textureSenders.Clear(); | ||
259 | } | ||
260 | |||
261 | // XXX: It might be possible to also remove pending texture requests from the asset cache queues, | ||
262 | // though this might also be more trouble than it's worth. | ||
263 | } | ||
264 | } | ||
265 | } | ||