From c99491a8e77341d04b275f9e97c92284cf12b68c Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Fri, 9 Apr 2021 11:45:30 -0400 Subject: [PATCH] categorizer initialize on demand --- .../DefaultDomainCategorizer.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/DefaultDomainCategorizer.java b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/DefaultDomainCategorizer.java index 0d64661f6c..9519a37bb1 100644 --- a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/DefaultDomainCategorizer.java +++ b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/DefaultDomainCategorizer.java @@ -128,18 +128,33 @@ public class DefaultDomainCategorizer implements DomainCategorizer { private Map mapping = null; @Override - public void initialize() throws DomainCategorizerException { - if (this.mapping == null) { - try { - this.mapping = loadMapping(); - } catch (IOException ex) { - throw new DomainCategorizerException("Unable to load domain type csv for domain category analysis", ex); - } + public synchronized void initialize() throws DomainCategorizerException { + if (isInitialized()) { + return; + } + + try { + this.mapping = loadMapping(); + } catch (IOException ex) { + throw new DomainCategorizerException("Unable to load domain type csv for domain category analysis", ex); } } + /** + * Returns true if this categorizer is properly initialized. + * + * @return True if this categorizer is properly initialized. + */ + private synchronized boolean isInitialized() { + return this.mapping != null; + } + @Override - public DomainCategory getCategory(String domain, String host) throws DomainCategorizerException { + public synchronized DomainCategory getCategory(String domain, String host) throws DomainCategorizerException { + if (!isInitialized()) { + initialize(); + } + // use host; use domain as fallback if no host provided String hostToUse = StringUtils.isBlank(host) ? domain : host; @@ -162,7 +177,7 @@ public class DefaultDomainCategorizer implements DomainCategorizer { } @Override - public void close() throws Exception { + public synchronized void close() throws Exception { // clear out the mapping to release resources mapping = null; }