org.compass.needle.terracotta
Class TerracottaDirectory

java.lang.Object
  extended by org.apache.lucene.store.Directory
      extended by org.compass.needle.terracotta.TerracottaDirectory
Direct Known Subclasses:
CSMTerracottaDirectory, ManagedTerracottaDirectory

public class TerracottaDirectory
extends Directory

A Terracota based directory based on Lucene RAM directory improved to support better concurrency.

Basically, the direcotry stores TerracottaFile which are broken into one or more byte arrays. The size of the byte array can be configured but should not be changed once the index created.

Author:
kimchy

Field Summary
static int DEFAULT_BUFFER_SIZE
           
static int DEFAULT_CHM_CONCURRENCY_LEVEL
           
static int DEFAULT_CHM_INITIAL_CAPACITY
           
static float DEFAULT_CHM_LOAD_FACTOR
           
static int DEFAULT_FLUSH_RATE
           
static TerracottaFile EMPTY_FILE
           
 
Fields inherited from class org.apache.lucene.store.Directory
lockFactory
 
Constructor Summary
TerracottaDirectory()
           
TerracottaDirectory(Directory dir)
           
TerracottaDirectory(File dir)
           
TerracottaDirectory(int bufferSize, int flushRate)
           
TerracottaDirectory(int bufferSize, int flushRate, int chmInitialCapacity, float chmLoadFactor, int chmConcurrencyLevel)
          Constructs an empty Directory.
TerracottaDirectory(String dir)
           
 
Method Summary
(package private)  void addFile(String name, TerracottaFile file)
           
 void close()
          Closes the store to future operations, releasing associated memory.
protected  Map<String,TerracottaFile> createMap(int chmInitialCapacity, float chmLoadFactor, int chmConcurrencyLevel)
           
 IndexOutput createOutput(String name)
          Creates a new, empty file in the directory with the given name.
 void deleteFile(String name)
          Removes an existing file in the directory.
 boolean fileExists(String name)
          Returns true iff the named file exists in this directory.
 long fileLength(String name)
          Returns the length in bytes of a file in the directory.
 long fileModified(String name)
          Returns the time the named file was last modified.
(package private)  int getBufferSize()
           
(package private)  int getFlushRate()
           
 LockFactory getLockFactory()
           
 String[] list()
          Returns an array of strings, one for each file in the directory.
 IndexInput openInput(String name)
          Returns a stream reading an existing file.
 void renameFile(String from, String to)
          Deprecated.  
 void setLockFactory(LockFactory lockFactory)
           
 void touchFile(String name)
          Set the modified time of an existing file to now.
 
Methods inherited from class org.apache.lucene.store.Directory
clearLock, copy, ensureOpen, getLockID, makeLock, openInput, sync
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_FILE

public static final transient TerracottaFile EMPTY_FILE

DEFAULT_BUFFER_SIZE

public static final transient int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

DEFAULT_FLUSH_RATE

public static final transient int DEFAULT_FLUSH_RATE
See Also:
Constant Field Values

DEFAULT_CHM_CONCURRENCY_LEVEL

public static final transient int DEFAULT_CHM_CONCURRENCY_LEVEL
See Also:
Constant Field Values

DEFAULT_CHM_LOAD_FACTOR

public static final transient float DEFAULT_CHM_LOAD_FACTOR
See Also:
Constant Field Values

DEFAULT_CHM_INITIAL_CAPACITY

public static final transient int DEFAULT_CHM_INITIAL_CAPACITY
See Also:
Constant Field Values
Constructor Detail

TerracottaDirectory

public TerracottaDirectory()

TerracottaDirectory

public TerracottaDirectory(int bufferSize,
                           int flushRate)

TerracottaDirectory

public TerracottaDirectory(int bufferSize,
                           int flushRate,
                           int chmInitialCapacity,
                           float chmLoadFactor,
                           int chmConcurrencyLevel)
Constructs an empty Directory.


TerracottaDirectory

public TerracottaDirectory(Directory dir)
                    throws IOException
Throws:
IOException

TerracottaDirectory

public TerracottaDirectory(File dir)
                    throws IOException
Throws:
IOException

TerracottaDirectory

public TerracottaDirectory(String dir)
                    throws IOException
Throws:
IOException
Method Detail

createMap

protected Map<String,TerracottaFile> createMap(int chmInitialCapacity,
                                               float chmLoadFactor,
                                               int chmConcurrencyLevel)

setLockFactory

public void setLockFactory(LockFactory lockFactory)
Overrides:
setLockFactory in class Directory

getLockFactory

public LockFactory getLockFactory()
Overrides:
getLockFactory in class Directory

list

public String[] list()
Returns an array of strings, one for each file in the directory.

Specified by:
list in class Directory

fileExists

public boolean fileExists(String name)
Returns true iff the named file exists in this directory.

Specified by:
fileExists in class Directory

fileModified

public long fileModified(String name)
                  throws IOException
Returns the time the named file was last modified.

Specified by:
fileModified in class Directory
Throws:
IOException - if the file does not exist

touchFile

public void touchFile(String name)
               throws IOException
Set the modified time of an existing file to now.

Specified by:
touchFile in class Directory
Throws:
IOException - if the file does not exist

fileLength

public long fileLength(String name)
                throws IOException
Returns the length in bytes of a file in the directory.

Specified by:
fileLength in class Directory
Throws:
IOException - if the file does not exist

deleteFile

public void deleteFile(String name)
                throws IOException
Removes an existing file in the directory.

Specified by:
deleteFile in class Directory
Throws:
IOException - if the file does not exist

renameFile

public void renameFile(String from,
                       String to)
                throws IOException
Deprecated. 

Renames an existing file in the directory.

Specified by:
renameFile in class Directory
Throws:
FileNotFoundException - if from does not exist
IOException

createOutput

public IndexOutput createOutput(String name)
                         throws IOException
Creates a new, empty file in the directory with the given name. Returns a stream writing this file.

Specified by:
createOutput in class Directory
Throws:
IOException

openInput

public IndexInput openInput(String name)
                     throws IOException
Returns a stream reading an existing file.

Specified by:
openInput in class Directory
Throws:
IOException

addFile

void addFile(String name,
             TerracottaFile file)
       throws IOException
Throws:
IOException

getBufferSize

int getBufferSize()

getFlushRate

int getFlushRate()

close

public void close()
Closes the store to future operations, releasing associated memory.

Specified by:
close in class Directory


Copyright (c) 2004-2009 The Compass Project.