use of gate.creole.annic.lucene.LuceneIndexer in project gate-core by GateNLP.
the class LuceneDataStoreImpl method open.
// close()
/**
* Open a connection to the data store.
*/
@Override
public void open() throws PersistenceException {
super.open();
/*
* check if the storage directory is a valid serial datastore if we
* want to support old style: String versionInVersionFile = "1.0";
* (but this means it will open *any* directory)
*/
BufferedReader isr = null;
try {
isr = new BufferedReader(new FileReader(getVersionFile()));
currentProtocolVersion = isr.readLine();
String indexDirRelativePath = isr.readLine();
if (indexDirRelativePath != null && indexDirRelativePath.trim().length() > 1) {
URL storageDirURL = storageDir.toURI().toURL();
URL theIndexURL = new URL(storageDirURL, indexDirRelativePath);
// check if index directory exists
File indexDir = Files.fileFromURL(theIndexURL);
if (!indexDir.exists()) {
throw new PersistenceException("Index directory " + indexDirRelativePath + " could not be found for datastore at " + storageDirURL);
}
indexURL = theIndexURL;
this.indexer = new LuceneIndexer(indexURL);
this.searcher = new LuceneSearcher();
((LuceneSearcher) this.searcher).setLuceneDatastore(this);
}
} catch (IOException e) {
throw new PersistenceException("Invalid storage directory: " + e);
} finally {
IOUtils.closeQuietly(isr);
}
if (!isValidProtocolVersion(currentProtocolVersion))
throw new PersistenceException("Invalid protocol version number: " + currentProtocolVersion);
// Lets create a separate indexer thread which keeps running in the
// background
executor = new ScheduledThreadPoolExecutor(1, Executors.defaultThreadFactory());
// set up the executor so it does not execute delayed indexing tasks
// that are still waiting when it is shut down. We run these tasks
// immediately at shutdown time rather than waiting.
executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
// start listening to Creole events
Gate.getCreoleRegister().addCreoleListener(this);
}
Aggregations