From 46700d3b7d5bd71d880b3cc0dd0e2d6edd701195 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Fri, 19 Oct 2007 07:46:03 +0000 Subject: * Total refactoring of Asset Server for massive win * There is now a AssetServerBase * lolcat in ur assets --- .../Communications/Cache/SQLAssetServer.cs | 206 +-------------------- 1 file changed, 10 insertions(+), 196 deletions(-) (limited to 'OpenSim/Framework/Communications/Cache/SQLAssetServer.cs') diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs index 35ec1cf..cf54b81 100644 --- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs @@ -36,32 +36,22 @@ using OpenSim.Framework.Interfaces; using OpenSim.Framework.Types; using OpenSim.Framework.Utilities; -namespace OpenSim.Framework.Communications.Caches +namespace OpenSim.Framework.Communications.Cache { - - public class SQLAssetServer : IAssetServer + public class SQLAssetServer : AssetServerBase { - private IAssetReceiver _receiver; - private BlockingQueue _assetRequests; - private Thread _localAssetServerThread; - protected IAssetProvider m_assetProviderPlugin; - private object syncLock = new object(); - - public SQLAssetServer(string pluginName) { _assetRequests = new BlockingQueue(); AddPlugin(pluginName); - SetUpAssetDatabase(); - this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); this._localAssetServerThread.IsBackground = true; this._localAssetServerThread.Start(); } - public SQLAssetServer( IAssetProvider assetProvider ) + public SQLAssetServer(IAssetProvider assetProvider) { m_assetProviderPlugin = assetProvider; } @@ -93,49 +83,15 @@ namespace OpenSim.Framework.Communications.Caches pluginAssembly = null; } - public void SetReceiver(IAssetReceiver receiver) - { - this._receiver = receiver; - } - - public void FetchAsset(LLUUID assetID, bool isTexture) - { - ARequest req = new ARequest(); - req.AssetID = assetID; - req.IsTexture = isTexture; - this._assetRequests.Enqueue(req); - } - - public void UpdateAsset(AssetBase asset) - { - lock (syncLock) - { - m_assetProviderPlugin.UpdateAsset(asset); - m_assetProviderPlugin.CommitAssets(); - } - } - public void CreateAsset(AssetBase asset) - { - lock (syncLock) - { - m_assetProviderPlugin.CreateAsset(asset); - m_assetProviderPlugin.CommitAssets(); - } - } - - public void SetServerInfo(string ServerUrl, string ServerKey) - { - - } - public void Close() + public override void Close() { m_assetProviderPlugin.CommitAssets(); } private void RunRequests() { - + while (true) { ARequest req = this._assetRequests.Dequeue(); @@ -160,156 +116,14 @@ namespace OpenSim.Framework.Communications.Caches } - private void SetUpAssetDatabase() + protected override void StoreAsset(AssetBase asset) { - MainLog.Instance.Verbose("Setting up asset database"); - - AssetBase Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); - Image.Name = "Bricks"; - this.LoadAsset(Image, true, "bricks.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); - Image.Name = "Plywood"; - this.LoadAsset(Image, true, "plywood.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); - Image.Name = "Rocks"; - this.LoadAsset(Image, true, "rocks.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); - Image.Name = "Granite"; - this.LoadAsset(Image, true, "granite.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); - Image.Name = "Hardwood"; - this.LoadAsset(Image, true, "hardwood.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); - Image.Name = "Prim Base Texture"; - this.LoadAsset(Image, true, "plywood.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006"); - Image.Name = "Map Base Texture"; - this.LoadAsset(Image, true, "map_base.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007"); - Image.Name = "Map Texture"; - this.LoadAsset(Image, true, "map1.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000010"); - Image.Name = "Female Body Texture"; - this.LoadAsset(Image, true, "femalebody.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000011"); - Image.Name = "Female Bottom Texture"; - this.LoadAsset(Image, true, "femalebottom.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000012"); - Image.Name = "Female Face Texture"; - this.LoadAsset(Image, true, "femaleface.jp2"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); - Image.Name = "Skin"; - Image.Type = 13; - Image.InvType = 13; - this.LoadAsset(Image, false, "base_skin.dat"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); - Image.Name = "Shape"; - Image.Type = 13; - Image.InvType = 13; - this.LoadAsset(Image, false, "base_shape.dat"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111110"); - Image.Name = "Shirt"; - Image.Type = 5; - Image.InvType = 18; - this.LoadAsset(Image, false, "newshirt.dat"); - m_assetProviderPlugin.CreateAsset(Image); - - Image = new AssetBase(); - Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111120"); - Image.Name = "Shirt"; - Image.Type = 5; - Image.InvType = 18; - this.LoadAsset(Image, false, "newpants.dat"); - m_assetProviderPlugin.CreateAsset(Image); - - string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); - if (File.Exists(filePath)) - { - XmlConfigSource source = new XmlConfigSource(filePath); - ReadAssetDetails(source); - } - - m_assetProviderPlugin.CommitAssets(); + m_assetProviderPlugin.CreateAsset(asset); } - protected void ReadAssetDetails(IConfigSource source) + protected override void CommitAssets() { - AssetBase newAsset = null; - for (int i = 0; i < source.Configs.Count; i++) - { - newAsset = new AssetBase(); - newAsset.FullID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated())); - newAsset.Name = source.Configs[i].GetString("name", ""); - newAsset.Type = (sbyte)source.Configs[i].GetInt("assetType", 0); - newAsset.InvType = (sbyte)source.Configs[i].GetInt("inventoryType", 0); - string fileName = source.Configs[i].GetString("fileName", ""); - if (fileName != "") - { - MainLog.Instance.Verbose("Creating new asset: " + newAsset.Name); - this.LoadAsset(newAsset, false, fileName); - m_assetProviderPlugin.CreateAsset(newAsset); - } - } - } - - private void LoadAsset(AssetBase info, bool image, string filename) - { - //should request Asset from storage manager - //but for now read from file - - string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; - string fileName = Path.Combine(dataPath, filename); - FileInfo fInfo = new FileInfo(fileName); - long numBytes = fInfo.Length; - FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); - byte[] idata = new byte[numBytes]; - BinaryReader br = new BinaryReader(fStream); - idata = br.ReadBytes((int)numBytes); - br.Close(); - fStream.Close(); - info.Data = idata; - //info.loaded=true; + m_assetProviderPlugin.CommitAssets(); } } - -} +} \ No newline at end of file -- cgit v1.1