* Implement asynchronous assets request for archiving

* No user functionality yet
0.6.0-stable
Justin Clarke Casey 2008-05-27 14:21:32 +00:00
parent 2cea74181a
commit 64821ac0a1
1 changed files with 187 additions and 116 deletions

View File

@ -25,6 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Communications.Cache;
using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Modules.World.Serialiser; using OpenSim.Region.Environment.Modules.World.Serialiser;
@ -37,6 +38,11 @@ using Nini.Config;
namespace OpenSim.Region.Environment namespace OpenSim.Region.Environment
{ {
/// <summary>
/// Method called when all the necessary assets for an archive request have been received.
/// </summary>
public delegate void AssetsRequestCallback(IDictionary<LLUUID, AssetBase> assets);
/// <summary> /// <summary>
/// Handles an individual archive request /// Handles an individual archive request
/// </summary> /// </summary>
@ -83,9 +89,17 @@ namespace OpenSim.Region.Environment
{ {
m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count); m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count);
m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} textures", textureUuids.Count); m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} textures", textureUuids.Count);
// Asynchronously request all the assets required to perform this archive operation
new AssetsRequest(ReceivedAllAssets, m_scene.AssetCache, textureUuids.Keys);
} }
} }
protected internal void ReceivedAllAssets(IDictionary<LLUUID, AssetBase> assets)
{
m_log.DebugFormat("[ARCHIVER]: Received all {0} textures required", assets.Count);
}
/// <summary> /// <summary>
/// Get an xml representation of the given scene objects. /// Get an xml representation of the given scene objects.
/// </summary> /// </summary>
@ -113,4 +127,61 @@ namespace OpenSim.Region.Environment
return serialization; return serialization;
} }
} }
/// <summary>
/// Encapsulate the asynchronous requests for the assets required for an archive operation
/// </summary>
class AssetsRequest
{
/// <summary>
/// Callback used when all the assets requested have been received.
/// </summary>
protected AssetsRequestCallback m_assetsRequestCallback;
/// <summary>
/// Assets retrieved in this request
/// </summary>
protected Dictionary<LLUUID, AssetBase> m_assets = new Dictionary<LLUUID, AssetBase>();
/// <summary>
/// Record the number of asset replies required so we know when we've finished
/// </summary>
private int m_repliesRequired;
/// <summary>
/// Asset cache used to request the assets
/// </summary>
protected AssetCache m_assetCache;
protected internal AssetsRequest(AssetsRequestCallback assetsRequestCallback, AssetCache assetCache, ICollection<LLUUID> uuids)
{
m_assetsRequestCallback = assetsRequestCallback;
m_assetCache = assetCache;
m_repliesRequired = uuids.Count;
// We can stop here if there are no assets to fetch
if (m_repliesRequired == 0)
m_assetsRequestCallback(m_assets);
foreach (LLUUID uuid in uuids)
{
m_assetCache.GetAsset(uuid, AssetRequestCallback, true);
}
}
/// <summary>
/// Called back by the asset cache when it has the asset
/// </summary>
/// <param name="assetID"></param>
/// <param name="asset"></param>
public void AssetRequestCallback(LLUUID assetID, AssetBase asset)
{
m_assets[assetID] = asset;
if (m_assets.Count == m_repliesRequired)
{
m_assetsRequestCallback(m_assets);
}
}
}
} }