From 45567b71b8c3c6f2e52dacdda92671048bb3faf0 Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Wed, 19 Dec 2007 18:05:45 +0000
Subject: Refactor asset request processing for consistent status information
on whether an asset was actually found or not
---
.../Framework/Communications/Cache/AssetServer.cs | 8 ++---
.../Communications/Cache/AssetServerBase.cs | 37 ++++++++++++++++++++--
.../Communications/Cache/GridAssetClient.cs | 14 +++-----
.../Communications/Cache/SQLAssetServer.cs | 12 ++-----
4 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/OpenSim/Framework/Communications/Cache/AssetServer.cs b/OpenSim/Framework/Communications/Cache/AssetServer.cs
index 00c2b2a..4ad0f60 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServer.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServer.cs
@@ -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;
}
}
diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
index 659b9c9..4d03fee 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
@@ -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);
+ ///
+ /// 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.
+ ///
+ ///
+ ///
+ protected abstract AssetBase _ProcessRequest(AssetRequest req);
+
+ ///
+ /// Process an asset request. This method will call _ProcessRequest(AssetRequest req)
+ /// on the subclass.
+ ///
+ ///
+ 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)
diff --git a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs
index 47104d7..5801aa8 100644
--- a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs
+++ b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs
@@ -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;
}
diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
index 010581f..4fa7684 100644
--- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
+++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
@@ -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)
--
cgit v1.1