Add a slow cache cleaner thread. By default, the thread starts a cleanup
sweep every 10 minutes. If any texture data is older than 12 hours, it is regenerated and the memory cache is refreshed. After each decode, the thread delays for 5 seconds.remotes/origin/0.6.7-post-fixes
parent
2a5b9f7740
commit
1a6b30e092
|
@ -30,6 +30,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using log4net;
|
using log4net;
|
||||||
using Nini.Config;
|
using Nini.Config;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
@ -38,6 +39,7 @@ using OpenMetaverse.Imaging;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
|
||||||
namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
||||||
{
|
{
|
||||||
|
@ -56,8 +58,11 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
||||||
private readonly Dictionary<UUID, OpenJPEG.J2KLayerInfo[]> m_cacheddecode = new Dictionary<UUID, OpenJPEG.J2KLayerInfo[]>();
|
private readonly Dictionary<UUID, OpenJPEG.J2KLayerInfo[]> m_cacheddecode = new Dictionary<UUID, OpenJPEG.J2KLayerInfo[]>();
|
||||||
private bool OpenJpegFail = false;
|
private bool OpenJpegFail = false;
|
||||||
private string CacheFolder = Util.dataDir() + "/j2kDecodeCache";
|
private string CacheFolder = Util.dataDir() + "/j2kDecodeCache";
|
||||||
private int CacheTimeout = 60;
|
private int CacheTimeout = 720;
|
||||||
private J2KDecodeFileCache fCache;
|
private J2KDecodeFileCache fCache = null;
|
||||||
|
private Thread CleanerThread = null;
|
||||||
|
private IAssetService AssetService = null;
|
||||||
|
private Scene m_Scene = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of client methods to notify of results of decode
|
/// List of client methods to notify of results of decode
|
||||||
|
@ -70,6 +75,9 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
||||||
|
|
||||||
public void Initialise(Scene scene, IConfigSource source)
|
public void Initialise(Scene scene, IConfigSource source)
|
||||||
{
|
{
|
||||||
|
if (m_Scene == null)
|
||||||
|
m_Scene = scene;
|
||||||
|
|
||||||
IConfig j2kConfig = source.Configs["J2KDecoder"];
|
IConfig j2kConfig = source.Configs["J2KDecoder"];
|
||||||
if (j2kConfig != null)
|
if (j2kConfig != null)
|
||||||
{
|
{
|
||||||
|
@ -77,14 +85,23 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
||||||
CacheTimeout = j2kConfig.GetInt("CacheTimeout", CacheTimeout);
|
CacheTimeout = j2kConfig.GetInt("CacheTimeout", CacheTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fCache = new J2KDecodeFileCache(CacheFolder, CacheTimeout);
|
if (fCache == null)
|
||||||
|
fCache = new J2KDecodeFileCache(CacheFolder, CacheTimeout);
|
||||||
|
|
||||||
scene.RegisterModuleInterface<IJ2KDecoder>(this);
|
scene.RegisterModuleInterface<IJ2KDecoder>(this);
|
||||||
|
|
||||||
|
if (CleanerThread == null && CacheTimeout != 0)
|
||||||
|
{
|
||||||
|
CleanerThread = new Thread(CleanCache);
|
||||||
|
CleanerThread.Name = "J2KCleanerThread";
|
||||||
|
CleanerThread.IsBackground = true;
|
||||||
|
CleanerThread.Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PostInitialise()
|
public void PostInitialise()
|
||||||
{
|
{
|
||||||
|
AssetService = m_Scene.AssetService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
|
@ -340,8 +357,9 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
||||||
// Cache Decoded layers
|
// Cache Decoded layers
|
||||||
lock (m_cacheddecode)
|
lock (m_cacheddecode)
|
||||||
{
|
{
|
||||||
if (!m_cacheddecode.ContainsKey(AssetId))
|
if (m_cacheddecode.ContainsKey(AssetId))
|
||||||
m_cacheddecode.Add(AssetId, layers);
|
m_cacheddecode.Remove(AssetId);
|
||||||
|
m_cacheddecode.Add(AssetId, layers);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,6 +377,28 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CleanCache()
|
||||||
|
{
|
||||||
|
m_log.Info("[J2KDecoderModule]: Cleaner thread started");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (AssetService != null)
|
||||||
|
fCache.ScanCacheFiles(RedecodeTexture);
|
||||||
|
|
||||||
|
System.Threading.Thread.Sleep(600000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RedecodeTexture(UUID assetID)
|
||||||
|
{
|
||||||
|
AssetBase texture = AssetService.Get(assetID.ToString());
|
||||||
|
if (texture == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
doJ2kDecode(assetID, texture.Data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class J2KDecodeFileCache
|
public class J2KDecodeFileCache
|
||||||
|
@ -656,7 +696,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
|
||||||
{
|
{
|
||||||
File.Delete(f.Name);
|
File.Delete(f.Name);
|
||||||
decode(AssetIdFromFileName(f.Name));
|
decode(AssetIdFromFileName(f.Name));
|
||||||
System.Threading.Thread.Sleep(2000);
|
System.Threading.Thread.Sleep(5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1371,7 +1371,7 @@
|
||||||
|
|
||||||
[J2KDecoder]
|
[J2KDecoder]
|
||||||
;CacheDir = "./j2kDecodeCache"
|
;CacheDir = "./j2kDecodeCache"
|
||||||
;CacheTimeout = 60
|
;CacheTimeout = 720
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; These are defaults that are overwritten below in [Architecture].
|
;; These are defaults that are overwritten below in [Architecture].
|
||||||
|
|
Loading…
Reference in New Issue