2009-02-12 09:53:12 +00:00
|
|
|
/*
|
2008-06-17 08:14:58 +00:00
|
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2009-06-01 06:37:14 +00:00
|
|
|
* * Neither the name of the OpenSimulator Project nor the
|
2008-06-17 08:14:58 +00:00
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2009-02-12 18:59:45 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Threading;
|
|
|
|
using log4net;
|
|
|
|
using OpenMetaverse;
|
|
|
|
using OpenSim.Framework;
|
2009-05-14 20:37:54 +00:00
|
|
|
using OpenSim.Framework.Serialization;
|
2009-05-15 05:00:25 +00:00
|
|
|
using OpenSim.Services.Interfaces;
|
2009-02-12 18:59:45 +00:00
|
|
|
|
2009-02-10 13:10:57 +00:00
|
|
|
namespace OpenSim.Region.CoreModules.World.Archiver
|
2008-06-17 08:14:58 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Encapsulate the asynchronous requests for the assets required for an archive operation
|
|
|
|
/// </summary>
|
|
|
|
class AssetsRequest
|
|
|
|
{
|
2008-11-04 21:19:00 +00:00
|
|
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
2008-08-18 00:39:10 +00:00
|
|
|
|
2009-05-14 20:37:54 +00:00
|
|
|
/// <value>
|
2008-06-17 08:14:58 +00:00
|
|
|
/// uuids to request
|
2009-05-14 20:37:54 +00:00
|
|
|
/// </value>
|
2008-09-06 07:52:41 +00:00
|
|
|
protected ICollection<UUID> m_uuids;
|
2008-08-18 00:39:10 +00:00
|
|
|
|
2009-05-14 20:37:54 +00:00
|
|
|
/// <value>
|
2008-06-17 08:14:58 +00:00
|
|
|
/// Callback used when all the assets requested have been received.
|
2009-05-14 20:37:54 +00:00
|
|
|
/// </value>
|
2008-06-17 08:14:58 +00:00
|
|
|
protected AssetsRequestCallback m_assetsRequestCallback;
|
|
|
|
|
2009-05-14 20:37:54 +00:00
|
|
|
/// <value>
|
|
|
|
/// List of assets that were found. This will be passed back to the requester.
|
|
|
|
/// </value>
|
|
|
|
protected List<UUID> m_foundAssetUuids = new List<UUID>();
|
|
|
|
|
|
|
|
/// <value>
|
2008-07-21 17:13:32 +00:00
|
|
|
/// Maintain a list of assets that could not be found. This will be passed back to the requester.
|
2009-05-14 20:37:54 +00:00
|
|
|
/// </value>
|
2008-09-06 07:52:41 +00:00
|
|
|
protected List<UUID> m_notFoundAssetUuids = new List<UUID>();
|
2008-06-17 08:14:58 +00:00
|
|
|
|
2009-05-14 20:37:54 +00:00
|
|
|
/// <value>
|
2008-06-17 08:14:58 +00:00
|
|
|
/// Record the number of asset replies required so we know when we've finished
|
2009-05-14 20:37:54 +00:00
|
|
|
/// </value>
|
2008-06-17 08:14:58 +00:00
|
|
|
private int m_repliesRequired;
|
|
|
|
|
2009-05-14 20:37:54 +00:00
|
|
|
/// <value>
|
2009-06-01 16:00:46 +00:00
|
|
|
/// Asset service used to request the assets
|
2009-05-14 20:37:54 +00:00
|
|
|
/// </value>
|
2009-06-01 16:00:46 +00:00
|
|
|
protected IAssetService m_assetService;
|
2008-06-17 08:14:58 +00:00
|
|
|
|
2009-05-14 20:37:54 +00:00
|
|
|
protected AssetsArchiver m_assetsArchiver;
|
|
|
|
|
2009-03-09 17:55:08 +00:00
|
|
|
protected internal AssetsRequest(
|
2009-05-14 20:37:54 +00:00
|
|
|
AssetsArchiver assetsArchiver, ICollection<UUID> uuids,
|
2009-06-01 16:00:46 +00:00
|
|
|
IAssetService assetService, AssetsRequestCallback assetsRequestCallback)
|
2008-06-17 08:14:58 +00:00
|
|
|
{
|
2009-05-14 20:37:54 +00:00
|
|
|
m_assetsArchiver = assetsArchiver;
|
2008-06-17 08:14:58 +00:00
|
|
|
m_uuids = uuids;
|
|
|
|
m_assetsRequestCallback = assetsRequestCallback;
|
2009-06-01 16:00:46 +00:00
|
|
|
m_assetService = assetService;
|
2008-06-17 08:14:58 +00:00
|
|
|
m_repliesRequired = uuids.Count;
|
|
|
|
}
|
2008-08-18 00:39:10 +00:00
|
|
|
|
2008-06-17 08:14:58 +00:00
|
|
|
protected internal void Execute()
|
|
|
|
{
|
2009-03-13 20:46:53 +00:00
|
|
|
m_log.DebugFormat("[ARCHIVER]: AssetsRequest executed looking for {0} assets", m_repliesRequired);
|
|
|
|
|
2008-06-17 08:14:58 +00:00
|
|
|
// We can stop here if there are no assets to fetch
|
|
|
|
if (m_repliesRequired == 0)
|
2009-06-01 16:00:46 +00:00
|
|
|
PerformAssetsRequestCallback();
|
|
|
|
|
2008-09-06 07:52:41 +00:00
|
|
|
foreach (UUID uuid in m_uuids)
|
2008-06-17 08:14:58 +00:00
|
|
|
{
|
2009-06-01 16:00:46 +00:00
|
|
|
m_assetService.Get(uuid.ToString(), this, AssetRequestCallback);
|
2008-06-17 08:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called back by the asset cache when it has the asset
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="assetID"></param>
|
|
|
|
/// <param name="asset"></param>
|
2009-05-15 20:20:55 +00:00
|
|
|
public void AssetRequestCallback(string id, object sender, AssetBase asset)
|
2008-06-17 08:14:58 +00:00
|
|
|
{
|
2009-06-01 16:00:46 +00:00
|
|
|
try
|
2009-03-09 17:55:08 +00:00
|
|
|
{
|
2009-06-01 16:00:46 +00:00
|
|
|
lock (this)
|
|
|
|
{
|
|
|
|
//m_log.DebugFormat("[ARCHIVER]: Received callback for asset {0}", id);
|
|
|
|
|
|
|
|
if (asset != null)
|
|
|
|
{
|
|
|
|
m_foundAssetUuids.Add(asset.FullID);
|
|
|
|
m_assetsArchiver.WriteAsset(asset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_notFoundAssetUuids.Add(new UUID(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_foundAssetUuids.Count + m_notFoundAssetUuids.Count == m_repliesRequired)
|
|
|
|
{
|
|
|
|
m_log.DebugFormat(
|
2009-06-02 15:24:29 +00:00
|
|
|
"[ARCHIVER]: Successfully added {0} assets ({1} assets notified missing)",
|
2009-06-01 16:00:46 +00:00
|
|
|
m_foundAssetUuids.Count, m_notFoundAssetUuids.Count);
|
|
|
|
|
|
|
|
// We want to stop using the asset cache thread asap
|
|
|
|
// as we now need to do the work of producing the rest of the archive
|
|
|
|
Thread newThread = new Thread(PerformAssetsRequestCallback);
|
|
|
|
newThread.Name = "OpenSimulator archiving thread post assets receipt";
|
|
|
|
newThread.Start();
|
|
|
|
}
|
|
|
|
}
|
2009-03-09 17:55:08 +00:00
|
|
|
}
|
2009-06-01 16:00:46 +00:00
|
|
|
catch (Exception e)
|
2008-06-17 08:14:58 +00:00
|
|
|
{
|
2009-06-02 15:24:29 +00:00
|
|
|
m_log.ErrorFormat("[ARCHIVER]: AssetRequestCallback failed with {0}", e);
|
2008-06-17 08:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Perform the callback on the original requester of the assets
|
|
|
|
/// </summary>
|
|
|
|
protected void PerformAssetsRequestCallback()
|
|
|
|
{
|
2008-11-04 21:19:00 +00:00
|
|
|
try
|
|
|
|
{
|
2009-05-14 20:37:54 +00:00
|
|
|
m_assetsRequestCallback(m_foundAssetUuids, m_notFoundAssetUuids);
|
2008-11-04 21:19:00 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
m_log.ErrorFormat(
|
|
|
|
"[ARCHIVER]: Terminating archive creation since asset requster callback failed with {0}", e);
|
|
|
|
}
|
2008-06-17 08:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|