com.atlassian.bonnie
Class ConcurrentLuceneConnection

java.lang.Object
  extended bycom.atlassian.bonnie.ConcurrentLuceneConnection
All Implemented Interfaces:
ILuceneConnection

public class ConcurrentLuceneConnection
extends java.lang.Object
implements ILuceneConnection

ILuceneConnection implementation that allows concurrent searching/reading and writing/deleting. Concurrent writes and deletes block each other.

This class optimizes use of Lucene reader instances by holding a common IndexReader that is shared by idempotent operations on an unmodified index. Any mutative operations cause the current IndexReader to be cleared, and subsequent reads will see the results of the previous index change.

TODO We might need to keep track of currently open readers and block recreateIndexDirectory() until they are all closed. We would also need to prevent any new Readers being created during this time. The reason for this is that Windoze can whinge about open file crap and refuse to delete files rather than listen to its l33t haxor ruler.


Nested Class Summary
 
Nested classes inherited from class com.atlassian.bonnie.ILuceneConnection
ILuceneConnection.BatchUpdateAction, ILuceneConnection.Configuration, ILuceneConnection.ReaderAction, ILuceneConnection.SearcherAction, ILuceneConnection.WriterAction
 
Field Summary
 
Fields inherited from interface com.atlassian.bonnie.ILuceneConnection
DEFAULT_CONFIGURATION
 
Constructor Summary
ConcurrentLuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration)
           
ConcurrentLuceneConnection(java.io.File path, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration)
           
 
Method Summary
 void close()
          Closes the reader and the writer.
 void flipCurrentSearcher()
          Closes the searcher that is currently in use.
 int getNumDocs()
          Returns the number of documents in the index.
 boolean isIndexCreated()
          Returns true if the index has been created.
 org.apache.lucene.search.IndexSearcher leakSearcher()
          Get the current Searcher from the ILuceneConnection.
 void optimize()
          Blocks and waits until all write operations to the index complete.
 void recreateIndexDirectory()
          Blocks and waits until all write operations to the index complete.
 void withBatchUpdate(ILuceneConnection.BatchUpdateAction action)
          Blocks and waits until all write operations to the index complete.
 void withDeleteAndWrites(ILuceneConnection.ReaderAction readerAction, ILuceneConnection.WriterAction writerAction)
          Perform an Atomic delete and add.
 java.lang.Object withReader(ILuceneConnection.ReaderAction action)
          Idempotent operation.
 void withReaderAndDeletes(ILuceneConnection.ReaderAction action)
          Blocks and waits until all write operations to the index complete.
 void withSearch(ILuceneConnection.SearcherAction action)
          This implementation does not respect the boolean return of the of the SearcherAction#perform(org.apache.lucene.search.IndexSearcher) method
 void withWriter(ILuceneConnection.WriterAction action)
          Blocks and waits until all write operations to the index complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcurrentLuceneConnection

public ConcurrentLuceneConnection(org.apache.lucene.store.Directory directory,
                                  org.apache.lucene.analysis.Analyzer analyzer,
                                  ILuceneConnection.Configuration configuration)

ConcurrentLuceneConnection

public ConcurrentLuceneConnection(java.io.File path,
                                  org.apache.lucene.analysis.Analyzer analyzer,
                                  ILuceneConnection.Configuration configuration)
Method Detail

getNumDocs

public int getNumDocs()
Description copied from interface: ILuceneConnection
Returns the number of documents in the index.

Specified by:
getNumDocs in interface ILuceneConnection

isIndexCreated

public boolean isIndexCreated()
Description copied from interface: ILuceneConnection
Returns true if the index has been created. This means that the index directory itself exists AND has been initialised with the default required index files.

Specified by:
isIndexCreated in interface ILuceneConnection
Returns:
true if the index exists, false otherwise.

leakSearcher

public org.apache.lucene.search.IndexSearcher leakSearcher()
Description copied from interface: ILuceneConnection
Get the current Searcher from the ILuceneConnection.

Do not forget to call the Searcher's close() method once the searcher is no longer neeeded.

Specified by:
leakSearcher in interface ILuceneConnection

optimize

public void optimize()
              throws LuceneException
Blocks and waits until all write operations to the index complete. Optimizes the index while holding the write lock to ensure no concurrent modifications. Optimize is done using interactive mode configuration.

Specified by:
optimize in interface ILuceneConnection
Throws:
LuceneException

recreateIndexDirectory

public void recreateIndexDirectory()
Blocks and waits until all write operations to the index complete. Recreates the index while holding the write lock to ensure no concurrent modifications.

Specified by:
recreateIndexDirectory in interface ILuceneConnection

close

public void close()
Description copied from interface: ILuceneConnection
Closes the reader and the writer.

Specified by:
close in interface ILuceneConnection

withSearch

public void withSearch(ILuceneConnection.SearcherAction action)
                throws LuceneException
This implementation does not respect the boolean return of the of the SearcherAction#perform(org.apache.lucene.search.IndexSearcher) method

Specified by:
withSearch in interface ILuceneConnection
Throws:
LuceneException

withReader

public java.lang.Object withReader(ILuceneConnection.ReaderAction action)
                            throws LuceneException
Description copied from interface: ILuceneConnection
Idempotent operation. Just for querying, do not delete documents with this action use #withReaderAndDeletes(ReaderAction) to perform index deletes.

Specified by:
withReader in interface ILuceneConnection
Throws:
LuceneException

withReaderAndDeletes

public void withReaderAndDeletes(ILuceneConnection.ReaderAction action)
                          throws LuceneException
Blocks and waits until all write operations to the index complete. Executes the ReaderAction while holding the write lock to ensure no concurrent modifications.

Specified by:
withReaderAndDeletes in interface ILuceneConnection
Throws:
LuceneException

withWriter

public void withWriter(ILuceneConnection.WriterAction action)
                throws LuceneException
Blocks and waits until all write operations to the index complete. Executes the WriterAction while holding the write lock to ensure no concurrent modifications.

Specified by:
withWriter in interface ILuceneConnection
Throws:
LuceneException

withDeleteAndWrites

public void withDeleteAndWrites(ILuceneConnection.ReaderAction readerAction,
                                ILuceneConnection.WriterAction writerAction)
                         throws LuceneException
Description copied from interface: ILuceneConnection
Perform an Atomic delete and add. Shouldn't perform too many writes, for multiple writes use ILuceneConnection.withBatchUpdate(com.atlassian.bonnie.ILuceneConnection.BatchUpdateAction) as it will use the batch mode configuration, speeding up the writes.

Specified by:
withDeleteAndWrites in interface ILuceneConnection
Throws:
LuceneException

withBatchUpdate

public void withBatchUpdate(ILuceneConnection.BatchUpdateAction action)
Blocks and waits until all write operations to the index complete. Executes the BatchUpdateAction while holding the write lock to ensure no concurrent modifications.

Note: This method holds the writeLock for the whole operation, so is used to ensure a set of deletes and writes are effectively executed atomically.

Specified by:
withBatchUpdate in interface ILuceneConnection

flipCurrentSearcher

public void flipCurrentSearcher()
Closes the searcher that is currently in use.



Copyright © 2006-2009 Atlassian Software Systems Pty Ltd. All Rights Reserved.