aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/TextureDownloadModule.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/TextureDownloadModule.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/TextureDownloadModule.cs (renamed from OpenSim/Region/Environment/Modules/TextureDownloadModule.cs)433
1 files changed, 215 insertions, 218 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}