Better handling of core being closed

This commit is contained in:
Eugene Livis 2017-03-27 16:40:21 -04:00
parent 378aff4ea0
commit d2a4c9b2a9
5 changed files with 21 additions and 22 deletions

View File

@ -189,7 +189,7 @@ class DropdownToolbar extends javax.swing.JPanel {
disableSearch = true; disableSearch = true;
} }
} }
} catch (KeywordSearchModuleException ex) { } catch (NoOpenCoreException ex) {
/* /*
* Error, disable the ad hoc search UI components. * Error, disable the ad hoc search UI components.
*/ */

View File

@ -227,7 +227,7 @@ class Ingester {
solrServer.addDocument(updateDoc); solrServer.addDocument(updateDoc);
uncommitedIngests = true; uncommitedIngests = true;
} catch (KeywordSearchModuleException ex) { } catch (KeywordSearchModuleException | NoOpenCoreException ex) {
//JMTODO: does this need to be internationalized? //JMTODO: does this need to be internationalized?
throw new IngesterException( throw new IngesterException(
NbBundle.getMessage(Ingester.class, "Ingester.ingest.exception.err.msg", sourceName), ex); NbBundle.getMessage(Ingester.class, "Ingester.ingest.exception.err.msg", sourceName), ex);

View File

@ -166,7 +166,7 @@ public final class KeywordSearchIngestModule implements FileIngestModule {
if (!IndexFinder.getCurrentSchemaVersion().equals(indexInfo.getSchemaVersion())) { if (!IndexFinder.getCurrentSchemaVersion().equals(indexInfo.getSchemaVersion())) {
throw new IngestModuleException(Bundle.KeywordSearchIngestModule_startupException_indexSchemaNotSupported(indexInfo.getSchemaVersion())); throw new IngestModuleException(Bundle.KeywordSearchIngestModule_startupException_indexSchemaNotSupported(indexInfo.getSchemaVersion()));
} }
} catch (KeywordSearchModuleException ex) { } catch (NoOpenCoreException ex) {
throw new IngestModuleException(Bundle.KeywordSearchIngestModule_startupMessage_failedToGetIndexSchema(), ex); throw new IngestModuleException(Bundle.KeywordSearchIngestModule_startupMessage_failedToGetIndexSchema(), ex);
} }

View File

@ -36,11 +36,9 @@ import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -62,11 +60,9 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.openide.modules.InstalledFileLocator; import org.openide.modules.InstalledFileLocator;
import org.openide.modules.Places; import org.openide.modules.Places;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.Case.CaseType; import org.sleuthkit.autopsy.casemodule.Case.CaseType;
import org.sleuthkit.autopsy.casemodule.CaseMetadata;
import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.core.UserPreferences;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings;
@ -569,7 +565,7 @@ public class Server {
try { try {
// Close any open core before stopping server // Close any open core before stopping server
closeCore(); closeCore();
} catch (KeywordSearchModuleException e) { } catch (KeywordSearchModuleException | NoOpenCoreException e) {
logger.log(Level.WARNING, "Failed to close core: ", e); //NON-NLS logger.log(Level.WARNING, "Failed to close core: ", e); //NON-NLS
} }
@ -696,35 +692,38 @@ public class Server {
} }
} }
Index getIndexInfo() throws KeywordSearchModuleException { Index getIndexInfo() throws NoOpenCoreException {
currentCoreLock.readLock().lock(); currentCoreLock.readLock().lock();
try { try {
if (null != currentCore) { if (null == currentCore) {
return currentCore.getIndexInfo(); throw new NoOpenCoreException();
} else {
throw new KeywordSearchModuleException("Cannot get text index info, no core is open");
} }
return currentCore.getIndexInfo();
} finally { } finally {
currentCoreLock.readLock().unlock(); currentCoreLock.readLock().unlock();
} }
} }
void closeCore() throws KeywordSearchModuleException { void closeCore() throws KeywordSearchModuleException, NoOpenCoreException {
currentCoreLock.writeLock().lock(); currentCoreLock.writeLock().lock();
try { try {
if (null != currentCore) { if (null == currentCore) {
throw new NoOpenCoreException();
}
currentCore.close(); currentCore.close();
currentCore = null; currentCore = null;
serverAction.putValue(CORE_EVT, CORE_EVT_STATES.STOPPED); serverAction.putValue(CORE_EVT, CORE_EVT_STATES.STOPPED);
}
} finally { } finally {
currentCoreLock.writeLock().unlock(); currentCoreLock.writeLock().unlock();
} }
} }
void addDocument(SolrInputDocument doc) throws KeywordSearchModuleException { void addDocument(SolrInputDocument doc) throws KeywordSearchModuleException, NoOpenCoreException {
currentCoreLock.readLock().lock(); currentCoreLock.readLock().lock();
try { try {
if (null == currentCore) {
throw new NoOpenCoreException();
}
currentCore.addDocument(doc); currentCore.addDocument(doc);
} finally { } finally {
currentCoreLock.readLock().unlock(); currentCoreLock.readLock().unlock();
@ -761,7 +760,7 @@ public class Server {
closeCore(); closeCore();
} }
} }
} catch (KeywordSearchModuleException ex) { } catch (KeywordSearchModuleException | NoOpenCoreException ex) {
throw new KeywordSearchServiceException(NbBundle.getMessage(Server.class, "Server.close.exception.msg"), ex); throw new KeywordSearchServiceException(NbBundle.getMessage(Server.class, "Server.close.exception.msg"), ex);
} finally { } finally {
currentCoreLock.readLock().unlock(); currentCoreLock.readLock().unlock();

View File

@ -375,7 +375,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
try { try {
KeywordSearch.getServer().closeCore(); KeywordSearch.getServer().closeCore();
} catch (KeywordSearchModuleException ex) { } catch (KeywordSearchModuleException | NoOpenCoreException ex) {
throw new AutopsyServiceException(String.format("Failed to close core for %s", context.getCase().getCaseDirectory()), ex); throw new AutopsyServiceException(String.format("Failed to close core for %s", context.getCase().getCaseDirectory()), ex);
} }
} }