* Remove unused texture dictionaries from AssetCache

* Add documentation to AssetCache
ThreadPoolClientBranch
Justin Clarke Casey 2008-02-20 19:02:04 +00:00
parent a8cfbbe963
commit 53d5aeec24
2 changed files with 73 additions and 48 deletions

View File

@ -41,38 +41,60 @@ namespace OpenSim.Framework.Communications.Cache
/// <summary> /// <summary>
/// Manages local cache of assets and their sending to viewers. /// Manages local cache of assets and their sending to viewers.
///
/// This class actually encapsulates two largely separate mechanisms. One mechanism fetches assets either
/// synchronously or async and passes the data back to the requester. The second mechanism fetches assets and
/// sends packetised data directly back to the client. The only point where they meets is AssetReceived() and
/// AssetNotFound().
///
/// TODO Assets in this cache are effectively immortal (they are never disposed off through old age).
/// This is not a huge problem at the moment since other memory use usually dwarfs that used by assets
/// but it's something to bear in mind.
/// </summary> /// </summary>
public class AssetCache : IAssetReceiver public class AssetCache : IAssetReceiver
{ {
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog m_log
= log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Dictionary<LLUUID, AssetInfo> Assets; /// <summary>
public Dictionary<LLUUID, TextureImage> Textures; /// The cache of assets. This does not include textures.
/// </summary>
private Dictionary<LLUUID, AssetInfo> Assets;
public List<AssetRequest> AssetRequests; //assets ready to be sent to viewers /// <summary>
public List<AssetRequest> TextureRequests; //textures ready to be sent /// The cache of textures.
/// </summary>
private Dictionary<LLUUID, TextureImage> Textures;
public Dictionary<LLUUID, AssetRequest> RequestedAssets; /// <summary>
//Assets requested from the asset server /// Assets requests which are waiting for asset server data. This includes texture requests
/// </summary>
private Dictionary<LLUUID, AssetRequest> RequestedAssets;
public Dictionary<LLUUID, AssetRequest> RequestedTextures; /// <summary>
//Textures requested from the asset server /// Asset requests with data which are ready to be sent back to requesters. This includes textures.
/// </summary>
private List<AssetRequest> AssetRequests;
public Dictionary<LLUUID, AssetRequestsList> RequestLists; /// <summary>
/// Until the asset request is fulfilled, each asset request is associated with a list of requesters
/// </summary>
private Dictionary<LLUUID, AssetRequestsList> RequestLists;
private readonly IAssetServer m_assetServer; private readonly IAssetServer m_assetServer;
private readonly Thread m_assetCacheThread; private readonly Thread m_assetCacheThread;
/// <summary>
/// Report statistical data.
/// </summary>
public void ShowState() public void ShowState()
{ {
m_log.InfoFormat("Assets:{0} Textures:{1} AssetRequests:{2} TextureRequests:{3} RequestedAssets:{4} RequestedTextures:{5} RequestLists:{6}", m_log.InfoFormat("Assets:{0} Textures:{1} AssetRequests:{2} RequestedAssets:{3} RequestLists:{4}",
Assets.Count, Assets.Count,
Textures.Count, Textures.Count,
AssetRequests.Count, AssetRequests.Count,
TextureRequests.Count,
RequestedAssets.Count, RequestedAssets.Count,
RequestedTextures.Count,
RequestLists.Count); RequestLists.Count);
int temporaryImages = 0; int temporaryImages = 0;
@ -81,9 +103,6 @@ namespace OpenSim.Framework.Communications.Cache
long imageBytes = 0; long imageBytes = 0;
long assetBytes = 0; long assetBytes = 0;
foreach (TextureImage texture in Textures.Values) foreach (TextureImage texture in Textures.Values)
{ {
if (texture.Temporary) if (texture.Temporary)
@ -114,25 +133,32 @@ namespace OpenSim.Framework.Communications.Cache
} }
/// <summary>
/// Clear the asset cache.
/// </summary>
public void Clear() public void Clear()
{ {
m_log.Info("[ASSET CACHE]: Clearing Asset cache"); m_log.Info("[ASSET CACHE]: Clearing Asset cache");
Initialize(); Initialize();
} }
/// <summary>
/// Initialize the cache.
/// </summary>
private void Initialize() private void Initialize()
{ {
Assets = new Dictionary<LLUUID, AssetInfo>(); Assets = new Dictionary<LLUUID, AssetInfo>();
Textures = new Dictionary<LLUUID, TextureImage>(); Textures = new Dictionary<LLUUID, TextureImage>();
AssetRequests = new List<AssetRequest>(); //assets ready to be sent to viewers AssetRequests = new List<AssetRequest>();
TextureRequests = new List<AssetRequest>(); //textures ready to be sent
RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); RequestedAssets = new Dictionary<LLUUID, AssetRequest>();
RequestedTextures = new Dictionary<LLUUID, AssetRequest>();
RequestLists = new Dictionary<LLUUID, AssetRequestsList>(); RequestLists = new Dictionary<LLUUID, AssetRequestsList>();
} }
/// <summary>
/// Constructor. Initialize will need to be called separately.
/// </summary>
/// <param name="assetServer"></param>
public AssetCache(IAssetServer assetServer) public AssetCache(IAssetServer assetServer)
{ {
m_log.Info("[ASSET CACHE]: Creating Asset cache"); m_log.Info("[ASSET CACHE]: Creating Asset cache");
@ -148,7 +174,8 @@ namespace OpenSim.Framework.Communications.Cache
} }
/// <summary> /// <summary>
/// /// Process the asset queue which holds data which is packeted up and sent
/// directly back to the client.
/// </summary> /// </summary>
public void RunAssetManager() public void RunAssetManager()
{ {
@ -359,6 +386,12 @@ namespace OpenSim.Framework.Communications.Cache
m_log.InfoFormat("[ASSET CACHE]: Adding {0} {1} [{2}]: {3}.", temporary, type, asset.FullID, result); m_log.InfoFormat("[ASSET CACHE]: Adding {0} {1} [{2}]: {3}.", temporary, type, asset.FullID, result);
} }
/// <summary>
/// Copy an asset and add it to the cache with a new assetID.
/// XXX We shouldn't actually ever need to do this!
/// </summary>
/// <param name="assetID"></param>
/// <returns></returns>
public AssetBase CopyAsset(LLUUID assetID) public AssetBase CopyAsset(LLUUID assetID)
{ {
AssetBase asset; AssetBase asset;
@ -402,19 +435,6 @@ namespace OpenSim.Framework.Communications.Cache
{ {
StatsManager.SimExtraStats.AddTexture(image); StatsManager.SimExtraStats.AddTexture(image);
} }
if (RequestedTextures.ContainsKey(image.FullID))
{
m_log.InfoFormat("[ASSET CACHE]: Moving {0} from RequestedTextures to TextureRequests", asset.FullID);
AssetRequest req = RequestedTextures[image.FullID];
req.ImageInfo = image;
req.NumPackets = CalculateNumPackets(image.Data);
RequestedTextures.Remove(image.FullID);
TextureRequests.Add(req);
}
} }
} }
else else
@ -422,7 +442,7 @@ namespace OpenSim.Framework.Communications.Cache
AssetInfo assetInf = new AssetInfo(asset); AssetInfo assetInf = new AssetInfo(asset);
if (Assets.ContainsKey(assetInf.FullID)) if (Assets.ContainsKey(assetInf.FullID))
{ {
m_log.InfoFormat("[ASSET CACHE]: There's already an asset {0} in memory. Skipping.", asset.FullID); m_log.DebugFormat("[ASSET CACHE]: There's already an asset {0} in memory. Skipping.", asset.FullID);
} }
else else
{ {
@ -435,7 +455,7 @@ namespace OpenSim.Framework.Communications.Cache
if (RequestedAssets.ContainsKey(assetInf.FullID)) if (RequestedAssets.ContainsKey(assetInf.FullID))
{ {
m_log.InfoFormat("[ASSET CACHE]: Moving {0} from RequestedAssets to AssetRequests", asset.FullID); m_log.DebugFormat("[ASSET CACHE]: Moving {0} from RequestedAssets to AssetRequests", asset.FullID);
AssetRequest req = RequestedAssets[assetInf.FullID]; AssetRequest req = RequestedAssets[assetInf.FullID];
req.AssetInf = assetInf; req.AssetInf = assetInf;
@ -447,6 +467,7 @@ namespace OpenSim.Framework.Communications.Cache
} }
} }
// Notify requesters for this asset
if (RequestLists.ContainsKey(asset.FullID)) if (RequestLists.ContainsKey(asset.FullID))
{ {
lock (RequestLists) lock (RequestLists)
@ -503,6 +524,11 @@ namespace OpenSim.Framework.Communications.Cache
} }
} }
/// <summary>
/// Calculate the number of packets required to send the asset to the client.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private int CalculateNumPackets(byte[] data) private int CalculateNumPackets(byte[] data)
{ {
const uint m_maxPacketSize = 600; const uint m_maxPacketSize = 600;
@ -519,10 +545,8 @@ namespace OpenSim.Framework.Communications.Cache
return numPackets; return numPackets;
} }
#region Assets
/// <summary> /// <summary>
/// /// Make an asset request the result of which will be packeted up and sent directly back to the client.
/// </summary> /// </summary>
/// <param name="userInfo"></param> /// <param name="userInfo"></param>
/// <param name="transferRequest"></param> /// <param name="transferRequest"></param>
@ -577,7 +601,7 @@ namespace OpenSim.Framework.Communications.Cache
} }
/// <summary> /// <summary>
/// /// Process the asset queue which sends packets directly back to the client.
/// </summary> /// </summary>
private void ProcessAssetQueue() private void ProcessAssetQueue()
{ {
@ -672,8 +696,6 @@ namespace OpenSim.Framework.Communications.Cache
} }
} }
#endregion
public class AssetRequest public class AssetRequest
{ {
public IClientAPI RequestUser; public IClientAPI RequestUser;
@ -730,7 +752,6 @@ namespace OpenSim.Framework.Communications.Cache
} }
} }
public class AssetRequestsList public class AssetRequestsList
{ {
public LLUUID AssetID; public LLUUID AssetID;

View File

@ -120,6 +120,10 @@ namespace OpenSim.Framework.Communications.Cache
} }
} }
/// <summary>
/// The receiver will be called back with asset data once it comes in.
/// </summary>
/// <param name="receiver"></param>
public void SetReceiver(IAssetReceiver receiver) public void SetReceiver(IAssetReceiver receiver)
{ {
m_receiver = receiver; m_receiver = receiver;