Refactor asset request processing for consistent status information on whether an asset was actually found or not

afrisby
Justin Clarke Casey 2007-12-19 18:05:45 +00:00
parent 4314b6115b
commit 45567b71b8
4 changed files with 46 additions and 25 deletions

View File

@ -72,7 +72,7 @@ namespace OpenSim.Framework.Communications.Cache
}
}
protected override void ProcessRequest(AssetRequest req)
protected override AssetBase _ProcessRequest(AssetRequest req)
{
byte[] idata = null;
bool found = false;
@ -93,12 +93,12 @@ namespace OpenSim.Framework.Communications.Cache
asset.Name = foundAsset.Name;
idata = foundAsset.Data;
asset.Data = idata;
_receiver.AssetReceived(asset, req.IsTexture);
return asset;
}
else
{
//asset.FullID = ;
_receiver.AssetNotFound(req.AssetID);
return null;
}
}

View File

@ -48,7 +48,38 @@ namespace OpenSim.Framework.Communications.Cache
protected abstract void StoreAsset(AssetBase asset);
protected abstract void CommitAssets();
protected abstract void ProcessRequest(AssetRequest req);
/// <summary>
/// This method must be implemented by a subclass to retrieve the asset named in the
/// AssetRequest. If the asset is not found, null should be returned.
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
protected abstract AssetBase _ProcessRequest(AssetRequest req);
/// <summary>
/// Process an asset request. This method will call _ProcessRequest(AssetRequest req)
/// on the subclass.
/// </summary>
/// <param name="req"></param>
protected void ProcessRequest(AssetRequest req)
{
AssetBase asset = _ProcessRequest(req);
if (asset != null)
{
MainLog.Instance.Verbose(
"ASSET", "Asset {0} received from asset server", req.AssetID);
_receiver.AssetReceived(asset, req.IsTexture);
}
else
{
MainLog.Instance.Error(
"ASSET", "Asset {0} not found by asset server", req.AssetID);
_receiver.AssetNotFound(req.AssetID);
}
}
public void LoadDefaultAssets()
{
@ -117,9 +148,9 @@ namespace OpenSim.Framework.Communications.Cache
AssetRequest req = new AssetRequest();
req.AssetID = assetID;
req.IsTexture = isTexture;
MainLog.Instance.Verbose("ASSET","Adding {0} to request queue", assetID);
_assetRequests.Enqueue(req);
MainLog.Instance.Verbose("ASSET","Added {0} to request queue", assetID);
MainLog.Instance.Verbose("ASSET", "Added {0} to request queue", assetID);
}
public virtual void UpdateAsset(AssetBase asset)

View File

@ -47,7 +47,7 @@ namespace OpenSim.Framework.Communications.Cache
#region IAssetServer Members
protected override void ProcessRequest(AssetRequest req)
protected override AssetBase _ProcessRequest(AssetRequest req)
{
Stream s = null;
try
@ -66,14 +66,8 @@ namespace OpenSim.Framework.Communications.Cache
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);
return (AssetBase)xs.Deserialize(s);
}
}
catch (Exception e)
@ -82,6 +76,8 @@ namespace OpenSim.Framework.Communications.Cache
MainLog.Instance.Debug("ASSETCACHE", "Getting asset {0}", req.AssetID.ToString());
MainLog.Instance.Error("ASSETCACHE", e.StackTrace);
}
return null;
}

View File

@ -77,21 +77,15 @@ namespace OpenSim.Framework.Communications.Cache
m_assetProviderPlugin.CommitAssets();
}
protected override void ProcessRequest(AssetRequest req)
protected override AssetBase _ProcessRequest(AssetRequest req)
{
AssetBase asset;
lock (syncLock)
{
asset = m_assetProviderPlugin.FetchAsset(req.AssetID);
}
if (asset != null)
{
_receiver.AssetReceived(asset, req.IsTexture);
}
else
{
_receiver.AssetNotFound(req.AssetID);
}
return asset;
}
protected override void StoreAsset(AssetBase asset)