From fabace8005f179b5a5f04ab109f3ba8589f0ca99 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Fri, 22 Aug 2014 22:31:20 -0500 Subject: [PATCH] Fixes for unmanaged FileInputStreams hogging file descriptors. Misc UI fixes. Temporary fallback to the sequential engine as it works on remote files and consistently. Massive cleanup work. Need to go through code and do a little more cleanup. Need to inspect why the concurrent engine chokes on remote files and multiple runs. (Nothing helpful in logs as of yet.) --- pom.xml | 15 ++- src/includes/LICENSE | 2 +- .../java/com/sothr/imagetools/AppCLI.java | 3 + .../java/com/sothr/imagetools/AppConfig.java | 30 +++--- .../errors/ImageToolsException.java | 2 + .../sothr/imagetools/util/ResourceLoader.java | 5 +- src/main/resources/application.conf | 6 +- src/main/resources/ehcache.xml | 1 + src/main/resources/fxml/mainapp/MainApp.fxml | 15 +-- .../sothr/imagetools/dao/HibernateUtil.scala | 16 ++- .../com/sothr/imagetools/dao/ImageDAO.scala | 6 +- .../sothr/imagetools/dto/ImageHashDTO.scala | 3 +- .../{ => engine}/ConcurrentEngine.scala | 36 +++---- .../imagetools/{ => engine}/Engine.scala | 19 ++-- .../{ => engine}/SequentialEngine.scala | 13 ++- .../com/sothr/imagetools/hash/DHash.scala | 4 +- .../sothr/imagetools/hash/HashService.scala | 36 ++++--- .../imagetools/hash/PerceptualHasher.scala | 4 +- .../com/sothr/imagetools/image/Image.scala | 7 +- .../sothr/imagetools/image/ImageFilter.scala | 5 + .../sothr/imagetools/image/ImageService.scala | 26 ++--- .../imagetools/image/SimilarImages.scala | 4 +- .../imagetools/ui/component/ImageTile.scala | 3 + .../ui/component/ImageTileFactory.scala | 54 +++++++--- .../ui/controller/AppController.scala | 101 ++++++++++++------ .../imagetools/util/DirectoryFilter.scala | 4 +- .../imagetools/util/PropertiesService.scala | 59 +++++----- ...ropertiesEnum.scala => PropertyEnum.scala} | 10 +- .../com/sothr/imagetools/util/Version.scala | 46 ++++---- src/test/resources/application.conf | 6 +- .../scala/com/sothr/imagetools/BaseTest.scala | 4 +- .../com/sothr/imagetools/EngineTest.scala | 4 + .../com/sothr/imagetools/ScalaAppTest.scala | 2 +- .../imagetools/hash/HashServiceTest.scala | 18 ++-- .../imagetools/image/ImageFilterTest.scala | 5 +- 35 files changed, 364 insertions(+), 210 deletions(-) rename src/main/scala/com/sothr/imagetools/{ => engine}/ConcurrentEngine.scala (94%) rename src/main/scala/com/sothr/imagetools/{ => engine}/Engine.scala (91%) rename src/main/scala/com/sothr/imagetools/{ => engine}/SequentialEngine.scala (94%) rename src/main/scala/com/sothr/imagetools/util/{PropertiesEnum.scala => PropertyEnum.scala} (81%) diff --git a/pom.xml b/pom.xml index d89afab..792541b 100644 --- a/pom.xml +++ b/pom.xml @@ -28,12 +28,13 @@ UTF-8 1.8 + 2.11 + 2.11.2 4.11 2.2.1 1.1.2 1.7.7 1.0.2 - 2.11.2 2.3.5 1.1 2.8.0 @@ -46,6 +47,7 @@ 4.3.0.Final 2.6.6 2.2-cj-1.0 + 1.4 @@ -57,7 +59,7 @@ org.scalatest - scalatest_2.11 + scalatest_${scala.binary.version} ${lib.scalatest.version} test @@ -83,7 +85,7 @@ org.clapper - grizzled-slf4j_2.11 + grizzled-slf4j_${scala.binary.version} ${lib.grizzled-slf4j.version} @@ -133,7 +135,7 @@ com.typesafe.akka - akka-slf4j_2.11 + akka-slf4j_${scala.binary.version} ${lib.akka.version} @@ -166,6 +168,11 @@ markdown4j ${lib.markdown4j.version} + + com.jsuereth + scala-arm_${scala.binary.version} + ${lib.scala-arm.version} + diff --git a/src/includes/LICENSE b/src/includes/LICENSE index c969132..0dcd862 100644 --- a/src/includes/LICENSE +++ b/src/includes/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013 Drew Short +Copyright (c) 2014 Drew Short Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/main/java/com/sothr/imagetools/AppCLI.java b/src/main/java/com/sothr/imagetools/AppCLI.java index e18f27d..7c63604 100644 --- a/src/main/java/com/sothr/imagetools/AppCLI.java +++ b/src/main/java/com/sothr/imagetools/AppCLI.java @@ -3,6 +3,9 @@ package com.sothr.imagetools; import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Props; +import com.sothr.imagetools.engine.CLIEngineListener; +import com.sothr.imagetools.engine.ConcurrentEngine; +import com.sothr.imagetools.engine.Engine; import com.sothr.imagetools.image.SimilarImages; import org.apache.commons.cli.*; import org.slf4j.Logger; diff --git a/src/main/java/com/sothr/imagetools/AppConfig.java b/src/main/java/com/sothr/imagetools/AppConfig.java index f98d987..be8ddf6 100644 --- a/src/main/java/com/sothr/imagetools/AppConfig.java +++ b/src/main/java/com/sothr/imagetools/AppConfig.java @@ -1,23 +1,19 @@ package com.sothr.imagetools; import akka.actor.ActorSystem; -import com.sothr.imagetools.dao.HibernateUtil; -import com.sothr.imagetools.util.ResourceLoader; -import com.sothr.imagetools.util.PropertiesService; -import com.sothr.imagetools.util.PropertiesEnum; -import javafx.stage.Stage; -import net.sf.ehcache.CacheManager; - -import org.slf4j.LoggerFactory; - import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.util.StatusPrinter; +import com.sothr.imagetools.dao.HibernateUtil; +import com.sothr.imagetools.util.PropertiesService; +import com.sothr.imagetools.util.ResourceLoader; +import javafx.stage.Stage; +import net.sf.ehcache.CacheManager; +import org.slf4j.LoggerFactory; import java.io.File; -import java.util.Properties; public class AppConfig { @@ -37,7 +33,7 @@ public class AppConfig { private static Boolean configuredCache = false; // General Akka Actor System - private static ActorSystem appSystem = ActorSystem.create("ITActorSystem"); + private static final ActorSystem appSystem = ActorSystem.create("ITActorSystem"); // The Main App private static Stage primaryStage = null; @@ -55,7 +51,7 @@ public class AppConfig { configCache(); } - public static void configLogging(String location) { + private static void configLogging(String location) { //Logging Config //remove previous configuration if it exists Logger rootLogger = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); @@ -91,11 +87,11 @@ public class AppConfig { } String message = fromFile ? "From File" : "From Defaults"; logger.info(String.format("Configured Logger %s", message)); - logger.info("Detected Version: %s of Image Tools".format(PropertiesService.getVersion().toString())); + logger.info(String.format("Detected Version: %s of Image Tools", PropertiesService.getVersion().toString())); } //Only configure logging from the default file once - public static void configLogging() { + private static void configLogging() { if (!configuredLogging) { configLogging(LOGSETTINGSFILE); configuredLogging = true; @@ -103,7 +99,7 @@ public class AppConfig { } } - public static void loadProperties() { + private static void loadProperties() { if (!loadedProperties) { File file = new File(USERPROPERTIESFILE); if (file.exists()) { @@ -116,7 +112,7 @@ public class AppConfig { } } - public static void configCache() { + private static void configCache() { if (!configuredCache) { cacheManager = CacheManager.newInstance(); configuredCache = true; @@ -129,7 +125,7 @@ public class AppConfig { HibernateUtil.getSessionFactory().close(); } - public static void saveProperties() { + private static void saveProperties() { PropertiesService.saveConf(USERPROPERTIESFILE); logger.debug("Saved properties"); } diff --git a/src/main/java/com/sothr/imagetools/errors/ImageToolsException.java b/src/main/java/com/sothr/imagetools/errors/ImageToolsException.java index b935788..e7bb3d1 100644 --- a/src/main/java/com/sothr/imagetools/errors/ImageToolsException.java +++ b/src/main/java/com/sothr/imagetools/errors/ImageToolsException.java @@ -1,6 +1,8 @@ package com.sothr.imagetools.errors; /** + * Simple Exception + * * Created by drew on 12/31/13. */ public class ImageToolsException extends Exception { diff --git a/src/main/java/com/sothr/imagetools/util/ResourceLoader.java b/src/main/java/com/sothr/imagetools/util/ResourceLoader.java index 04783f3..e480d7a 100644 --- a/src/main/java/com/sothr/imagetools/util/ResourceLoader.java +++ b/src/main/java/com/sothr/imagetools/util/ResourceLoader.java @@ -2,17 +2,20 @@ package com.sothr.imagetools.util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import java.io.InputStream; import java.net.URL; /** + * Seamlessly handle resource loading + * * Created by drew on 1/5/14. */ public class ResourceLoader { private static final ResourceLoader instance = new ResourceLoader(); - private Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private ResourceLoader() { logger.info("Created Resource Loader"); diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 73c3060..420807b 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -29,20 +29,20 @@ app { use = true weight = 0.70 precision = 8 - tolerence = 8 + tolerance = 8 } dhash { use = true weight = 0.85 precision = 8 - tolerence = 8 + tolerance = 8 } phash { //set to false if hashing images is taking too long use = true weight = 1.0 precision = 32 - tolerence = 8 + tolerance = 8 } } //Default Thumbnail Settings diff --git a/src/main/resources/ehcache.xml b/src/main/resources/ehcache.xml index 705dd72..08679a7 100644 --- a/src/main/resources/ehcache.xml +++ b/src/main/resources/ehcache.xml @@ -1,4 +1,5 @@ + diff --git a/src/main/resources/fxml/mainapp/MainApp.fxml b/src/main/resources/fxml/mainapp/MainApp.fxml index 43007f0..f9811fc 100644 --- a/src/main/resources/fxml/mainapp/MainApp.fxml +++ b/src/main/resources/fxml/mainapp/MainApp.fxml @@ -1,11 +1,10 @@ - + - - + @@ -62,8 +61,12 @@ - +