* Stop asset transactions hanging around after they've completed

* Still not enough to solve the memory leak, though hopefully this is another step on the path
* All these changes are pretty temporary - this will be addressed with a more fundamental refactor in the future
ThreadPoolClientBranch
Justin Clarke Casey 2008-02-08 23:42:19 +00:00
parent fadf5b479f
commit 16f8f19a54
2 changed files with 79 additions and 11 deletions

View File

@ -25,13 +25,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using libsecondlife;
namespace OpenSim.Framework.Communications.Cache
{
public class AssetTransactionManager
{
private static readonly log4net.ILog m_log
= log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Fields
public CommunicationsManager CommsManager;
@ -92,7 +98,17 @@ namespace OpenSim.Framework.Communications.Cache
AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
if (uploader != null)
{
uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
// Upload has already compelted uploading...
if (uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile))
{
lock (transactions.XferUploaders)
{
// XXX Weak ass way of doing this by directly manipulating this public dictionary, purely temporary
transactions.XferUploaders.Remove(uploader.TransactionID);
m_log.Info(String.Format("[ASSET TRANSACTIONS] Current uploaders: {0}", transactions.XferUploaders.Count));
}
}
}
}
}

View File

@ -37,6 +37,9 @@ namespace OpenSim.Framework.Communications.Cache
{
public class AgentAssetTransactions
{
private static readonly log4net.ILog m_log
= log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Fields
public List<AssetCapsUploader> CapsUploaders = new List<AssetCapsUploader>();
public List<NoteCardCapsUpdate> NotecardUpdaters = new List<NoteCardCapsUpdate>();
@ -73,22 +76,48 @@ namespace OpenSim.Framework.Communications.Cache
{
AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);
lock (XferUploaders)
{
XferUploaders.Add(transactionID, uploader);
}
return uploader;
}
return null;
}
public void HandleXfer(ulong xferID, uint packetID, byte[] data)
{
AssetXferUploader uploaderFound = null;
lock (XferUploaders)
{
foreach (AssetXferUploader uploader in XferUploaders.Values)
{
if (uploader.XferID == xferID)
{
uploader.HandleXferPacket(xferID, packetID, data);
if (uploader.HandleXferPacket(xferID, packetID, data))
{
uploaderFound = uploader;
}
break;
}
}
// Remove the uploader once the uploader is complete
if (uploaderFound != null)
{
m_log.Info(
String.Format(
"[ASSET TRANSACTIONS] Removing asset xfer uploader with transfer id {0}, transaction {1}",
xferID, uploaderFound.TransactionID));
XferUploaders.Remove(uploaderFound.TransactionID);
m_log.Info(String.Format("[ASSET TRANSACTIONS] Current uploaders: {0}", XferUploaders.Count));
}
}
}
public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
@ -114,7 +143,11 @@ namespace OpenSim.Framework.Communications.Cache
{
AssetXferUploader uploader = XferUploaders[transactionID];
AssetBase asset = uploader.GetAssetData();
lock (XferUploaders)
{
XferUploaders.Remove(transactionID);
}
return asset;
}
@ -150,8 +183,14 @@ namespace OpenSim.Framework.Communications.Cache
m_dumpAssetToFile = dumpAssetToFile;
}
// Methods
public void HandleXferPacket(ulong xferID, uint packetID, byte[] data)
/// <summary>
/// Process transfer data received from the client.
/// </summary>
/// <param name="xferID"></param>
/// <param name="packetID"></param>
/// <param name="data"></param>
/// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns>
public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data)
{
if (XferID == xferID)
{
@ -175,11 +214,21 @@ namespace OpenSim.Framework.Communications.Cache
if ((packetID & 0x80000000) != 0)
{
SendCompleteMessage();
}
return true;
}
}
public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data,
return false;
}
/// <summary>
/// Initialise asset transfer from the client
/// </summary>
/// <param name="xferID"></param>
/// <param name="packetID"></param>
/// <param name="data"></param>
/// <returns>True if the transfer is complete, false otherwise</returns>
public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data,
bool storeLocal, bool tempFile)
{
ourClient = remoteClient;
@ -198,11 +247,14 @@ namespace OpenSim.Framework.Communications.Cache
if (Asset.Data.Length > 2)
{
SendCompleteMessage();
return true;
}
else
{
ReqestStartXfer();
}
return false;
}
protected void ReqestStartXfer()