org.apache.maven.index.context
Class DefaultIndexingContext

java.lang.Object
  extended by org.apache.maven.index.context.AbstractIndexingContext
      extended by org.apache.maven.index.context.DefaultIndexingContext
All Implemented Interfaces:
IndexingContext

public class DefaultIndexingContext
extends AbstractIndexingContext

The default IndexingContext implementation.

Author:
Jason van Zyl, Tamas Cservenak

Field Summary
static boolean BLOCKING_COMMIT
          A flag useful for tests, to make this IndexingContext implementation blocking.
static String FLD_DESCRIPTOR
           
 
Fields inherited from interface org.apache.maven.index.context.IndexingContext
INDEX_CHAIN_ID, INDEX_CHUNK_COUNTER, INDEX_CHUNK_PREFIX, INDEX_FILE_PREFIX, INDEX_ID, INDEX_LEGACY_TIMESTAMP, INDEX_PACKER_PROPERTIES_FILE, INDEX_PROPERTY_PREFIX, INDEX_REMOTE_PROPERTIES_FILE, INDEX_TIME_DAY_FORMAT, INDEX_TIME_FORMAT, INDEX_TIMESTAMP, INDEX_UPDATER_PROPERTIES_FILE
 
Constructor Summary
DefaultIndexingContext(String id, String repositoryId, File repository, org.apache.lucene.store.Directory indexDirectory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexCreators, boolean reclaimIndex)
           
DefaultIndexingContext(String id, String repositoryId, File repository, File indexDirectoryFile, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexCreators, boolean reclaimIndex)
           
 
Method Summary
 void close(boolean deleteFiles)
          Shuts down this context.
 void commit()
          Commits changes to context, eventually refreshing readers/searchers too.
protected  org.apache.lucene.document.Document createGroupsDocument(Collection<String> groups, String field, String fieldValue, String listField)
           
protected  void doCommit(boolean blocking)
           
protected  void flagNeedsReopen()
           
 Set<String> getAllGroups()
          Gets all group names stored in the current indexing context
 org.apache.lucene.analysis.Analyzer getAnalyzer()
          Returns the Lucene Analyzer of this context used for by IndexWriter and IndexSearcher.
 GavCalculator getGavCalculator()
          Returns the GavCalculator for this Context.
protected  Set<String> getGroups(String field, String filedValue, String listField)
           
 String getId()
          Returns this indexing context id.
 List<IndexCreator> getIndexCreators()
          List of IndexCreators used in this context.
 org.apache.lucene.store.Directory getIndexDirectory()
           
 File getIndexDirectoryFile()
           
 org.apache.lucene.index.IndexReader getIndexReader()
          Returns the Lucene IndexReader of this context.
 org.apache.lucene.search.IndexSearcher getIndexSearcher()
          Returns the Lucene IndexSearcher of this context.
 String getIndexUpdateUrl()
          Returns url for the index update
 org.apache.lucene.index.IndexWriter getIndexWriter()
          Returns the Lucene IndexWriter of this context.
 File getRepository()
          Returns location for the local repository.
 String getRepositoryId()
          Returns repository id.
 String getRepositoryUrl()
          Returns public repository url.
 Set<String> getRootGroups()
          Gets root group names stored in the current indexing context
 int getSize()
          Returns a number that represents the "size" useful for doing comparisons between contexts (which one has more data indexed?).
 Date getTimestamp()
          Returns index update time
protected  void installBottleWarmer()
           
protected  boolean isReopenNeeded()
           
 boolean isSearchable()
          Is the context searchable when doing "non-targeted" searches?
 void lock()
          Performs a shared locking on this context, guaranteeing that no IndexReader/Searcher/Writer close will occur.
 void lockExclusively()
           
 void merge(org.apache.lucene.store.Directory directory)
          Merges content of given Lucene directory with this context.
 void merge(org.apache.lucene.store.Directory directory, DocumentFilter filter)
          Merges content of given Lucene directory with this context, but filters out the unwanted ones.
protected  void openAndWarmup()
           
protected  void openAndWarmupReaders()
           
 void optimize()
          Optimizes index
 void purge()
          Purge (cleans) the context, deletes/empties the index and restores the context to new/empty state.
 void rebuildGroups()
          Rebuilds stored group names from the index
 void replace(org.apache.lucene.store.Directory directory)
          Replaces the Lucene index with the one from supplied directory.
 void rollback()
          Rolls back changes to context, eventually refreshing readers/searchers too.
 void setAllGroups(Collection<String> groups)
          Sets all group names stored in the current indexing context
protected  void setGroups(Collection<String> groups, String groupField, String groupFieldValue, String groupListField)
           
 void setRootGroups(Collection<String> groups)
          Sets root group names stored in the current indexing context
 void setSearchable(boolean searchable)
          Sets is the context searchable when doing "non-targeted" searches.
 String toString()
           
