4288 Make executor in ImageGalleryController final

This commit is contained in:
Richard Cordovano 2018-12-03 14:29:05 -05:00
parent 21a279063b
commit e81ebfac76

View File

@ -114,7 +114,7 @@ public final class ImageGalleryController {
private final CategoryManager categoryManager; private final CategoryManager categoryManager;
private final DrawableTagsManager tagsManager; private final DrawableTagsManager tagsManager;
private ListeningExecutorService dbExecutor; private final ListeningExecutorService dbExecutor;
private final Case autopsyCase; private final Case autopsyCase;
private final SleuthkitCase sleuthKitCase; private final SleuthkitCase sleuthKitCase;
@ -165,7 +165,7 @@ public final class ImageGalleryController {
} }
/** /**
* *
* @param b True if any data source in the case is stale * @param b True if any data source in the case is stale
*/ */
@ThreadConfined(type = ThreadConfined.ThreadType.ANY) @ThreadConfined(type = ThreadConfined.ThreadType.ANY)
@ -180,7 +180,7 @@ public final class ImageGalleryController {
} }
/** /**
* *
* @return true if any data source in the case is stale * @return true if any data source in the case is stale
*/ */
@ThreadConfined(type = ThreadConfined.ThreadType.JFX) @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
@ -188,7 +188,7 @@ public final class ImageGalleryController {
return isCaseStale.get(); return isCaseStale.get();
} }
ImageGalleryController(@Nonnull Case newCase) throws TskCoreException { ImageGalleryController(@Nonnull Case newCase) throws TskCoreException {
this.autopsyCase = Objects.requireNonNull(newCase); this.autopsyCase = Objects.requireNonNull(newCase);
this.sleuthKitCase = newCase.getSleuthkitCase(); this.sleuthKitCase = newCase.getSleuthkitCase();
@ -347,8 +347,8 @@ public final class ImageGalleryController {
* Returns a set of data source object ids that are stale. * Returns a set of data source object ids that are stale.
* *
* This includes any data sources already in the table, that are not in * This includes any data sources already in the table, that are not in
* COMPLETE or IN_PROGRESS status, or any data sources that might have been added to the * COMPLETE or IN_PROGRESS status, or any data sources that might have been
* case, but are not in the datasources table. * added to the case, but are not in the datasources table.
* *
* @return list of data source object ids that are stale. * @return list of data source object ids that are stale.
*/ */
@ -485,7 +485,7 @@ public final class ImageGalleryController {
return sleuthKitCase.countFilesWhere(whereClause) > 0; return sleuthKitCase.countFilesWhere(whereClause) > 0;
} }
public boolean hasFilesWithMimeType(long dataSourceId) throws TskCoreException { public boolean hasFilesWithMimeType(long dataSourceId) throws TskCoreException {
String whereClause = "data_source_obj_id = " + dataSourceId String whereClause = "data_source_obj_id = " + dataSourceId
@ -496,14 +496,11 @@ public final class ImageGalleryController {
} }
synchronized private void shutDownDBExecutor() { synchronized private void shutDownDBExecutor() {
if (dbExecutor != null) { dbExecutor.shutdownNow();
dbExecutor.shutdownNow(); try {
try { dbExecutor.awaitTermination(30, TimeUnit.SECONDS);
dbExecutor.awaitTermination(30, TimeUnit.SECONDS); } catch (InterruptedException ex) {
} catch (InterruptedException ex) { logger.log(Level.WARNING, "Image Gallery failed to shutdown DB Task Executor in a timely fashion.", ex);
logger.log(Level.WARNING, "Image Gallery failed to shutdown DB Task Executor in a timely fashion.", ex);
}
dbExecutor = null;
} }
} }
@ -518,12 +515,10 @@ public final class ImageGalleryController {
* @param bgTask * @param bgTask
*/ */
public synchronized void queueDBTask(BackgroundTask bgTask) { public synchronized void queueDBTask(BackgroundTask bgTask) {
if (dbExecutor == null || dbExecutor.isShutdown()) { if (!dbExecutor.isShutdown()) {
dbExecutor = getNewDBExecutor(); incrementQueueSize();
dbExecutor.submit(bgTask).addListener(this::decrementQueueSize, MoreExecutors.directExecutor());
} }
incrementQueueSize();
dbExecutor.submit(bgTask).addListener(this::decrementQueueSize, MoreExecutors.directExecutor());
} }
private void incrementQueueSize() { private void incrementQueueSize() {
@ -629,7 +624,6 @@ public final class ImageGalleryController {
} }
} }
/** /**
* task that updates one file in database with results from ingest * task that updates one file in database with results from ingest
*/ */
@ -645,7 +639,7 @@ public final class ImageGalleryController {
public AbstractFile getFile() { public AbstractFile getFile() {
return file; return file;
} }
UpdateFileTask(AbstractFile f, DrawableDB taskDB) { UpdateFileTask(AbstractFile f, DrawableDB taskDB) {
super(); super();
this.file = f; this.file = f;
@ -666,7 +660,6 @@ public final class ImageGalleryController {
} }
} }
/** /**
* Base abstract class for various methods of copying image files data, for * Base abstract class for various methods of copying image files data, for
* a given data source, into the Image gallery DB. * a given data source, into the Image gallery DB.
@ -675,6 +668,7 @@ public final class ImageGalleryController {
"BulkTask.stopCopy.status=Stopping copy to drawable db task.", "BulkTask.stopCopy.status=Stopping copy to drawable db task.",
"BulkTask.errPopulating.errMsg=There was an error populating Image Gallery database."}) "BulkTask.errPopulating.errMsg=There was an error populating Image Gallery database."})
abstract static class BulkTransferTask extends BackgroundTask { abstract static class BulkTransferTask extends BackgroundTask {
static private final String MIMETYPE_CLAUSE static private final String MIMETYPE_CLAUSE
= "(mime_type LIKE '" //NON-NLS = "(mime_type LIKE '" //NON-NLS
+ String.join("' OR mime_type LIKE '", FileTypeUtils.getAllSupportedMimeTypes()) //NON-NLS + String.join("' OR mime_type LIKE '", FileTypeUtils.getAllSupportedMimeTypes()) //NON-NLS
@ -737,11 +731,11 @@ public final class ImageGalleryController {
CaseDbTransaction caseDbTransaction = null; CaseDbTransaction caseDbTransaction = null;
boolean hasFilesWithNoMime = true; boolean hasFilesWithNoMime = true;
boolean endedEarly = false; boolean endedEarly = false;
try { try {
// See if there are any files in the DS w/out a MIME TYPE // See if there are any files in the DS w/out a MIME TYPE
hasFilesWithNoMime = controller.hasFilesWithNoMimeType(dataSourceObjId); hasFilesWithNoMime = controller.hasFilesWithNoMimeType(dataSourceObjId);
//grab all files with detected mime types //grab all files with detected mime types
final List<AbstractFile> files = getFiles(); final List<AbstractFile> files = getFiles();
progressHandle.switchToDeterminate(files.size()); progressHandle.switchToDeterminate(files.size());
@ -751,7 +745,6 @@ public final class ImageGalleryController {
updateProgress(0.0); updateProgress(0.0);
int workDone = 0; int workDone = 0;
// Cycle through all of the files returned and call processFile on each // Cycle through all of the files returned and call processFile on each
//do in transaction //do in transaction
drawableDbTransaction = taskDB.beginTransaction(); drawableDbTransaction = taskDB.beginTransaction();
@ -771,7 +764,6 @@ public final class ImageGalleryController {
logger.log(Level.WARNING, "Task cancelled or interrupted: not all contents may be transfered to drawable database."); //NON-NLS logger.log(Level.WARNING, "Task cancelled or interrupted: not all contents may be transfered to drawable database."); //NON-NLS
endedEarly = true; endedEarly = true;
progressHandle.finish(); progressHandle.finish();
break; break;
} }