Class CacheFileManagerImpl
- java.lang.Object
-
- com.biglybt.core.diskmanager.cache.impl.CacheFileManagerImpl
-
- All Implemented Interfaces:
CacheFileManager
,AEDiagnosticsEvidenceGenerator
public class CacheFileManagerImpl extends java.lang.Object implements CacheFileManager, AEDiagnosticsEvidenceGenerator
-
-
Field Summary
Fields Modifier and Type Field Description protected long
cache_bytes_read
protected long
cache_bytes_written
static int
CACHE_CLEANER_TICKS
protected boolean
cache_enabled
protected java.util.LinkedHashMap
cache_entries
private long
cache_file_id_next
protected java.util.WeakHashMap
cache_files
protected long
cache_files_not_smaller_than
protected long
cache_minimum_free_size
protected long
cache_read_count
protected boolean
cache_read_enabled
protected long
cache_size
protected long
cache_space_free
protected long
cache_write_count
protected boolean
cache_write_enabled
(package private) long
cleaner_ticks
static boolean
DEBUG
static long
DIRTY_CACHE_WRITE_MAX_AGE
protected long
file_bytes_read
protected long
file_bytes_written
protected FMFileManager
file_manager
protected long
file_read_count
protected long
file_write_count
private static LogIDs
LOGID
protected CacheFileManagerStatsImpl
stats
static int
STATS_UPDATE_FREQUENCY
protected AEMonitor
this_mon
protected java.util.Map
torrent_to_cache_file_map
protected java.util.WeakHashMap
updated_cache_files
-
Constructor Summary
Constructors Constructor Description CacheFileManagerImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addCacheSpace(CacheEntry new_entry)
protected CacheEntry
allocateCacheSpace(int entry_type, CacheFileWithCache file, DirectByteBuffer buffer, long file_position, int length)
allocates space but does NOT add it to the cache list due to synchronization issues.protected void
cacheBytesRead(int num)
protected void
cacheBytesWritten(long num)
protected void
cacheEntryUsed(CacheEntry entry)
protected void
cacheStatsAndCleaner()
protected void
closeFile(CacheFileWithCache file)
protected static int
convertCacheToFileType(int cache_type)
protected static int
convertFileToCacheType(int file_type)
CacheFile
createFile(CacheFileOwner owner, java.io.File file, int type, boolean force)
protected void
fileBytesRead(int num)
protected void
fileBytesWritten(long num)
void
generate(IndentWriter writer)
protected boolean[]
getBytesInCache(TOTorrent torrent, long[] absoluteOffsets, long[] lengths)
protected long
getBytesReadFromCache()
protected long
getBytesReadFromFile()
protected long
getBytesWrittenToCache()
protected long
getBytesWrittenToFile()
long
getCacheReadCount()
protected long
getCacheSize()
protected long
getCacheUsed()
long
getCacheWriteCount()
long
getFileReadCount()
long
getFileWriteCount()
CacheFileManagerStats
getStats()
protected void
initialise(boolean enabled, boolean enable_read, boolean enable_write, long size, long not_smaller_than)
protected boolean
isCacheEnabled()
protected boolean
isReadCacheEnabled()
protected boolean
isWriteCacheEnabled()
protected void
releaseCacheSpace(CacheEntry entry)
protected void
rethrow(CacheFile file, FMFileManagerException e)
void
setFileLinks(TOTorrent torrent, LinkFileMap links)
-
-
-
Field Detail
-
LOGID
private static final LogIDs LOGID
-
DEBUG
public static final boolean DEBUG
- See Also:
- Constant Field Values
-
CACHE_CLEANER_TICKS
public static final int CACHE_CLEANER_TICKS
- See Also:
- Constant Field Values
-
STATS_UPDATE_FREQUENCY
public static final int STATS_UPDATE_FREQUENCY
- See Also:
- Constant Field Values
-
DIRTY_CACHE_WRITE_MAX_AGE
public static final long DIRTY_CACHE_WRITE_MAX_AGE
- See Also:
- Constant Field Values
-
cache_enabled
protected boolean cache_enabled
-
cache_read_enabled
protected boolean cache_read_enabled
-
cache_write_enabled
protected boolean cache_write_enabled
-
cache_size
protected long cache_size
-
cache_files_not_smaller_than
protected long cache_files_not_smaller_than
-
cache_minimum_free_size
protected long cache_minimum_free_size
-
cache_space_free
protected long cache_space_free
-
cache_file_id_next
private long cache_file_id_next
-
file_manager
protected final FMFileManager file_manager
-
cache_files
protected java.util.WeakHashMap cache_files
-
updated_cache_files
protected java.util.WeakHashMap updated_cache_files
-
cache_entries
protected final java.util.LinkedHashMap cache_entries
-
stats
protected CacheFileManagerStatsImpl stats
-
torrent_to_cache_file_map
protected final java.util.Map torrent_to_cache_file_map
-
cache_bytes_written
protected long cache_bytes_written
-
cache_bytes_read
protected long cache_bytes_read
-
file_bytes_written
protected long file_bytes_written
-
file_bytes_read
protected long file_bytes_read
-
cache_read_count
protected long cache_read_count
-
cache_write_count
protected long cache_write_count
-
file_read_count
protected long file_read_count
-
file_write_count
protected long file_write_count
-
this_mon
protected final AEMonitor this_mon
-
cleaner_ticks
long cleaner_ticks
-
-
Method Detail
-
convertCacheToFileType
protected static int convertCacheToFileType(int cache_type)
-
convertFileToCacheType
protected static int convertFileToCacheType(int file_type)
-
initialise
protected void initialise(boolean enabled, boolean enable_read, boolean enable_write, long size, long not_smaller_than)
-
isWriteCacheEnabled
protected boolean isWriteCacheEnabled()
-
isReadCacheEnabled
protected boolean isReadCacheEnabled()
-
createFile
public CacheFile createFile(CacheFileOwner owner, java.io.File file, int type, boolean force) throws CacheFileManagerException
- Specified by:
createFile
in interfaceCacheFileManager
- Throws:
CacheFileManagerException
-
getStats
public CacheFileManagerStats getStats()
- Specified by:
getStats
in interfaceCacheFileManager
-
isCacheEnabled
protected boolean isCacheEnabled()
-
allocateCacheSpace
protected CacheEntry allocateCacheSpace(int entry_type, CacheFileWithCache file, DirectByteBuffer buffer, long file_position, int length) throws CacheFileManagerException
allocates space but does NOT add it to the cache list due to synchronization issues. Basically the caller mustn't hold their monitor when calling allocate, as a flush may result in one or more other files being flushed which results in their monitor being taken, and we've got an A->B and B->A classic deadlock situation. However, we must keep the file's cache and our cache in step. It is not acceptable to have an entry inserted into our records but not in the file's as this then screws up the flush algorithm (which assumes that if it finds an entry in our list, a flush of that file is guaranteed to release space). Therefore we add the cache entry in addCacheSpace so that the caller can safely do this while synchronised firstly on its monitor and then we can sync on our. Hence we only ever get A->B monitor grabs which won't deadlock- Parameters:
file
-buffer
-file_position
-length
-- Returns:
- Throws:
CacheFileManagerException
-
cacheStatsAndCleaner
protected void cacheStatsAndCleaner()
-
addCacheSpace
protected void addCacheSpace(CacheEntry new_entry) throws CacheFileManagerException
- Throws:
CacheFileManagerException
-
cacheEntryUsed
protected void cacheEntryUsed(CacheEntry entry) throws CacheFileManagerException
- Throws:
CacheFileManagerException
-
releaseCacheSpace
protected void releaseCacheSpace(CacheEntry entry) throws CacheFileManagerException
- Throws:
CacheFileManagerException
-
getCacheSize
protected long getCacheSize()
-
getCacheUsed
protected long getCacheUsed()
-
cacheBytesWritten
protected void cacheBytesWritten(long num)
-
cacheBytesRead
protected void cacheBytesRead(int num)
-
fileBytesWritten
protected void fileBytesWritten(long num)
-
fileBytesRead
protected void fileBytesRead(int num)
-
getBytesWrittenToCache
protected long getBytesWrittenToCache()
-
getBytesWrittenToFile
protected long getBytesWrittenToFile()
-
getBytesReadFromCache
protected long getBytesReadFromCache()
-
getBytesReadFromFile
protected long getBytesReadFromFile()
-
getCacheReadCount
public long getCacheReadCount()
-
getCacheWriteCount
public long getCacheWriteCount()
-
getFileReadCount
public long getFileReadCount()
-
getFileWriteCount
public long getFileWriteCount()
-
closeFile
protected void closeFile(CacheFileWithCache file)
-
getBytesInCache
protected boolean[] getBytesInCache(TOTorrent torrent, long[] absoluteOffsets, long[] lengths)
-
rethrow
protected void rethrow(CacheFile file, FMFileManagerException e) throws CacheFileManagerException
- Throws:
CacheFileManagerException
-
generate
public void generate(IndentWriter writer)
- Specified by:
generate
in interfaceAEDiagnosticsEvidenceGenerator
-
setFileLinks
public void setFileLinks(TOTorrent torrent, LinkFileMap links)
- Specified by:
setFileLinks
in interfaceCacheFileManager
-
-