move interface between services and manager out to IngestManagerProxy

This commit is contained in:
adam-m
2012-02-03 17:26:06 -05:00
parent 2f59912b5c
commit 62afecfe23
8 changed files with 94 additions and 43 deletions
@@ -26,6 +26,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.ingest.IngestManagerProxy;
import org.sleuthkit.autopsy.ingest.IngestMessage;
import org.sleuthkit.autopsy.ingest.IngestServiceFsContent;
import org.sleuthkit.datamodel.BlackboardArtifact;
@@ -42,7 +43,7 @@ public class HashDbIngestService implements IngestServiceFsContent {
private static HashDbIngestService instance = null;
private final static String NAME = "Hash Lookup";
private static final Logger logger = Logger.getLogger(HashDbIngestService.class.getName());
private IngestManager manager;
private IngestManagerProxy managerProxy;
private SleuthkitCase skCase;
private static int messageId = 0;
// Whether or not to do hash lookups (only set to true if there are dbs set)
@@ -64,10 +65,10 @@ public class HashDbIngestService implements IngestServiceFsContent {
* @param IngestManager handle to the manager to postMessage() to
*/
@Override
public void init(IngestManager manager){
public void init(IngestManagerProxy managerProxy){
this.process = false;
this.manager = manager;
manager.postMessage(IngestMessage.createMessage(++messageId, IngestMessage.MessageType.INFO, this, "Started"));
this.managerProxy = managerProxy;
this.managerProxy.postMessage(IngestMessage.createMessage(++messageId, IngestMessage.MessageType.INFO, this, "Started"));
this.skCase = Case.getCurrentCase().getSleuthkitCase();
try {
HashDbSettings hashDbSettings = HashDbSettings.getHashDbSettings();
@@ -76,13 +77,13 @@ public class HashDbIngestService implements IngestServiceFsContent {
skCase.setNSRLDatabase(nsrlDbPath);
this.process = true;
}else
manager.postMessage(IngestMessage.createErrorMessage(++messageId, this, "No NSRL database set"));
this.managerProxy.postMessage(IngestMessage.createErrorMessage(++messageId, this, "No NSRL database set"));
if((knownBadDbPath = hashDbSettings.getKnownBadDatabasePath()) != null && !knownBadDbPath.equals("")){
skCase.setKnownBadDatabase(knownBadDbPath);
this.process = true;
}else
manager.postMessage(IngestMessage.createErrorMessage(++messageId, this, "No known bad database set"));
this.managerProxy.postMessage(IngestMessage.createErrorMessage(++messageId, this, "No known bad database set"));
} catch (TskException ex) {
logger.log(Level.WARNING, "Setting NSRL and Known database failed", ex);
@@ -97,7 +98,7 @@ public class HashDbIngestService implements IngestServiceFsContent {
*/
@Override
public void complete(){
manager.postMessage(IngestMessage.createMessage(++messageId, IngestMessage.MessageType.INFO, this, "Complete"));
managerProxy.postMessage(IngestMessage.createMessage(++messageId, IngestMessage.MessageType.INFO, this, "Complete"));
}
/**
@@ -138,7 +139,7 @@ public class HashDbIngestService implements IngestServiceFsContent {
//TODO: Shouldn't be calculating the hash twice.
BlackboardAttribute att3 = new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_HASH_MD5.getTypeID(), NAME, "Known Bad", Hash.calculateMd5(fsContent));
badFile.addAttribute(att3);
manager.postMessage(IngestMessage.createDataMessage(++messageId, this, "Found " + status + " file: " + name, null));
managerProxy.postMessage(IngestMessage.createDataMessage(++messageId, this, "Found " + status + " file: " + name, null));
}
} catch (TskException ex){
// TODO: This shouldn't be at level INFO, but it needs to be to hide the popup
@@ -49,7 +49,7 @@ import org.sleuthkit.datamodel.Image;
* IngestManager sets up and manages ingest services
* runs them in a background thread
* notifies services when work is complete or should be interrupted
* processes messages from services in postMessage() and posts them to GUI
* processes messages from services via messenger proxy and posts them to GUI
*
*/
public class IngestManager {
@@ -69,6 +69,8 @@ public class IngestManager {
//services
final Collection<IngestServiceImage> imageServices = enumerateImageServices();
final Collection<IngestServiceFsContent> fsContentServices = enumerateFsContentServices();
//manager proxy
final IngestManagerProxy managerProxy = new IngestManagerProxy(this);
//notifications
private final static PropertyChangeSupport pcs = new PropertyChangeSupport(IngestManager.class);
@@ -193,7 +195,7 @@ public class IngestManager {
imageIngesters.add(newImageWorker);
//image services are now initialized per instance
quService.init(this);
quService.init(managerProxy);
newImageWorker.execute();
IngestManager.firePropertyChange(SERVICE_STARTED_EVT, quService.getName());
}
@@ -223,7 +225,7 @@ public class IngestManager {
fsContentIngester = new IngestFsContentThread();
//init all fs services, everytime new worker starts
for (IngestServiceFsContent s : fsContentServices) {
s.init(this);
s.init(managerProxy);
}
fsContentIngester.execute();
}
@@ -280,7 +282,7 @@ public class IngestManager {
* Services should call this between processing iterations to get current setting
* and use the setting to change notification and data refresh intervals
*/
public synchronized int getUpdateFrequency() {
synchronized int getUpdateFrequency() {
return updateFrequency;
}
@@ -306,7 +308,7 @@ public class IngestManager {
* IngestService should make an attempt not to publish the same message multiple times.
* Viewer will attempt to identify duplicate messages and filter them out (slower)
*/
public synchronized void postMessage(final IngestMessage message) {
synchronized void postMessage(final IngestMessage message) {
if (stats != null) {
//record the error for stats, if stats are running
@@ -0,0 +1,47 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.ingest;
/**
* Facility for services to send interact with the manager
* for messaging, update frequency configuration
* interface between services and manager
*/
public class IngestManagerProxy {
private IngestManager manager;
IngestManagerProxy(IngestManager manager) {
this.manager = manager;
}
public void postMessage(final IngestMessage message) {
manager.postMessage(message);
}
public int getUpdateFrequency() {
return manager.getUpdateFrequency();
}
}
@@ -31,9 +31,9 @@ public interface IngestServiceAbstract {
* Service loads its configuration and performs initialization
* called once per new worker thread
*
* @param IngestManager handle to the manager to postMessage() to
* @param IngestManagerProxy interface to manager for posting messages, getting configurations
*/
public void init(IngestManager manager);
public void init(IngestManagerProxy managerProxy);
/**
* notification from manager that there is no more content to process and all work is done.
@@ -20,7 +20,7 @@ package org.sleuthkit.autopsy.ingest.example;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.ingest.IngestManagerProxy;
import org.sleuthkit.autopsy.ingest.IngestMessage;
import org.sleuthkit.autopsy.ingest.IngestMessage.MessageType;
import org.sleuthkit.autopsy.ingest.IngestServiceAbstract.ServiceType;
@@ -35,7 +35,7 @@ public class ExampleFsContentIngestService implements IngestServiceFsContent {
private static final Logger logger = Logger.getLogger(ExampleFsContentIngestService.class.getName());
private static ExampleFsContentIngestService instance = null;
private IngestManager manager;
private IngestManagerProxy managerProxy;
private static int messageId = 0;
public static synchronized ExampleFsContentIngestService getDefault() {
@@ -47,7 +47,7 @@ public class ExampleFsContentIngestService implements IngestServiceFsContent {
@Override
public void process(FsContent fsContent) {
manager.postMessage(IngestMessage.createMessage(++messageId, MessageType.INFO, this, "Processing " + fsContent.getName()));
managerProxy.postMessage(IngestMessage.createMessage(++messageId, MessageType.INFO, this, "Processing " + fsContent.getName()));
//service specific FsContent processing code here
try {
@@ -61,7 +61,7 @@ public class ExampleFsContentIngestService implements IngestServiceFsContent {
@Override
public void complete() {
logger.log(Level.INFO, "complete()");
manager.postMessage(IngestMessage.createMessage(++messageId, MessageType.INFO, this, "COMPLETE"));
managerProxy.postMessage(IngestMessage.createMessage(++messageId, MessageType.INFO, this, "COMPLETE"));
//service specific cleanup due completion here
}
@@ -72,9 +72,9 @@ public class ExampleFsContentIngestService implements IngestServiceFsContent {
}
@Override
public void init(IngestManager manager) {
public void init(IngestManagerProxy managerProxy) {
logger.log(Level.INFO, "init()");
this.manager = manager;
this.managerProxy = managerProxy;
//service specific initialization here
}
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.sleuthkit.autopsy.ingest.IngestImageWorkerController;
import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.ingest.IngestManagerProxy;
import org.sleuthkit.autopsy.ingest.IngestMessage;
import org.sleuthkit.autopsy.ingest.IngestMessage.MessageType;
import org.sleuthkit.autopsy.ingest.IngestServiceImage;
@@ -35,7 +36,7 @@ public final class ExampleImageIngestService implements IngestServiceImage {
private static final Logger logger = Logger.getLogger(ExampleImageIngestService.class.getName());
private static ExampleImageIngestService defaultInstance = null;
private IngestManager manager;
private IngestManagerProxy managerProxy;
private static int messageId = 0;
//public constructor is required
@@ -55,7 +56,7 @@ public final class ExampleImageIngestService implements IngestServiceImage {
public void process(Image image, IngestImageWorkerController controller) {
logger.log(Level.INFO, "process() " + this.toString());
manager.postMessage(IngestMessage.createMessage(++messageId, MessageType.INFO, this, "Processing " + image.getName()));
managerProxy.postMessage(IngestMessage.createMessage(++messageId, MessageType.INFO, this, "Processing " + image.getName()));
//service specific Image processing code here
//example:
@@ -75,7 +76,7 @@ public final class ExampleImageIngestService implements IngestServiceImage {
//do the work
Thread.sleep(500);
//post message to user if found something interesting
manager.postMessage(IngestMessage.createMessage(processedFiles, MessageType.INFO, this, "Processed " + image.getName() + ": " + Integer.toString(processedFiles)));
managerProxy.postMessage(IngestMessage.createMessage(processedFiles, MessageType.INFO, this, "Processed " + image.getName() + ": " + Integer.toString(processedFiles)));
//update progress
controller.progress(++processedFiles);
@@ -91,7 +92,7 @@ public final class ExampleImageIngestService implements IngestServiceImage {
logger.log(Level.INFO, "complete() " + this.toString());
final IngestMessage msg = IngestMessage.createMessage(++messageId, MessageType.INFO, this, "completed image processing");
manager.postMessage(msg);
managerProxy.postMessage(msg);
//service specific cleanup due to completion here
}
@@ -102,9 +103,9 @@ public final class ExampleImageIngestService implements IngestServiceImage {
}
@Override
public void init(IngestManager manager) {
public void init(IngestManagerProxy managerProxy) {
logger.log(Level.INFO, "init() " + this.toString());
this.manager = manager;
this.managerProxy = managerProxy;
//service specific initialization here
@@ -24,7 +24,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import org.apache.solr.client.solrj.SolrServerException;
import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.ingest.IngestManagerProxy;
import org.sleuthkit.autopsy.ingest.IngestMessage;
import org.sleuthkit.autopsy.ingest.IngestMessage.MessageType;
import org.sleuthkit.autopsy.ingest.IngestServiceFsContent;
@@ -37,7 +37,7 @@ public final class KeywordSearchIngestService implements IngestServiceFsContent
private static final Logger logger = Logger.getLogger(KeywordSearchIngestService.class.getName());
private static KeywordSearchIngestService instance = null;
private IngestManager manager;
private IngestManagerProxy managerProxy;
private int messageID = 0;
private static final long MAX_STRING_EXTRACT_SIZE = 10 * (1 << 10) * (1 << 10);
private static final long MAX_INDEX_SIZE = 200 * (1 << 10) * (1 << 10);
@@ -129,7 +129,7 @@ public final class KeywordSearchIngestService implements IngestServiceFsContent
logger.log(Level.INFO, "Error executing Solr query to check number of indexed files: ", se);
}
manager.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Complete"));
managerProxy.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Complete"));
//manager.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Indexed files: " + ingestStat));
//postSummary();
}
@@ -140,16 +140,16 @@ public final class KeywordSearchIngestService implements IngestServiceFsContent
}
@Override
public void init(IngestManager manager) {
public void init(IngestManagerProxy managerProxy) {
logger.log(Level.INFO, "init()");
this.manager = manager;
this.managerProxy = managerProxy;
final Server.Core solrCore = KeywordSearch.getServer().getCore();
ingester = solrCore.getIngester();
ingestStatus = new HashMap<Long, IngestStatus>();
manager.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Started"));
managerProxy.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Started"));
}
@Override
@@ -215,8 +215,8 @@ public final class KeywordSearchIngestService implements IngestServiceFsContent
;
}
}
manager.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Indexed files: " + indexed));
manager.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Indexed strings: " + indexed_extr));
manager.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Skipped files: " + skipped));
managerProxy.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Indexed files: " + indexed));
managerProxy.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Indexed strings: " + indexed_extr));
managerProxy.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Skipped files: " + skipped));
}
}
@@ -21,7 +21,7 @@ package org.sleuthkit.autopsy.recentactivity;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.sleuthkit.autopsy.ingest.IngestImageWorkerController;
import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.ingest.IngestManagerProxy;
import org.sleuthkit.autopsy.ingest.IngestMessage;
import org.sleuthkit.autopsy.ingest.IngestMessage.MessageType;
import org.sleuthkit.autopsy.ingest.IngestServiceImage;
@@ -35,7 +35,7 @@ public final class RAImageIngestService implements IngestServiceImage {
private static final Logger logger = Logger.getLogger(RAImageIngestService.class.getName());
private static RAImageIngestService defaultInstance = null;
private IngestManager manager;
private IngestManagerProxy managerProxy;
private static int messageId = 0;
//public constructor is required
@@ -54,7 +54,7 @@ public final class RAImageIngestService implements IngestServiceImage {
@Override
public void process(Image image, IngestImageWorkerController controller) {
//logger.log(Level.INFO, "process() " + this.toString());
manager.postMessage(IngestMessage.createMessage(++messageId, MessageType.INFO, this, "Started " + image.getName()));
managerProxy.postMessage(IngestMessage.createMessage(++messageId, MessageType.INFO, this, "Started " + image.getName()));
ExtractAll ext = new ExtractAll();
@@ -64,7 +64,7 @@ public final class RAImageIngestService implements IngestServiceImage {
} catch (Exception e) {
logger.log(Level.SEVERE, "Error extracting recent activity", e);
manager.postMessage(IngestMessage.createErrorMessage(++messageId, this, "Error extracting recent activity data"));
managerProxy.postMessage(IngestMessage.createErrorMessage(++messageId, this, "Error extracting recent activity data"));
}
}
@@ -74,7 +74,7 @@ public final class RAImageIngestService implements IngestServiceImage {
logger.log(Level.INFO, "complete() " + this.toString());
final IngestMessage msg = IngestMessage.createMessage(++messageId, MessageType.INFO, this, "Completed");
manager.postMessage(msg);
managerProxy.postMessage(msg);
//service specific cleanup due to completion here
}
@@ -85,9 +85,9 @@ public final class RAImageIngestService implements IngestServiceImage {
}
@Override
public void init(IngestManager manager) {
public void init(IngestManagerProxy managerProxy) {
logger.log(Level.INFO, "init() " + this.toString());
this.manager = manager;
this.managerProxy = managerProxy;
//service specific initialization here