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