* ARequest changed name to AssetRequest and moved to own file.

* The AssetServerBase is now responsible for dequeueing, the server implementations merely recieves ProcessRequest( AssetRequest req )
* Catchall added around queue processing thread so thread won't abort on exceptions.
afrisby
lbsa71 2007-12-14 08:47:15 +00:00
parent 79935881aa
commit 0a4a5bbcef
6 changed files with 105 additions and 108 deletions

View File

@ -0,0 +1,10 @@
using libsecondlife;
namespace OpenSim.Framework
{
public struct AssetRequest
{
public LLUUID AssetID;
public bool IsTexture;
}
}

View File

@ -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; foundAsset = (AssetStorage)result.Next();
bool found = false; found = true;
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;
}
AssetBase asset = new AssetBase(); AssetBase asset = new AssetBase();
if (found) if (found)
{ {
asset.FullID = foundAsset.UUID; asset.FullID = foundAsset.UUID;
asset.Type = foundAsset.Type; asset.Type = foundAsset.Type;
asset.InvType = foundAsset.Type; asset.InvType = foundAsset.Type;
asset.Name = foundAsset.Name; asset.Name = foundAsset.Name;
idata = foundAsset.Data; idata = foundAsset.Data;
asset.Data = idata; asset.Data = idata;
_receiver.AssetReceived(asset, req.IsTexture); _receiver.AssetReceived(asset, req.IsTexture);
} }
else else
{ {
//asset.FullID = ; //asset.FullID = ;
_receiver.AssetNotFound(req.AssetID); _receiver.AssetNotFound(req.AssetID);
}
} }
} }

View File

