aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetServerBase.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServerBase.cs246
1 files changed, 0 insertions, 246 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
deleted file mode 100644
index 4b2a752..0000000
--- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
+++ /dev/null
@@ -1,246 +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
28using System;
29using System.Reflection;
30using System.Threading;
31using log4net;
32using OpenMetaverse;
33using OpenSim.Data;
34using OpenSim.Framework.AssetLoader.Filesystem;
35using OpenSim.Framework.Statistics;
36
37namespace OpenSim.Framework.Communications.Cache
38{
39 public abstract class AssetServerBase : IAssetServer
40 {
41 private static readonly ILog m_log
42 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 protected IAssetReceiver m_receiver;
45 protected BlockingQueue<AssetRequest> m_assetRequests = new BlockingQueue<AssetRequest>();
46 protected Thread m_localAssetServerThread;
47 protected IAssetDataPlugin m_assetProvider;
48
49 #region IPlugin
50
51 /// <summary>
52 /// The methods and properties in this region are needed to implement
53 /// the IPlugin interface and its local extensions.
54 /// These can all be overridden as appropriate by a derived class.
55 /// These methods are only applicable when a class is loaded by the
56 /// IPlugin mechanism.
57 ///
58 /// Note that in the case of AssetServerBase, all initialization is
59 /// performed by the default constructor, so nothing additional is
60 /// required here. A derived class may wish to do more.
61 /// </summary>
62
63 public virtual string Name
64 {
65 // get { return "OpenSim.Framework.Communications.Cache.AssetServerBase"; }
66 get { return "AssetServerBase"; }
67 }
68
69 public virtual string Version
70 {
71 get { return "1.0"; }
72 }
73
74 public virtual void Initialise()
75 {
76 m_log.Debug("[ASSET SERVER]: IPlugin null initialization");
77 }
78
79 public virtual void Initialise(ConfigSettings settings)
80 {
81 m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(1)");
82 m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version);
83 }
84
85 public virtual void Initialise(ConfigSettings settings, string p_url)
86 {
87 m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(2)");
88 m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version);
89 }
90
91 public virtual void Initialise(ConfigSettings settings, string p_url, string p_dir, bool p_t)
92 {
93 m_log.Debug("[ASSET SERVER]: IPlugin null configured initialization(3)");
94 m_log.InfoFormat("[ASSET SERVER]: Initializing client [{0}/{1}", Name, Version);
95 }
96
97 public virtual void Dispose()
98 {
99 m_log.Debug("[ASSET SERVER]: dispose");
100 }
101
102 #endregion
103
104 public IAssetDataPlugin AssetProviderPlugin
105 {
106 get { return m_assetProvider; }
107 }
108
109 // Temporarily hardcoded - should be a plugin
110 protected IAssetLoader assetLoader = new AssetLoaderFileSystem();
111
112 public virtual void Start()
113 {
114 m_log.Debug("[ASSET SERVER]: Starting asset server");
115
116 m_localAssetServerThread = new Thread(RunRequests);
117 m_localAssetServerThread.Name = "LocalAssetServerThread";
118 m_localAssetServerThread.IsBackground = true;
119 m_localAssetServerThread.Start();
120 ThreadTracker.Add(m_localAssetServerThread);
121 }
122
123 public virtual void Stop()
124 {
125 m_localAssetServerThread.Abort();
126 }
127
128 public abstract void StoreAsset(AssetBase asset);
129
130 /// <summary>
131 /// This method must be implemented by a subclass to retrieve the asset named in the
132 /// AssetRequest. If the asset is not found, null should be returned.
133 /// </summary>
134 /// <param name="req"></param>
135 /// <returns></returns>
136 /// <exception cref="System.Exception">
137 /// Thrown if the request failed for some other reason than that the
138 /// asset cannot be found.
139 /// </exception>
140 protected abstract AssetBase GetAsset(AssetRequest req);
141
142 /// <summary>
143 /// Does the asset server have any waiting requests?
144 /// </summary>
145 ///
146 /// This does include any request that is currently being handled. This information is not reliable where
147 /// another thread may be processing requests.
148 ///
149 /// <returns>
150 /// True if there are waiting requests. False if there are no waiting requests.
151 /// </returns>
152 public virtual bool HasWaitingRequests()
153 {
154 return m_assetRequests.Count() != 0;
155 }
156
157 /// <summary>
158 /// Process an asset request. This method will call GetAsset(AssetRequest req)
159 /// on the subclass.
160 /// </summary>
161 public virtual void ProcessNextRequest()
162 {
163 AssetRequest req = m_assetRequests.Dequeue();
164 AssetBase asset;
165
166 try
167 {
168 asset = GetAsset(req);
169 }
170 catch (Exception e)
171 {
172 m_log.ErrorFormat("[ASSET]: Asset request for {0} threw exception {1} - Stack Trace: {2}", req.AssetID, e, e.StackTrace);
173
174 if (StatsManager.SimExtraStats != null)
175 StatsManager.SimExtraStats.AddAssetServiceRequestFailure();
176
177 m_receiver.AssetNotFound(req.AssetID, req.IsTexture);
178
179 return;
180 }
181
182 if (asset != null)
183 {
184 //m_log.DebugFormat("[ASSET]: Asset {0} received from asset server", req.AssetID);
185
186 m_receiver.AssetReceived(asset, req.IsTexture);
187 }
188 else
189 {
190 //m_log.WarnFormat("[ASSET]: Asset {0} not found by asset server", req.AssetID);
191
192 m_receiver.AssetNotFound(req.AssetID, req.IsTexture);
193 }
194 }
195
196 public virtual void LoadDefaultAssets(string pAssetSetsXml)
197 {
198 m_log.Info("[ASSET SERVER]: Setting up asset database");
199
200 assetLoader.ForEachDefaultXmlAsset(pAssetSetsXml, StoreAsset);
201 }
202
203 private void RunRequests()
204 {
205 while (true) // Since it's a 'blocking queue'
206 {
207 try
208 {
209 ProcessNextRequest();
210 }
211 catch (Exception e)
212 {
213 m_log.Error("[ASSET SERVER]: " + e.ToString());
214 }
215 }
216 }
217
218 /// <summary>
219 /// The receiver will be called back with asset data once it comes in.
220 /// </summary>
221 /// <param name="receiver"></param>
222 public void SetReceiver(IAssetReceiver receiver)
223 {
224 m_receiver = receiver;
225 }
226
227 public void RequestAsset(UUID assetID, bool isTexture)
228 {
229 AssetRequest req = new AssetRequest();
230 req.AssetID = assetID;
231 req.IsTexture = isTexture;
232 m_assetRequests.Enqueue(req);
233
234 //m_log.DebugFormat("[ASSET SERVER]: Added {0} to request queue", assetID);
235 }
236
237 public virtual void UpdateAsset(AssetBase asset)
238 {
239 m_assetProvider.UpdateAsset(asset);
240 }
241
242 public void SetServerInfo(string ServerUrl, string ServerKey)
243 {
244 }
245 }
246}