protected  void unflagNeedsReopen()
           
 void unlock()
          Releases the shared lock on this context.
 void unlockExclusively()
           
 void updateTimestamp()
           
 void updateTimestamp(boolean save)
           
 void updateTimestamp(boolean save, Date timestamp)
           
protected  void warmUp(NexusIndexSearcher searcher)
           
 
Methods inherited from class org.apache.maven.index.context.AbstractIndexingContext
isReceivingUpdates
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FLD_DESCRIPTOR

public static final String FLD_DESCRIPTOR
See Also:
Constant Field Values

BLOCKING_COMMIT

public static boolean BLOCKING_COMMIT
A flag useful for tests, to make this IndexingContext implementation blocking. If this flag is true, context will block the commit() calls and will return from it when Lucene commit done AND all the readers are reopened and are current. TODO: this is currently inherently unsafe (is not final), and is meant to be used in Unit tests only! Think something and tie this knot properly.

Constructor Detail

DefaultIndexingContext

public DefaultIndexingContext(String id,
                              String repositoryId,
                              File repository,
                              File indexDirectoryFile,
                              String repositoryUrl,
                              String indexUpdateUrl,
                              List<? extends IndexCreator> indexCreators,
                              boolean reclaimIndex)
                       throws IOException,
                              UnsupportedExistingLuceneIndexException
Throws:
IOException
UnsupportedExistingLuceneIndexException

DefaultIndexingContext

public DefaultIndexingContext(String id,
                              String repositoryId,
                              File repository,
                              org.apache.lucene.store.Directory indexDirectory,
                              String repositoryUrl,
                              String indexUpdateUrl,
                              List<? extends IndexCreator> indexCreators,
                              boolean reclaimIndex)
                       throws IOException,
                              UnsupportedExistingLuceneIndexException
Throws:
IOException
UnsupportedExistingLuceneIndexException
Method Detail

lock

public void lock()
Description copied from interface: IndexingContext
Performs a shared locking on this context, guaranteeing that no IndexReader/Searcher/Writer close will occur. But the cost of it is potentially blocking other threads, so stay in critical region locking this context as less as possible.


unlock

public void unlock()
Description copied from interface: IndexingContext
Releases the shared lock on this context.


lockExclusively

public void lockExclusively()

unlockExclusively

public void unlockExclusively()

getIndexDirectory

public org.apache.lucene.store.Directory getIndexDirectory()

getIndexDirectoryFile

public File getIndexDirectoryFile()

isSearchable

public boolean isSearchable()
Description copied from interface: IndexingContext
Is the context searchable when doing "non-targeted" searches? Ie. Should it take a part when searching without specifying context?

Returns:

setSearchable

public void setSearchable(boolean searchable)
Description copied from interface: IndexingContext
Sets is the context searchable when doing "non-targeted" searches.


getId

public String getId()
Description copied from interface: IndexingContext
Returns this indexing context id.


updateTimestamp

public void updateTimestamp()
                     throws IOException
Throws:
IOException

updateTimestamp

public void updateTimestamp(boolean save)
                     throws IOException
Throws:
IOException

updateTimestamp

public void updateTimestamp(boolean save,
                            Date timestamp)
                     throws IOException
Throws:
IOException

getTimestamp

public Date getTimestamp()
Description copied from interface: IndexingContext
Returns index update time


getSize

public int getSize()
            throws IOException
Description copied from interface: IndexingContext
Returns a number that represents the "size" useful for doing comparisons between contexts (which one has more data indexed?). The number return does not represent the count of ArtifactInfos, neither other "meaningful" info, it is purely to be used for inter-context comparisons only!

Returns:
Throws:
IOException

getRepositoryId

public String getRepositoryId()
Description copied from interface: IndexingContext
Returns repository id.


getRepository

public File getRepository()
Description copied from interface: IndexingContext
Returns location for the local repository.


getRepositoryUrl

public String getRepositoryUrl()
Description copied from interface: IndexingContext
Returns public repository url.


getIndexUpdateUrl

public String getIndexUpdateUrl()
Description copied from interface: IndexingContext
Returns url for the index update


getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer()
Description copied from interface: IndexingContext
Returns the Lucene Analyzer of this context used for by IndexWriter and IndexSearcher. Note: this method always creates a new instance of analyzer!

Returns:

openAndWarmup

protected void openAndWarmup()
                      throws IOException
Throws:
IOException

openAndWarmupReaders

protected void openAndWarmupReaders()
                             throws IOException
Throws:
IOException

warmUp

protected void warmUp(NexusIndexSearcher searcher)
               throws IOException
