aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent/TextureDownload
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
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/TextureDownloadModule.cs (renamed from OpenSim/Region/Environment/Modules/TextureDownloadModule.cs)433
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs (renamed from OpenSim/Region/Environment/Modules/TextureNotFoundSender.cs)186
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs (renamed from OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs)502
3 files changed, 560 insertions, 561 deletions
diff --git a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs
index bde0dc0..b8899d2 100644
--- a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs
@@ -1,218 +1,215 @@
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; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Threading; 30using System.Threading;
31using libsecondlife; 31using libsecondlife;
32using Nini.Config; 32using Nini.Config;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
36 36
37namespace OpenSim.Region.Environment.Modules 37namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
38{ 38{
39 //this is a first attempt, to start breaking the mess thats called the assetcache up. 39 public class TextureDownloadModule : IRegionModule
40 // basically this should be the texture sending (to clients) code moved out of assetcache 40 {
41 //and some small clean up 41 //private static readonly log4net.ILog m_log
42 public class TextureDownloadModule : IRegionModule 42 // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
43 { 43
44 //private static readonly log4net.ILog m_log 44 private Scene m_scene;
45 // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 45 private List<Scene> m_scenes = new List<Scene>();
46 46
47 private Scene m_scene; 47 /// <summary>
48 private List<Scene> m_scenes = new List<Scene>(); 48 /// There is one queue for all textures waiting to be sent, regardless of the requesting user.
49 49 /// </summary>
50 /// <summary> 50 private readonly BlockingQueue<ITextureSender> m_queueSenders
51 /// There is one queue for all textures waiting to be sent, regardless of the requesting user. 51 = new BlockingQueue<ITextureSender>();
52 /// </summary> 52
53 private readonly BlockingQueue<ITextureSender> m_queueSenders 53 /// <summary>
54 = new BlockingQueue<ITextureSender>(); 54 /// Each user has their own texture download service.
55 55 /// </summary>
56 /// <summary> 56 private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices =
57 /// Each user has their own texture download service. 57 new Dictionary<LLUUID, UserTextureDownloadService>();
58 /// </summary> 58
59 private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices = 59 private Thread m_thread;
60 new Dictionary<LLUUID, UserTextureDownloadService>(); 60
61 61 public TextureDownloadModule()
62 private Thread m_thread; 62 {
63 63 }
64 public TextureDownloadModule() 64
65 { 65 public void Initialise(Scene scene, IConfigSource config)
66 } 66 {
67 67 if (m_scene == null)
68 public void Initialise(Scene scene, IConfigSource config) 68 {
69 { 69 //Console.WriteLine("Creating Texture download module");
70 if (m_scene == null) 70 m_thread = new Thread(new ThreadStart(ProcessTextureSenders));
71 { 71 m_thread.Name = "ProcessTextureSenderThread";
72 //Console.WriteLine("Creating Texture download module"); 72 m_thread.IsBackground = true;
73 m_thread = new Thread(new ThreadStart(ProcessTextureSenders)); 73 m_thread.Start();
74 m_thread.Name = "ProcessTextureSenderThread"; 74 ThreadTracker.Add(m_thread);
75 m_thread.IsBackground = true; 75 }
76 m_thread.Start(); 76
77 ThreadTracker.Add(m_thread); 77 if (!m_scenes.Contains(scene))
78 } 78 {
79 79 m_scenes.Add(scene);
80 if (!m_scenes.Contains(scene)) 80 m_scene = scene;
81 { 81 m_scene.EventManager.OnNewClient += NewClient;
82 m_scenes.Add(scene); 82 m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence;
83 m_scene = scene; 83 }
84 m_scene.EventManager.OnNewClient += NewClient; 84 }
85 m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence; 85
86 } 86 /// <summary>
87 } 87 /// Cleanup the texture service related objects for the removed presence.
88 88 /// </summary>
89 /// <summary> 89 /// <param name="agentId"> </param>
90 /// Cleanup the texture service related objects for the removed presence. 90 private void EventManager_OnRemovePresence(LLUUID agentId)
91 /// </summary> 91 {
92 /// <param name="agentId"> </param> 92 UserTextureDownloadService textureService;
93 private void EventManager_OnRemovePresence(LLUUID agentId) 93
94 { 94 lock (m_userTextureServices)
95 UserTextureDownloadService textureService; 95 {
96 96 if (m_userTextureServices.TryGetValue(agentId, out textureService))
97 lock (m_userTextureServices) 97 {
98 { 98 textureService.Close();
99 if (m_userTextureServices.TryGetValue(agentId, out textureService)) 99
100 { 100 m_userTextureServices.Remove(agentId);
101 textureService.Close(); 101 }
102 102 }
103 m_userTextureServices.Remove(agentId); 103 }
104 } 104
105 } 105 public void PostInitialise()
106 } 106 {
107 107 }
108 public void PostInitialise() 108
109 { 109 public void Close()
110 } 110 {
111 111 }
112 public void Close() 112
113 { 113 public string Name
114 } 114 {
115 115 get { return "TextureDownloadModule"; }
116 public string Name 116 }
117 { 117
118 get { return "TextureDownloadModule"; } 118 public bool IsSharedModule
119 } 119 {
120 120 get { return false; }
121 public bool IsSharedModule 121 }
122 { 122
123 get { return false; } 123 public void NewClient(IClientAPI client)
124 } 124 {
125 125 client.OnRequestTexture += TextureRequest;
126 public void NewClient(IClientAPI client) 126 }
127 { 127
128 client.OnRequestTexture += TextureRequest; 128 /// <summary>
129 } 129 /// Does this user have a registered texture download service?
130 130 /// </summary>
131 /// <summary> 131 /// <param name="userID"></param>
132 /// Does this user have a registered texture download service? 132 /// <param name="textureService"></param>
133 /// </summary> 133 /// <returns>Always returns true, since a service is created if one does not already exist</returns>
134 /// <param name="userID"></param> 134 private bool TryGetUserTextureService(
135 /// <param name="textureService"></param> 135 IClientAPI client, out UserTextureDownloadService textureService)
136 /// <returns>Always returns true, since a service is created if one does not already exist</returns> 136 {
137 private bool TryGetUserTextureService( 137 lock (m_userTextureServices)
138 IClientAPI client, out UserTextureDownloadService textureService) 138 {
139 { 139 if (m_userTextureServices.TryGetValue(client.AgentId, out textureService))
140 lock (m_userTextureServices) 140 {
141 { 141 return true;
142 if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) 142 }
143 { 143
144 return true; 144 textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders);
145 } 145 m_userTextureServices.Add(client.AgentId, textureService);
146 146
147 textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders); 147 return true;
148 m_userTextureServices.Add(client.AgentId, textureService); 148 }
149 149 }
150 return true; 150
151 } 151 /// <summary>
152 } 152 /// Start the process of requesting a given texture.
153 153 /// </summary>
154 /// <summary> 154 /// <param name="sender"> </param>
155 /// Start the process of requesting a given texture. 155 /// <param name="e"></param>
156 /// </summary> 156 public void TextureRequest(Object sender, TextureRequestArgs e)
157 /// <param name="sender"> </param> 157 {
158 /// <param name="e"></param> 158 IClientAPI client = (IClientAPI) sender;
159 public void TextureRequest(Object sender, TextureRequestArgs e) 159 UserTextureDownloadService textureService;
160 { 160
161 IClientAPI client = (IClientAPI) sender; 161 if (TryGetUserTextureService(client, out textureService))
162 UserTextureDownloadService textureService; 162 {
163 163 textureService.HandleTextureRequest(e);
164 if (TryGetUserTextureService(client, out textureService)) 164 }
165 { 165 }
166 textureService.HandleTextureRequest(e); 166
167 } 167 /// <summary>
168 } 168 /// Entry point for the thread dedicated to processing the texture queue.
169 169 /// </summary>
170 /// <summary> 170 public void ProcessTextureSenders()
171 /// Entry point for the thread dedicated to processing the texture queue. 171 {
172 /// </summary> 172 ITextureSender sender = null;
173 public void ProcessTextureSenders() 173
174 { 174 while (true)
175 ITextureSender sender = null; 175 {
176 176 sender = m_queueSenders.Dequeue();
177 while (true) 177
178 { 178 if (sender.Cancel)
179 sender = m_queueSenders.Dequeue(); 179 {
180 180 TextureSent(sender);
181 if (sender.Cancel) 181
182 { 182 sender.Cancel = false;
183 TextureSent(sender); 183 }
184 184 else
185 sender.Cancel = false; 185 {
186 } 186 bool finished = sender.SendTexturePacket();
187 else 187 if (finished)
188 { 188 {
189 bool finished = sender.SendTexturePacket(); 189 TextureSent(sender);
190 if (finished) 190 }
191 { 191 else
192 TextureSent(sender); 192 {
193 } 193 m_queueSenders.Enqueue(sender);
194 else 194 }
195 { 195 }
196 m_queueSenders.Enqueue(sender); 196
197 } 197 // Make sure that any sender we currently have can get garbage collected
198 } 198 sender = null;
199 199
200 // Make sure that any sender we currently have can get garbage collected 200 //m_log.InfoFormat("[TEXTURE DOWNLOAD] Texture sender queue size: {0}", m_queueSenders.Count());
201 sender = null; 201 }
202 202 }
203 //m_log.InfoFormat("[TEXTURE DOWNLOAD] Texture sender queue size: {0}", m_queueSenders.Count()); 203
204 } 204 /// <summary>
205 } 205 /// Called when the texture has finished sending.
206 206 /// </summary>
207 /// <summary> 207 /// <param name="sender"></param>
208 /// Called when the texture has finished sending. 208 private void TextureSent(ITextureSender sender)
209 /// </summary> 209 {
210 /// <param name="sender"></param> 210 sender.Sending = false;
211 private void TextureSent(ITextureSender sender) 211 //m_log.DebugFormat("[TEXTURE DOWNLOAD]: Removing download stat for {0}", sender.assetID);
212 { 212 m_scene.AddPendingDownloads(-1);
213 sender.Sending = false; 213 }
214 //m_log.DebugFormat("[TEXTURE DOWNLOAD]: Removing download stat for {0}", sender.assetID); 214 }
215 m_scene.AddPendingDownloads(-1); 215} \ No newline at end of file
216 }
217 }
218}
diff --git a/OpenSim/Region/Environment/Modules/TextureNotFoundSender.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs
index 7b835a1..6f11f73 100644
--- a/OpenSim/Region/Environment/Modules/TextureNotFoundSender.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs
@@ -1,93 +1,93 @@
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 libsecondlife; 28using libsecondlife;
29using libsecondlife.Packets; 29using libsecondlife.Packets;
30using OpenSim.Framework; 30using OpenSim.Framework;
31using OpenSim.Region.Environment.Interfaces; 31using OpenSim.Region.Environment.Interfaces;
32 32
33namespace OpenSim.Region.Environment.Modules 33namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
34{ 34{
35 /// <summary> 35 /// <summary>
36 /// Sends a 'texture not found' packet back to the client 36 /// Sends a 'texture not found' packet back to the client
37 /// </summary> 37 /// </summary>
38 public class TextureNotFoundSender : ITextureSender 38 public class TextureNotFoundSender : ITextureSender
39 { 39 {
40 //private static readonly log4net.ILog m_log 40 //private static readonly log4net.ILog m_log
41 // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 41 // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
42 42
43 private LLUUID m_textureId; 43 private LLUUID m_textureId;
44 private IClientAPI m_client; 44 private IClientAPI m_client;
45 45
46 // See ITextureSender 46 // See ITextureSender
47 public bool Sending 47 public bool Sending
48 { 48 {
49 get { return false; } 49 get { return false; }
50 set { m_sending = value; } 50 set { m_sending = value; }
51 } 51 }
52 52
53 private bool m_sending = false; 53 private bool m_sending = false;
54 54
55 // See ITextureSender 55 // See ITextureSender
56 public bool Cancel 56 public bool Cancel
57 { 57 {
58 get { return false; } 58 get { return false; }
59 set { m_cancel = value; } 59 set { m_cancel = value; }
60 } 60 }
61 61
62 private bool m_cancel = false; 62 private bool m_cancel = false;
63 63
64 public TextureNotFoundSender(IClientAPI client, LLUUID textureID) 64 public TextureNotFoundSender(IClientAPI client, LLUUID textureID)
65 { 65 {
66 m_client = client; 66 m_client = client;
67 m_textureId = textureID; 67 m_textureId = textureID;
68 } 68 }
69 69
70 // See ITextureSender 70 // See ITextureSender
71 public void UpdateRequest(int discardLevel, uint packetNumber) 71 public void UpdateRequest(int discardLevel, uint packetNumber)
72 { 72 {
73 // Not need to implement since priority changes don't affect this operation 73 // Not need to implement since priority changes don't affect this operation
74 } 74 }
75 75
76 // See ITextureSender 76 // See ITextureSender
77 public bool SendTexturePacket() 77 public bool SendTexturePacket()
78 { 78 {
79 //m_log.InfoFormat( 79 //m_log.InfoFormat(
80 // "[TEXTURE NOT FOUND SENDER]: Informing the client that texture {0} cannot be found", 80 // "[TEXTURE NOT FOUND SENDER]: Informing the client that texture {0} cannot be found",
81 // m_textureId); 81 // m_textureId);
82 82
83 ImageNotInDatabasePacket notFound = new ImageNotInDatabasePacket(); 83 ImageNotInDatabasePacket notFound = new ImageNotInDatabasePacket();
84 notFound.ImageID.ID = m_textureId; 84 notFound.ImageID.ID = m_textureId;
85 85
86 // XXX Temporarily disabling as this appears to be causing client crashes on at least 86 // XXX Temporarily disabling as this appears to be causing client crashes on at least
87 // 1.19.0(5) of the Linden Second Life client. 87 // 1.19.0(5) of the Linden Second Life client.
88 // m_client.OutPacket(notFound, ThrottleOutPacketType.Texture); 88 // m_client.OutPacket(notFound, ThrottleOutPacketType.Texture);
89 89
90 return true; 90 return true;
91 } 91 }
92 } 92 }
93} 93} \ No newline at end of file
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