@ -31,6 +31,8 @@ class ConcurrentEngine extends Engine with grizzled.slf4j.Logging {
debug ( s" Looking for images in directory: $directoryPath " )
debug ( s" Looking for images in directory: $directoryPath " )
val imageFiles = getAllImageFiles ( directoryPath , recursive , recursiveDepth )
val imageFiles = getAllImageFiles ( directoryPath , recursive , recursiveDepth )
val images : mutable.MutableList [ Image ] = new mutable . MutableList [ Image ] ( )
val images : mutable.MutableList [ Image ] = new mutable . MutableList [ Image ] ( )
// make sure the engine is listening
engineProcessingController ! EngineStart
for ( file <- imageFiles ) {
for ( file <- imageFiles ) {
engineProcessingController ! EngineProcessFile ( file )
engineProcessingController ! EngineProcessFile ( file )
}
}
@ -61,6 +63,8 @@ class ConcurrentEngine extends Engine with grizzled.slf4j.Logging {
debug ( s" Looking for similar images in directory: $directoryPath " )
debug ( s" Looking for similar images in directory: $directoryPath " )
val images = getImagesForDirectory ( directoryPath , recursive , recursiveDepth )
val images = getImagesForDirectory ( directoryPath , recursive , recursiveDepth )
info ( s" Searching ${ images . length } images for similarities " )
info ( s" Searching ${ images . length } images for similarities " )
// make sure the engine is listening
engineSimilarityController ! EngineStart
for ( rootImage <- images ) {
for ( rootImage <- images ) {
debug ( s" Looking for images similar to: ${ rootImage . imagePath } " )
debug ( s" Looking for images similar to: ${ rootImage . imagePath } " )
engineSimilarityController ! EngineCompareImages ( rootImage , images )
engineSimilarityController ! EngineCompareImages ( rootImage , images )
@ -113,6 +117,7 @@ class ConcurrentEngine extends Engine with grizzled.slf4j.Logging {
// external cases //
// external cases //
case class SetNewListener ( listenerType : ActorRef )
case class SetNewListener ( listenerType : ActorRef )
case object EngineStart
// processing files into images
// processing files into images
case class EngineProcessFile ( file : File )
case class EngineProcessFile ( file : File )
@ -133,7 +138,7 @@ class ConcurrentEngineProcessingController extends Actor with ActorLogging {
if ( processors > max ) threads = max else if ( processors > 1 ) threads = processors - 1 else threads = 1
if ( processors > max ) threads = max else if ( processors > 1 ) threads = processors - 1 else threads = 1
threads
threads
}
}
val router = context . actorOf ( Props [ ConcurrentEngineProcessingActor ] . withRouter ( SmallestMailboxRouter ( nrOfInstances = numOfRouters ) ) )
var router = context . actorOf ( Props [ ConcurrentEngineProcessingActor ] . withRouter ( SmallestMailboxRouter ( nrOfInstances = numOfRouters ) ) )
var images : mutable.MutableList [ Image ] = new mutable . MutableList [ Image ] ( )
var images : mutable.MutableList [ Image ] = new mutable . MutableList [ Image ] ( )
var toProcess = 0
var toProcess = 0
@ -159,6 +164,7 @@ class ConcurrentEngineProcessingController extends Actor with ActorLogging {
case command : SetNewListener => setListener ( command . listenerType )
case command : SetNewListener => setListener ( command . listenerType )
case command : EngineProcessFile => processFile ( command )
case command : EngineProcessFile => processFile ( command )
case command : EngineFileProcessed => fileProcessed ( command )
case command : EngineFileProcessed => fileProcessed ( command )
case EngineStart => startEngine ( )
case EngineNoMoreFiles => requestWrapup ( )
case EngineNoMoreFiles => requestWrapup ( )
case EngineActorProcessingFinished => actorProcessingFinished ( )
case EngineActorProcessingFinished => actorProcessingFinished ( )
case EngineIsProcessingFinished => checkIfProcessingIsFinished ( )
case EngineIsProcessingFinished => checkIfProcessingIsFinished ( )
@ -171,6 +177,10 @@ class ConcurrentEngineProcessingController extends Actor with ActorLogging {
this . listener ! PoisonPill
this . listener ! PoisonPill
}
}
def startEngine ( ) = {
router ! Broadcast ( EngineActorReactivate )
}
def processFile ( command : EngineProcessFile ) = {
def processFile ( command : EngineProcessFile ) = {
log . debug ( s" Started evaluating ${ command . file . getAbsolutePath } " )
log . debug ( s" Started evaluating ${ command . file . getAbsolutePath } " )
toProcess += 1
toProcess += 1
@ -302,6 +312,7 @@ class ConcurrentEngineSimilarityController extends Actor with ActorLogging {
case command : SetNewListener => setListener ( command . listenerType )
case command : SetNewListener => setListener ( command . listenerType )
case command : EngineCompareImages => findSimilarities ( command )
case command : EngineCompareImages => findSimilarities ( command )
case command : EngineCompareImagesComplete => similarityProcessed ( command )
case command : EngineCompareImagesComplete => similarityProcessed ( command )
case EngineStart => startEngine ( )
case EngineNoMoreComparisons => requestWrapup ( )
case EngineNoMoreComparisons => requestWrapup ( )
case EngineActorCompareImagesFinished => actorProcessingFinished ( )
case EngineActorCompareImagesFinished => actorProcessingFinished ( )
case EngineIsSimilarityFinished => checkIfProcessingIsFinished ( )
case EngineIsSimilarityFinished => checkIfProcessingIsFinished ( )
@ -314,6 +325,10 @@ class ConcurrentEngineSimilarityController extends Actor with ActorLogging {
this . listener ! PoisonPill
this . listener ! PoisonPill
}
}
def startEngine ( ) = {
router ! Broadcast ( EngineActorReactivate )
}
def findSimilarities ( command : EngineCompareImages ) = {
def findSimilarities ( command : EngineCompareImages ) = {
log . debug ( s" Finding similarities between {} and {} images " , command . image1 . imagePath , command . images . length )
log . debug ( s" Finding similarities between {} and {} images " , command . image1 . imagePath , command . images . length )
toProcess += 1
toProcess += 1