@ -40,7 +40,7 @@ namespace OpenSim.Framework.Communications.Cache
public abstract class AssetServerBase : IAssetServer public abstract class AssetServerBase : IAssetServer
{ {
protected IAssetReceiver _receiver; protected IAssetReceiver _receiver;
protected BlockingQueue<ARequest> _assetRequests; protected BlockingQueue<AssetRequest> _assetRequests;
protected Thread _localAssetServerThread; protected Thread _localAssetServerThread;
protected IAssetProvider m_assetProviderPlugin; protected IAssetProvider m_assetProviderPlugin;
protected object syncLock = new object(); protected object syncLock = new object();
@ -48,7 +48,7 @@ namespace OpenSim.Framework.Communications.Cache
protected abstract void StoreAsset(AssetBase asset); protected abstract void StoreAsset(AssetBase asset);
protected abstract void CommitAssets(); protected abstract void CommitAssets();
protected abstract void RunRequests(); protected abstract void ProcessRequest(AssetRequest req);
public void LoadDefaultAssets() public void LoadDefaultAssets()
{ {
@ -64,13 +64,30 @@ namespace OpenSim.Framework.Communications.Cache
public AssetServerBase() public AssetServerBase()
{ {
MainLog.Instance.Verbose("ASSETSERVER", "Starting asset storage system"); MainLog.Instance.Verbose("ASSETSERVER", "Starting asset storage system");
_assetRequests = new BlockingQueue<ARequest>(); _assetRequests = new BlockingQueue<AssetRequest>();
_localAssetServerThread = new Thread(RunRequests); _localAssetServerThread = new Thread(RunRequests);
_localAssetServerThread.IsBackground = true; _localAssetServerThread.IsBackground = true;
_localAssetServerThread.Start(); _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) public void LoadAsset(AssetBase info, bool image, string filename)
{ {
//should request Asset from storage manager //should request Asset from storage manager
@ -97,7 +114,7 @@ namespace OpenSim.Framework.Communications.Cache
public void RequestAsset(LLUUID assetID, bool isTexture) public void RequestAsset(LLUUID assetID, bool isTexture)
{ {
ARequest req = new ARequest(); AssetRequest req = new AssetRequest();
req.AssetID = assetID; req.AssetID = assetID;
req.IsTexture = isTexture; req.IsTexture = isTexture;
MainLog.Instance.Verbose("ASSET","Adding {0} to request queue", assetID); MainLog.Instance.Verbose("ASSET","Adding {0} to request queue", assetID);

View File

@ -47,49 +47,40 @@ namespace OpenSim.Framework.Communications.Cache
#region IAssetServer Members #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; if (s.Length > 0)
try
{ {
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); _receiver.AssetReceived(newAsset, req.IsTexture);
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);
}
} }
catch (Exception e) else
{ {
MainLog.Instance.Error("ASSETCACHE", e.Message); MainLog.Instance.Debug("ASSETCACHE", "Asset not found {0}", req.AssetID.ToString());
MainLog.Instance.Debug("ASSETCACHE", "Getting asset {0}", req.AssetID.ToString()); _receiver.AssetNotFound(req.AssetID);
MainLog.Instance.Error("ASSETCACHE", e.StackTrace);
} }
}
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);
} }
} }
@ -104,18 +95,18 @@ namespace OpenSim.Framework.Communications.Cache
{ {
try try
{ {
// MemoryStream s = new MemoryStream(); // MemoryStream s = new MemoryStream();
// XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); // XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
// xs.Serialize(s, asset); // xs.Serialize(s, asset);
// RestClient rc = new RestClient(_assetServerUrl); // RestClient rc = new RestClient(_assetServerUrl);
MainLog.Instance.Verbose("ASSET", "Storing asset"); MainLog.Instance.Verbose("ASSET", "Storing asset");
//rc.AddResourcePath("assets"); //rc.AddResourcePath("assets");
// rc.RequestMethod = "POST"; // rc.RequestMethod = "POST";
// rc.Request(s); // rc.Request(s);
//MainLog.Instance.Verbose("ASSET", "Stored {0}", rc); //MainLog.Instance.Verbose("ASSET", "Stored {0}", rc);
MainLog.Instance.Verbose("ASSET", "Sending to " + _assetServerUrl + "/assets/"); MainLog.Instance.Verbose("ASSET", "Sending to " + _assetServerUrl + "/assets/");
RestObjectPoster.BeginPostObject<AssetBase>(_assetServerUrl + "/assets/", asset); RestObjectPoster.BeginPostObject<AssetBase>(_assetServerUrl + "/assets/", asset);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -57,7 +57,7 @@ namespace OpenSim.Framework.Communications.Cache
if (typeInterface != null) if (typeInterface != null)
{ {
IAssetProvider plug = IAssetProvider plug =
(IAssetProvider) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); (IAssetProvider)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
m_assetProviderPlugin = plug; m_assetProviderPlugin = plug;
m_assetProviderPlugin.Initialise(); m_assetProviderPlugin.Initialise();
@ -65,12 +65,8 @@ namespace OpenSim.Framework.Communications.Cache
"Added " + m_assetProviderPlugin.Name + " " + "Added " + m_assetProviderPlugin.Name + " " +
m_assetProviderPlugin.Version); m_assetProviderPlugin.Version);
} }
typeInterface = null;
} }
} }
pluginAssembly = null;
} }
@ -81,27 +77,20 @@ namespace OpenSim.Framework.Communications.Cache
m_assetProviderPlugin.CommitAssets(); m_assetProviderPlugin.CommitAssets();
} }
protected override void RunRequests() protected override void ProcessRequest(AssetRequest req)
{ {
while (true) AssetBase asset;
lock (syncLock)
{ {
ARequest req = _assetRequests.Dequeue(); asset = m_assetProviderPlugin.FetchAsset(req.AssetID);
}
//MainLog.Instance.Verbose("AssetStorage","Requesting asset: " + req.AssetID); if (asset != null)
{
AssetBase asset = null; _receiver.AssetReceived(asset, req.IsTexture);
lock (syncLock) }
{ else
asset = m_assetProviderPlugin.FetchAsset(req.AssetID); {
} _receiver.AssetNotFound(req.AssetID);
if (asset != null)
{
_receiver.AssetReceived(asset, req.IsTexture);
}
else
{
_receiver.AssetNotFound(req.AssetID);
}
} }
} }

View File

@ -60,10 +60,4 @@ namespace OpenSim.Framework
{ {
IAssetServer GetAssetServer(); IAssetServer GetAssetServer();
} }
public struct ARequest
{
public LLUUID AssetID;
public bool IsTexture;
}
} }