org.apache.blur.store.blockcache_v2
Class Cache

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

public abstract class Cache
extends Object
implements Closeable


Constructor Summary
Cache()
           
 
Method Summary
abstract  boolean cacheFileForReading(CacheDirectory directory, String fileName, org.apache.lucene.store.IOContext context)
          Checks whether file should be cached or not during reading.
abstract  boolean cacheFileForWriting(CacheDirectory directory, String fileName, org.apache.lucene.store.IOContext context)
          Checks whether file should be cached or not during writing.
abstract  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.
abstract  CacheValue get(CacheKey key)
          Gets the cache value for the given key.
abstract  int getCacheBlockSize(CacheDirectory directory, String fileName)
          Get capacity of each cache entry for the given file.
abstract  int getFileBufferSize(CacheDirectory directory, String fileName)
          Gets buffer size of the buffer used while interacting with the underlying directory.
abstract  long getFileId(CacheDirectory directory, String fileName)
          Gets unique id for the given file.
abstract  CacheValue getQuietly(CacheKey key)
          Gets the cache value for the given key.
 CacheValue newInstance(CacheDirectory directory, String fileName)
          Creates a new instance of CacheValue, the cache capacity should be used for the given file.
abstract  CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize)
          Creates a new instance of CacheValue, the cache capacity should be used for the given file.
abstract  void put(CacheKey key, CacheValue value)
          Puts the cache entry into the cache.
abstract  void releaseDirectory(String directoryName)
          This is called when the CacheDirectory is finalized.
abstract  void removeFile(CacheDirectory directory, String fileName)
          Removes the file from the cache.
abstract  boolean shouldBeQuiet(CacheDirectory directory, String fileName)
          Determines if the reader should be quiet or not.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.Closeable
close
 

Constructor Detail

Cache

public Cache()
Method Detail

newInstance

public CacheValue newInstance(CacheDirectory directory,
                              String fileName)
Creates a new instance of CacheValue, the cache capacity should be used for the given file.

Parameters:
directory - the directory.
fileName - the file name.
Returns:
the new CacheValue instance.

newInstance

public abstract CacheValue newInstance(CacheDirectory directory,
                                       String fileName,
                                       int cacheBlockSize)
Creates a new instance of CacheValue, the cache capacity should be used for the given file.

Parameters:
directory - the directory.
fileName - the file name.
cacheBlockSize - the length of the CacheValue.
Returns:
the new CacheValue instance.

getFileId

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

Parameters:
directory - the directory.
fileName - the file name.
Returns:
the file id.
Throws:
IOException

getCacheBlockSize

public abstract int getCacheBlockSize(CacheDirectory directory,
                                      String fileName)
Get capacity of each cache entry for the given file.

Parameters:
directory - the directory.
fileName - the file name.
Returns:
the capacity.

getFileBufferSize

public abstract int getFileBufferSize(CacheDirectory directory,
                                      String fileName)
Gets buffer size of the buffer used while interacting with the underlying directory.

Parameters:
directory - the directory.
fileName - the file name.
Returns:
the buffer size.

cacheFileForReading

public abstract boolean cacheFileForReading(CacheDirectory directory,
                                            String fileName,
                                            org.apache.lucene.store.IOContext context)
Checks whether file should be cached or not during reading.

Parameters:
directory - the directory.
fileName - the file name.
context - the IOContext from Lucene.
Returns:
boolean.

cacheFileForWriting

public abstract boolean cacheFileForWriting(CacheDirectory directory,
                                            String fileName,
                                            org.apache.lucene.store.IOContext context)
Checks whether file should be cached or not during writing.

Parameters:
directory - the directory.
fileName - the file name.
context - the IOContext from Lucene.
Returns:
boolean.

get

public abstract CacheValue get(CacheKey key)
Gets the cache value for the given key. Null if missing.

Parameters:
key - the key.
Returns:
the cache value or null.

getQuietly

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

Parameters:
key - the key.
Returns:
the cache value or null.

put

public abstract void put(CacheKey key,
                         CacheValue value)
Puts the cache entry into the cache.

Parameters:
key - the key.
value - the value.

removeFile

public abstract void removeFile(CacheDirectory directory,
                                String fileName)
                         throws IOException
Removes the file from the cache.

Parameters:
directory - the directory.
fileName - the file name.
Throws:
IOException

releaseDirectory

public abstract void releaseDirectory(String directoryName)
This is called when the CacheDirectory is finalized.

Parameters:
directoryName - the directory name.

shouldBeQuiet

public abstract boolean shouldBeQuiet(CacheDirectory directory,
                                      String fileName)
Determines if the reader should be quiet or not.

Parameters:
directory - the directory.
fileName - the file name.
Returns:
boolean.

fileClosedForWriting

public abstract void fileClosedForWriting(CacheDirectory directory,
                                          String fileName,
                                          long fileId)
                                   throws IOException
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.

Parameters:
fileId - the file id.
Throws:
IOException


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