Throws:
IOException

getIndexWriter

public org.apache.lucene.index.IndexWriter getIndexWriter()
                                                   throws IOException
Description copied from interface: IndexingContext
Returns the Lucene IndexWriter of this context.

Returns:
indexWriter
Throws:
IOException

getIndexReader

public org.apache.lucene.index.IndexReader getIndexReader()
                                                   throws IOException
Description copied from interface: IndexingContext
Returns the Lucene IndexReader of this context.

Returns:
reader
Throws:
IOException

getIndexSearcher

public org.apache.lucene.search.IndexSearcher getIndexSearcher()
                                                        throws IOException
Description copied from interface: IndexingContext
Returns the Lucene IndexSearcher of this context.

Returns:
searcher
Throws:
IOException

commit

public void commit()
            throws IOException
Description copied from interface: IndexingContext
Commits changes to context, eventually refreshing readers/searchers too.

Throws:
IOException

doCommit

protected void doCommit(boolean blocking)
                 throws IOException
Throws:
IOException

rollback

public void rollback()
              throws IOException
Description copied from interface: IndexingContext
Rolls back changes to context, eventually refreshing readers/searchers too.

Throws:
IOException

optimize

public void optimize()
              throws org.apache.lucene.index.CorruptIndexException,
                     IOException
Description copied from interface: IndexingContext
Optimizes index

Throws:
org.apache.lucene.index.CorruptIndexException
IOException

close

public void close(boolean deleteFiles)
           throws IOException
Description copied from interface: IndexingContext
Shuts down this context.

Throws:
IOException

purge

public void purge()
           throws IOException
Description copied from interface: IndexingContext
Purge (cleans) the context, deletes/empties the index and restores the context to new/empty state.

Throws:
IOException

replace

public void replace(org.apache.lucene.store.Directory directory)
             throws IOException
Description copied from interface: IndexingContext
Replaces the Lucene index with the one from supplied directory.

Throws:
IOException

merge

public void merge(org.apache.lucene.store.Directory directory)
           throws IOException
Description copied from interface: IndexingContext
Merges content of given Lucene directory with this context.

Parameters:
directory - - the directory to merge
Throws:
IOException

merge

public void merge(org.apache.lucene.store.Directory directory,
                  DocumentFilter filter)
           throws IOException
Description copied from interface: IndexingContext
Merges content of given Lucene directory with this context, but filters out the unwanted ones.

Parameters:
directory - - the directory to merge
Throws:
IOException

getGavCalculator

public GavCalculator getGavCalculator()
Description copied from interface: IndexingContext
Returns the GavCalculator for this Context. Implies repository layout.


getIndexCreators

public List<IndexCreator> getIndexCreators()
Description copied from interface: IndexingContext
List of IndexCreators used in this context.

Returns:
list of index creators.

rebuildGroups

public void rebuildGroups()
                   throws IOException
Description copied from interface: IndexingContext
Rebuilds stored group names from the index

Throws:
IOException

getAllGroups

public Set<String> getAllGroups()
                         throws IOException
Description copied from interface: IndexingContext
Gets all group names stored in the current indexing context

Throws:
IOException

setAllGroups

public void setAllGroups(Collection<String> groups)
                  throws IOException
Description copied from interface: IndexingContext
Sets all group names stored in the current indexing context

Throws:
IOException

getRootGroups

public Set<String> getRootGroups()
                          throws IOException
Description copied from interface: IndexingContext
Gets root group names stored in the current indexing context

Throws:
IOException

setRootGroups

public void setRootGroups(Collection<String> groups)
                   throws IOException
Description copied from interface: IndexingContext
Sets root group names stored in the current indexing context

Throws:
IOException

getGroups

protected Set<String> getGroups(String field,
                                String filedValue,
                                String listField)
                         throws IOException,
                                org.apache.lucene.index.CorruptIndexException
Throws:
IOException
org.apache.lucene.index.CorruptIndexException

setGroups

protected void setGroups(Collection<String> groups,
                         String groupField,
                         String groupFieldValue,
                         String groupListField)
                  throws IOException,
                         org.apache.lucene.index.CorruptIndexException
Throws:
IOException
org.apache.lucene.index.CorruptIndexException

createGroupsDocument

protected org.apache.lucene.document.Document createGroupsDocument(Collection<String> groups,
                                                                   String field,
                                                                   String fieldValue,
                                                                   String listField)

toString

public String toString()
Overrides:
toString in class Object

flagNeedsReopen

protected void flagNeedsReopen()

unflagNeedsReopen

protected void unflagNeedsReopen()

isReopenNeeded

protected boolean isReopenNeeded()

installBottleWarmer

protected void installBottleWarmer()


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