public class LogBufferedFileCache extends LogFileCache implements ILogMap
LogFileCache.LogCacheInfo| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_WRITEBUFFERSIZE |
static java.lang.String |
WRITEBUFFERSIZE_PROPERTY_NAME |
file, index, logID, replacedLogs| Constructor and Description |
|---|
LogBufferedFileCache()
Build a LogBufferedFileCache with the default sizes for
the write buffer
|
LogBufferedFileCache(int writeBufferSize)
Build a LogBufferedFileCache with the given size for the cache and the
write buffer.
|
| Modifier and Type | Method and Description |
|---|---|
int |
add(ILogEntry log)
Append a log to the cache
|
void |
clear()
Empty the cache
|
void |
deleteLog(java.lang.Integer key)
Delete a log with the given key
|
void |
deleteLogs(java.util.Collection<java.lang.Integer> keys)
Delete a collection of logs
|
void |
flushBuffer()
Flush all the logs on file
|
int |
getBufferSize() |
long |
getFileSize()
Return the length of the file on disk taking into account
the length of the string to write on the disk for the logs in the
buffer.
|
java.lang.Integer |
getFirstLog()
Return the key of the first valid log (FIFO).
|
int |
getFirstLogs(int n,
java.util.Collection<java.lang.Integer> keys)
Append at most n keys from the first valid logs to the collection.
|
java.lang.Integer |
getLastLog()
Return the key of the last valid log (FIFO)
The key of the last log is the key of the last inserted log
but it can cheang if such log has been deleted
|
ILogEntry |
getLog(java.lang.Integer key)
Return the log with the given key
|
int |
getSize()
Return the number of logs in cache
|
java.util.Iterator<ILogEntry> |
iterator()
Return an iterator over the logs in cache
|
java.util.Set<java.lang.Integer> |
keySet()
Return a set with all the keys of the logs in cache
|
void |
replaceLog(java.lang.Integer key,
ILogEntry log)
Replace the log in the given position with the new one
|
initCache, toCacheStringpublic static final java.lang.String WRITEBUFFERSIZE_PROPERTY_NAME
public static final int DEFAULT_WRITEBUFFERSIZE
public LogBufferedFileCache(int writeBufferSize)
throws LogCacheException
cacheSize - The size of the cachewriteBufferSize - The size of the write bufferLogCacheException - If there is'nt enough memory for a buffer of at least 32 logspublic LogBufferedFileCache()
throws LogCacheException
LogCacheExceptionLogBufferedFileCache.getDefaultWriteCacheSizepublic void clear()
throws LogCacheException
clear in interface ILogMapclear in class LogFileCachejava.io.IOExceptionLogCacheExceptionpublic ILogEntry getLog(java.lang.Integer key) throws LogCacheException
getLog in interface ILogMapgetLog in class LogFileCachekey - The key of the logLogCacheExceptionpublic void deleteLog(java.lang.Integer key)
throws LogCacheException
deleteLog in interface ILogMapdeleteLog in class LogFileCachepos - The key of the log to deleteLogCacheExceptionpublic void deleteLogs(java.util.Collection<java.lang.Integer> keys)
throws LogCacheException
deleteLogs in interface ILogMapdeleteLogs in class LogFileCachekeys - The keys of the logs to remove from the cacheLogCacheExceptionpublic int add(ILogEntry log) throws LogCacheException
add in interface ILogMapadd in class LogFileCachelog - The log to append in the cacheLogCacheExceptionpublic void flushBuffer()
throws LogCacheException
LogCacheExceptionpublic int getSize()
getSize in interface ILogMapgetSize in class LogFileCachepublic long getFileSize()
throws java.io.IOException
getFileSize in class LogFileCachejava.io.IOException - in case of I/O errorRandomAccessFilepublic final int getBufferSize()
public java.lang.Integer getFirstLog()
getFirstLog in interface ILogMapgetFirstLog in class LogFileCachepublic int getFirstLogs(int n,
java.util.Collection<java.lang.Integer> keys)
getFirstLogs in interface ILogMapgetFirstLogs in class LogFileCachen - The desired number of keys of first logskeys - The collection to add they keys topublic java.lang.Integer getLastLog()
getLastLog in interface ILogMapgetLastLog in class LogFileCachepublic java.util.Set<java.lang.Integer> keySet()
keySet in interface ILogMapkeySet in class LogFileCachepublic java.util.Iterator<ILogEntry> iterator()
iterator in interface ILogMapiterator in class LogFileCachepublic void replaceLog(java.lang.Integer key,
ILogEntry log)
throws LogCacheException
If the log to replace is not in the buffer, LogBufferedFileCache
delegated to LogFileCache
replaceLog in interface ILogMapreplaceLog in class LogFileCacheposition - The position of the log to replacelog - The key (identifier) of the logLogCacheException