org.apache.blur.store.blockcache_v2
Class BaseCache

java.lang.Object
  extended by org.apache.blur.store.blockcache_v2.Cache
      extended by org.apache.blur.store.blockcache_v2.BaseCache
All Implemented Interfaces:
Closeable

public class BaseCache
extends Cache
implements Closeable


Nested Class Summary
static class BaseCache.STORE
           
 
Constructor Summary
BaseCache(long totalNumberOfBytes, Size fileBufferSize, Size cacheBlockSize, FileNameFilter readFilter, FileNameFilter writeFilter, Quiet quiet, BaseCache.STORE store)
           
 
Method Summary
 boolean cacheFileForReading(CacheDirectory directory, String fileName, org.apache.lucene.store.IOContext context)
          Checks whether file should be cached or not during reading.
 boolean cacheFileForWriting(CacheDirectory directory, String fileName, org.apache.lucene.store.IOContext context)
          Checks whether file should be cached or not during writing.
 void close()
           
 void fileClosedForWriting(CacheDirectory directory, String fileName, long fileId)
          The cache internals rely on the last modified timestamp of a given file to know if the file is the same or not.
 CacheValue get(CacheKey key)
          Gets the cache value for the given key.
 int getCacheBlockSize(CacheDirectory directory, String fileName)
          Get capacity of each cache entry for the given file.
 int getFileBufferSize(CacheDirectory directory, String fileName)
          Gets buffer size of the buffer used while interacting with the underlying directory.
 long getFileId(CacheDirectory directory, String fileName)
          Gets unique id for the given file.
 CacheValue getQuietly(CacheKey key)
          Gets the cache value for the given key.
 CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize)
          Creates a new instance of CacheValue, the cache capacity should be used for the given file.
 void put(CacheKey key, CacheValue value)
          Puts the cache entry into the cache.
 void releaseDirectory(String directoryName)
          This is called when the CacheDirectory is finalized.
 void removeFile(CacheDirectory directory, String fileName)
          Removes the file from the cache.
 boolean shouldBeQuiet(CacheDirectory directory, String fileName)
          Determines if the reader should be quiet or not.
 
Methods inherited from class org.apache.blur.store.blockcache_v2.Cache
newInstance
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseCache

public BaseCache(long totalNumberOfBytes,
                 Size fileBufferSize,
                 Size cacheBlockSize,
                 FileNameFilter readFilter,
                 FileNameFilter writeFilter,
                 Quiet quiet,
                 BaseCache.STORE store)
Method Detail

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

shouldBeQuiet

public boolean shouldBeQuiet(CacheDirectory directory,
                             String fileName)
Description copied from class: Cache
Determines if the reader should be quiet or not.

Specified by:
shouldBeQuiet in class Cache
Parameters:
directory - the directory.
fileName - the file name.
Returns:
boolean.

newInstance

public CacheValue newInstance(CacheDirectory directory,
                              String fileName,
                              int cacheBlockSize)
Description copied from class: Cache
Creates a new instance of CacheValue, the cache capacity should be used for the given file.

Specified by:
newInstance in class Cache
Parameters:
directory - the directory.
fileName - the file name.
cacheBlockSize - the length of the CacheValue.
Returns:
the new CacheValue instance.

getFileId

public long getFileId(CacheDirectory directory,
                      String fileName)
               throws IOException
Description copied from class: Cache
Gets unique id for the given file. This is assumed to be unique even if the file is deleted and recreated.

Specified by:
getFileId in class Cache
Parameters:
directory - the directory.
fileName - the file name.
Returns:
the file id.
Throws:
IOException

removeFile

public void removeFile(CacheDirectory directory,
                       String fileName)
                throws IOException
Description copied from class: Cache
Removes the file from the cache.

Specified by:
removeFile in class Cache
Parameters:
directory - the directory.
fileName - the file name.
Throws:
IOException

fileClosedForWriting

public void fileClosedForWriting(CacheDirectory directory,
                                 String fileName,
                                 long fileId)
                          throws IOException
Description copied from class: Cache
The cache internals rely on the last modified timestamp of a given file to know if the file is the same or not. During the writing of a given file the last moified date is not know, so this method tells the cache that the file has completed the writing phase and the last modified time should now be accurate.

Specified by:
fileClosedForWriting in class Cache
fileId - the file id.
Throws:
IOException

getCacheBlockSize

public int getCacheBlockSize(CacheDirectory directory,
                             String fileName)
Description copied from class: Cache
Get capacity of each cache entry for the given file.

Specified by:
getCacheBlockSize in class Cache
Parameters:
directory - the directory.
fileName - the file name.
Returns:
the capacity.

getFileBufferSize

public int getFileBufferSize(CacheDirectory directory,
                             String fileName)
Description copied from class: Cache
Gets buffer size of the buffer used while interacting with the underlying directory.

Specified by:
getFileBufferSize in class Cache
Parameters:
directory - the directory.
fileName - the file name.
Returns:
the buffer size.

cacheFileForReading

public boolean cacheFileForReading(CacheDirectory directory,
                                   String fileName,
                                   org.apache.lucene.store.IOContext context)
Description copied from class: Cache
Checks whether file should be cached or not during reading.

Specified by:
cacheFileForReading in class Cache
Parameters:
directory - the directory.
fileName - the file name.
context - the IOContext from Lucene.
Returns:
boolean.

cacheFileForWriting

public boolean cacheFileForWriting(CacheDirectory directory,
                                   String fileName,
                                   org.apache.lucene.store.IOContext context)
Description copied from class: Cache
Checks whether file should be cached or not during writing.

Specified by:
cacheFileForWriting in class Cache
Parameters:
directory - the directory.
fileName - the file name.
context - the IOContext from Lucene.
Returns:
boolean.

get

public CacheValue get(CacheKey key)
Description copied from class: Cache
Gets the cache value for the given key. Null if missing.

Specified by:
get in class Cache
Parameters:
key - the key.
Returns:
the cache value or null.

getQuietly

public CacheValue getQuietly(CacheKey key)
Description copied from class: Cache
Gets the cache value for the given key. Null if missing. NOTE: This method will not effect the priority of the cache.

Specified by:
getQuietly in class Cache
Parameters:
key - the key.
Returns:
the cache value or null.

put

public void put(CacheKey key,
                CacheValue value)
Description copied from class: Cache
Puts the cache entry into the cache.

Specified by:
put in class Cache
Parameters:
key - the key.
value - the value.

releaseDirectory

public void releaseDirectory(String directoryName)
Description copied from class: Cache
This is called when the CacheDirectory is finalized.

Specified by:
releaseDirectory in class Cache
Parameters:
directoryName - the directory name.


Copyright © 2012-2014 The Apache Software Foundation. All Rights Reserved.