limit the scope of mutext when getting IngestManager singleton instance

This commit is contained in:
adam-m 2013-03-28 12:38:27 -04:00
parent ab39110253
commit 8e2bcdfae0

View File

@ -113,10 +113,9 @@ public class IngestManager {
* *
*/ */
DATA, DATA,
/** /**
* Event send when content changed, either its attributes changed, or new content * Event send when content changed, either its attributes changed, or
* children have been added * new content children have been added
*/ */
CONTENT_CHANGED CONTENT_CHANGED
}; };
@ -173,11 +172,15 @@ public class IngestManager {
* *
* @returns Instance of class. * @returns Instance of class.
*/ */
public static synchronized IngestManager getDefault() { public static IngestManager getDefault() {
if (instance == null) {
synchronized (IngestManager.class) {
if (instance == null) { if (instance == null) {
logger.log(Level.INFO, "creating manager instance"); logger.log(Level.INFO, "creating manager instance");
instance = new IngestManager(); instance = new IngestManager();
} }
}
}
return instance; return instance;
} }
@ -261,14 +264,14 @@ public class IngestManager {
} }
/** /**
* Schedule a file for ingest. * Schedule a file for ingest. Scheduler updates the current progress.
* Scheduler updates the current progress.
* *
* The file is usually a product of a recently ran ingest. * The file is usually a product of a recently ran ingest. Now we want to
* Now we want to process this file with the same ingest context. * process this file with the same ingest context.
* *
* @param file file to be scheduled * @param file file to be scheduled
* @param pipelineContext ingest context used to ingest parent of the file to be scheduled * @param pipelineContext ingest context used to ingest parent of the file
* to be scheduled
*/ */
void scheduleFile(AbstractFile file, PipelineContext pipelineContext) { void scheduleFile(AbstractFile file, PipelineContext pipelineContext) {
scheduler.getFileScheduler().schedule(file, pipelineContext); scheduler.getFileScheduler().schedule(file, pipelineContext);
@ -614,8 +617,8 @@ public class IngestManager {
} }
/** /**
* Get free disk space of a drive where ingest data are written to * Get free disk space of a drive where ingest data are written to That
* That drive is being monitored by IngestMonitor thread when ingest is running. * drive is being monitored by IngestMonitor thread when ingest is running.
* Use this method to get amount of free disk space anytime. * Use this method to get amount of free disk space anytime.
* *
* @return amount of disk space, -1 if unknown * @return amount of disk space, -1 if unknown
@ -623,8 +626,7 @@ public class IngestManager {
long getFreeDiskSpace() { long getFreeDiskSpace() {
if (ingestMonitor != null) { if (ingestMonitor != null) {
return ingestMonitor.getFreeSpace(); return ingestMonitor.getFreeSpace();
} } else {
else {
return -1; return -1;
} }
} }
@ -734,8 +736,7 @@ public class IngestManager {
String moduleName; String moduleName;
if (module != null) { if (module != null) {
moduleName = module.getName(); moduleName = module.getName();
} } else {
else {
//manager message //manager message
moduleName = "System"; moduleName = "System";
} }
@ -816,16 +817,14 @@ public class IngestManager {
} }
} }
/** /**
* File ingest pipeline processor. * File ingest pipeline processor. Worker runs until AbstractFile queue is
* Worker runs until AbstractFile queue is consumed * consumed New instance is created and started when data arrives and
* New instance is created and started when data arrives and previous pipeline completed. * previous pipeline completed.
*/ */
private class IngestAbstractFileProcessor extends SwingWorker<Object, Void> { private class IngestAbstractFileProcessor extends SwingWorker<Object, Void> {
private Logger logger = Logger.getLogger(IngestAbstractFileProcessor.class.getName()); private Logger logger = Logger.getLogger(IngestAbstractFileProcessor.class.getName());
//progress bar //progress bar
private ProgressHandle progress; private ProgressHandle progress;
@ -886,8 +885,7 @@ public class IngestManager {
try { try {
stats.logFileModuleStartProcess(module); stats.logFileModuleStartProcess(module);
IngestModuleAbstractFile.ProcessResult result = module.process IngestModuleAbstractFile.ProcessResult result = module.process(filepipelineContext, fileToProcess);
(filepipelineContext, fileToProcess);
stats.logFileModuleEndProcess(module); stats.logFileModuleEndProcess(module);
//store the result for subsequent modules for this file //store the result for subsequent modules for this file
@ -898,8 +896,7 @@ public class IngestManager {
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "Error: unexpected exception from module: " + module.getName(), e); logger.log(Level.SEVERE, "Error: unexpected exception from module: " + module.getName(), e);
stats.addError(module); stats.addError(module);
} } catch (OutOfMemoryError e) {
catch (OutOfMemoryError e) {
logger.log(Level.SEVERE, "Error: out of memory from module: " + module.getName(), e); logger.log(Level.SEVERE, "Error: out of memory from module: " + module.getName(), e);
stats.addError(module); stats.addError(module);
} }
@ -1105,16 +1102,14 @@ public class IngestManager {
//queue to schedulers //queue to schedulers
final boolean processUnalloc = getProcessUnallocSpace(); final boolean processUnalloc = getProcessUnallocSpace();
final ScheduledImageTask<IngestModuleImage> imageTask = new ScheduledImageTask<IngestModuleImage>(image, imageMods); final ScheduledImageTask<IngestModuleImage> imageTask = new ScheduledImageTask<IngestModuleImage>(image, imageMods);
final PipelineContext<IngestModuleImage>imagepipelineContext final PipelineContext<IngestModuleImage> imagepipelineContext = new PipelineContext<IngestModuleImage>(imageTask, processUnalloc);
= new PipelineContext<IngestModuleImage>(imageTask, processUnalloc);
logger.log(Level.INFO, "Queing image ingest task: " + imageTask); logger.log(Level.INFO, "Queing image ingest task: " + imageTask);
progress.progress("Image Ingest" + " " + imageName, processed); progress.progress("Image Ingest" + " " + imageName, processed);
imageScheduler.schedule(imagepipelineContext); imageScheduler.schedule(imagepipelineContext);
progress.progress("Image Ingest" + " " + imageName, ++processed); progress.progress("Image Ingest" + " " + imageName, ++processed);
final ScheduledImageTask fTask = new ScheduledImageTask(image, fileMods); final ScheduledImageTask fTask = new ScheduledImageTask(image, fileMods);
final PipelineContext<IngestModuleAbstractFile>filepipelineContext final PipelineContext<IngestModuleAbstractFile> filepipelineContext = new PipelineContext<IngestModuleAbstractFile>(fTask, processUnalloc);
= new PipelineContext<IngestModuleAbstractFile>(fTask, processUnalloc);
logger.log(Level.INFO, "Queing file ingest task: " + fTask); logger.log(Level.INFO, "Queing file ingest task: " + fTask);
progress.progress("File Ingest" + " " + imageName, processed); progress.progress("File Ingest" + " " + imageName, processed);
fileScheduler.schedule(filepipelineContext); fileScheduler.schedule(filepipelineContext);