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