diff --git a/OpenSim/Framework/AssetRequest.cs b/OpenSim/Framework/AssetRequest.cs new file mode 100644 index 0000000000..163ab701df --- /dev/null +++ b/OpenSim/Framework/AssetRequest.cs @@ -0,0 +1,10 @@ +using libsecondlife; + +namespace OpenSim.Framework +{ + public struct AssetRequest + { + public LLUUID AssetID; + public bool IsTexture; + } +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Cache/AssetServer.cs b/OpenSim/Framework/Communications/Cache/AssetServer.cs index e5cceaadec..00c2b2afbc 100644 --- a/OpenSim/Framework/Communications/Cache/AssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/AssetServer.cs @@ -72,37 +72,33 @@ namespace OpenSim.Framework.Communications.Cache } } - protected override void RunRequests() + protected override void ProcessRequest(AssetRequest req) { - while (true) + byte[] idata = null; + bool found = false; + AssetStorage foundAsset = null; + IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID)); + if (result.Count > 0) { - byte[] idata = null; - bool found = false; - AssetStorage foundAsset = null; - ARequest req = _assetRequests.Dequeue(); - IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID)); - if (result.Count > 0) - { - foundAsset = (AssetStorage) result.Next(); - found = true; - } + foundAsset = (AssetStorage)result.Next(); + found = true; + } - AssetBase asset = new AssetBase(); - if (found) - { - asset.FullID = foundAsset.UUID; - asset.Type = foundAsset.Type; - asset.InvType = foundAsset.Type; - asset.Name = foundAsset.Name; - idata = foundAsset.Data; - asset.Data = idata; - _receiver.AssetReceived(asset, req.IsTexture); - } - else - { - //asset.FullID = ; - _receiver.AssetNotFound(req.AssetID); - } + AssetBase asset = new AssetBase(); + if (found) + { + asset.FullID = foundAsset.UUID; + asset.Type = foundAsset.Type; + asset.InvType = foundAsset.Type; + asset.Name = foundAsset.Name; + idata = foundAsset.Data; + asset.Data = idata; + _receiver.AssetReceived(asset, req.IsTexture); + } + else + { + //asset.FullID = ; + _receiver.AssetNotFound(req.AssetID); } } diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs index e117c933a4..659b9c93e1 100644 --- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs +++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs @@ -40,7 +40,7 @@ namespace OpenSim.Framework.Communications.Cache public abstract class AssetServerBase : IAssetServer { protected IAssetReceiver _receiver; - protected BlockingQueue _assetRequests; + protected BlockingQueue _assetRequests; protected Thread _localAssetServerThread; protected IAssetProvider m_assetProviderPlugin; protected object syncLock = new object(); @@ -48,7 +48,7 @@ namespace OpenSim.Framework.Communications.Cache protected abstract void StoreAsset(AssetBase asset); protected abstract void CommitAssets(); - protected abstract void RunRequests(); + protected abstract void ProcessRequest(AssetRequest req); public void LoadDefaultAssets() { @@ -64,13 +64,30 @@ namespace OpenSim.Framework.Communications.Cache public AssetServerBase() { MainLog.Instance.Verbose("ASSETSERVER", "Starting asset storage system"); - _assetRequests = new BlockingQueue(); + _assetRequests = new BlockingQueue(); _localAssetServerThread = new Thread(RunRequests); _localAssetServerThread.IsBackground = true; _localAssetServerThread.Start(); } + private void RunRequests() + { + while (true) // Since it's a 'blocking queue' + { + try + { + AssetRequest req = _assetRequests.Dequeue(); + + ProcessRequest(req); + } + catch(Exception e) + { + MainLog.Instance.Error("ASSETSERVER", e.Message ); + } + } + } + public void LoadAsset(AssetBase info, bool image, string filename) { //should request Asset from storage manager @@ -97,7 +114,7 @@ namespace OpenSim.Framework.Communications.Cache public void RequestAsset(LLUUID assetID, bool isTexture) { - ARequest req = new ARequest(); + AssetRequest req = new AssetRequest(); req.AssetID = assetID; req.IsTexture = isTexture; MainLog.Instance.Verbose("ASSET","Adding {0} to request queue", assetID); diff --git a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs index e2924a4b41..47104d76e0 100644 --- a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs +++ b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs @@ -36,7 +36,7 @@ using OpenSim.Framework.Servers; namespace OpenSim.Framework.Communications.Cache { - public class GridAssetClient : AssetServerBase + public class GridAssetClient : AssetServerBase { private string _assetServerUrl; @@ -47,53 +47,44 @@ namespace OpenSim.Framework.Communications.Cache #region IAssetServer Members - protected override void RunRequests() + protected override void ProcessRequest(AssetRequest req) { - while (true) + Stream s = null; + try { - ARequest req = _assetRequests.Dequeue(); + MainLog.Instance.Debug("ASSETCACHE", "Querying for {0}", req.AssetID.ToString()); - //MainLog.Instance.Verbose("AssetStorage","Requesting asset: " + req.AssetID); + RestClient rc = new RestClient(_assetServerUrl); + rc.AddResourcePath("assets"); + rc.AddResourcePath(req.AssetID.ToString()); + if (req.IsTexture) + rc.AddQueryParameter("texture"); + rc.RequestMethod = "GET"; + s = rc.Request(); - Stream s = null; - try + if (s.Length > 0) { - MainLog.Instance.Debug("ASSETCACHE", "Querying for {0}", req.AssetID.ToString()); + XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); + AssetBase newAsset = (AssetBase)xs.Deserialize(s); - RestClient rc = new RestClient(_assetServerUrl); - rc.AddResourcePath("assets"); - rc.AddResourcePath(req.AssetID.ToString()); - if (req.IsTexture) - rc.AddQueryParameter("texture"); - - rc.RequestMethod = "GET"; - s = rc.Request(); - - if (s.Length > 0) - { - XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); - AssetBase newAsset = (AssetBase)xs.Deserialize(s); - - _receiver.AssetReceived(newAsset, req.IsTexture); - } - else - { - MainLog.Instance.Debug("ASSETCACHE", "Asset not found {0}", req.AssetID.ToString()); - _receiver.AssetNotFound(req.AssetID); - } + _receiver.AssetReceived(newAsset, req.IsTexture); } - catch (Exception e) + else { - MainLog.Instance.Error("ASSETCACHE", e.Message); - MainLog.Instance.Debug("ASSETCACHE", "Getting asset {0}", req.AssetID.ToString()); - MainLog.Instance.Error("ASSETCACHE", e.StackTrace); + MainLog.Instance.Debug("ASSETCACHE", "Asset not found {0}", req.AssetID.ToString()); + _receiver.AssetNotFound(req.AssetID); } - + } + catch (Exception e) + { + MainLog.Instance.Error("ASSETCACHE", e.Message); + MainLog.Instance.Debug("ASSETCACHE", "Getting asset {0}", req.AssetID.ToString()); + MainLog.Instance.Error("ASSETCACHE", e.StackTrace); } } - + public override void UpdateAsset(AssetBase asset) { @@ -104,18 +95,18 @@ namespace OpenSim.Framework.Communications.Cache { try { - // MemoryStream s = new MemoryStream(); + // MemoryStream s = new MemoryStream(); - // XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); - // xs.Serialize(s, asset); - // RestClient rc = new RestClient(_assetServerUrl); - MainLog.Instance.Verbose("ASSET", "Storing asset"); + // XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); + // xs.Serialize(s, asset); + // RestClient rc = new RestClient(_assetServerUrl); + MainLog.Instance.Verbose("ASSET", "Storing asset"); //rc.AddResourcePath("assets"); - // rc.RequestMethod = "POST"; - // rc.Request(s); - //MainLog.Instance.Verbose("ASSET", "Stored {0}", rc); - MainLog.Instance.Verbose("ASSET", "Sending to " + _assetServerUrl + "/assets/"); - RestObjectPoster.BeginPostObject(_assetServerUrl + "/assets/", asset); + // rc.RequestMethod = "POST"; + // rc.Request(s); + //MainLog.Instance.Verbose("ASSET", "Stored {0}", rc); + MainLog.Instance.Verbose("ASSET", "Sending to " + _assetServerUrl + "/assets/"); + RestObjectPoster.BeginPostObject(_assetServerUrl + "/assets/", asset); } catch (Exception e) { @@ -132,7 +123,7 @@ namespace OpenSim.Framework.Communications.Cache throw new Exception("The method or operation is not implemented."); } - + #endregion } diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs index 9d087859fe..010581f020 100644 --- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs @@ -57,7 +57,7 @@ namespace OpenSim.Framework.Communications.Cache if (typeInterface != null) { IAssetProvider plug = - (IAssetProvider) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + (IAssetProvider)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); m_assetProviderPlugin = plug; m_assetProviderPlugin.Initialise(); @@ -65,12 +65,8 @@ namespace OpenSim.Framework.Communications.Cache "Added " + m_assetProviderPlugin.Name + " " + m_assetProviderPlugin.Version); } - - typeInterface = null; } } - - pluginAssembly = null; } @@ -81,27 +77,20 @@ namespace OpenSim.Framework.Communications.Cache m_assetProviderPlugin.CommitAssets(); } - protected override void RunRequests() + protected override void ProcessRequest(AssetRequest req) { - while (true) + AssetBase asset; + lock (syncLock) { - ARequest req = _assetRequests.Dequeue(); - - //MainLog.Instance.Verbose("AssetStorage","Requesting asset: " + req.AssetID); - - AssetBase asset = null; - lock (syncLock) - { - asset = m_assetProviderPlugin.FetchAsset(req.AssetID); - } - if (asset != null) - { - _receiver.AssetReceived(asset, req.IsTexture); - } - else - { - _receiver.AssetNotFound(req.AssetID); - } + asset = m_assetProviderPlugin.FetchAsset(req.AssetID); + } + if (asset != null) + { + _receiver.AssetReceived(asset, req.IsTexture); + } + else + { + _receiver.AssetNotFound(req.AssetID); } } diff --git a/OpenSim/Framework/IAssetServer.cs b/OpenSim/Framework/IAssetServer.cs index 2200d900ac..2fa77a048d 100644 --- a/OpenSim/Framework/IAssetServer.cs +++ b/OpenSim/Framework/IAssetServer.cs @@ -60,10 +60,4 @@ namespace OpenSim.Framework { IAssetServer GetAssetServer(); } - - public struct ARequest - { - public LLUUID AssetID; - public bool IsTexture; - } }