Commit 11aa1072 authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

Integrated Pipeline: renamed TreeParser to TreeScanner

-new name makes the difference between "scanning" a file tree for candidate calculations and
 the actual "parsing" of individual files to extract meta-info more clear
parent de890087
......@@ -6,15 +6,15 @@ import scala.collection.parallel.mutable
trait EventListener {
private final val registeredTreeParsers: mutable.ParMap[TreeParser, TreeParserId] = mutable.ParMap()
private final val registeredTreeParsers: mutable.ParMap[TreeScanner, TreeScannerId] = mutable.ParMap()
private final val registeredCalculationParsers: mutable.ParMap[CalculationParsingEngine, CalculationParserId] = mutable.ParMap()
private final val registeredResultWriters: mutable.ParMap[ParsingResultsProcessingManager, ResultWriterId] = mutable.ParMap()
def registerReporter(reference: TreeParser, reporterId: Option[String]): TreeParserId = {
def registerReporter(reference: TreeScanner, reporterId: Option[String]): TreeScannerId = {
if (registeredTreeParsers.contains(reference)) {
throw new IllegalArgumentException("reference already registered as reporter")
} else {
val id = TreeParserId(reporterId.getOrElse(reference.toString), reference)
val id = TreeScannerId(reporterId.getOrElse(reference.toString), reference)
registeredTreeParsers.put(reference, id)
id
}
......@@ -40,7 +40,7 @@ trait EventListener {
}
}
def processEvent(reporter: TreeParserId, message: TreeParserEvent): Unit = {}
def processEvent(reporter: TreeScannerId, message: TreeParserEvent): Unit = {}
def processEvent(reporter: CalculationParserId, message: CalculationParserEvent): Unit = {}
......
......@@ -21,7 +21,7 @@ object EventLogger {
trait EventLogger extends EventListener with Logging {
import EventLogger._
override def processEvent(reporter: TreeParserId, message: TreeParserEvent): Unit = {
override def processEvent(reporter: TreeScannerId, message: TreeParserEvent): Unit = {
message match {
case x: TreeParserEventStart => logger.info(
baseMarker,
......
......@@ -126,7 +126,7 @@ class Main {
val treeParser = Flow.fromGraph(new MessageProcessorFlow[FileTreeScanTask, FileParsingTaskSignal] {
override val stageName = "TreeParser"
override val processor = new TreeParser {
override val processor = new TreeScanner {
override val eventListener = eventProcessor
override def createProcessor(task: FileTreeScanTask) = params.treeType match {
case TreeType.Zip => new ZipTreeParsingTaskGenerator(task, Main.parsers)
......
......@@ -4,7 +4,12 @@ import eu.nomad_lab.integrated_pipeline.messages._
import scala.annotation.tailrec
trait TreeParser extends MessageProcessor[FileTreeScanTask, FileParsingTaskSignal] {
/**
* A TreeScanner examines ("scans") all files inside a file tree (e.g. a directory or a
* zip-archive) for files that are potential calculations of interest for NOMAD and emits file
* parsing requests for these candidate files.
*/
trait TreeScanner extends MessageProcessor[FileTreeScanTask, FileParsingTaskSignal] {
protected[this] def createProcessor(task: FileTreeScanTask): ParsingTaskGenerator
protected[this] val eventListener: EventListener
......
......@@ -13,7 +13,7 @@ package object integrated_pipeline {
}
sealed abstract trait EventReporterId { val name: String }
case class TreeParserId(name: String, reference: TreeParser) extends EventReporterId
case class TreeScannerId(name: String, reference: TreeScanner) extends EventReporterId
case class CalculationParserId(name: String, reference: CalculationParsingEngine) extends EventReporterId
case class ResultWriterId(name: String, reference: ParsingResultsProcessingManager) extends EventReporterId
......
......@@ -8,7 +8,7 @@ import org.scalatest.{ Matchers, fixture }
trait EventListenerBehaviour extends Matchers with MockitoSugar with TestDataBuilders { this: fixture.WordSpec =>
abstract class EventListenerFixture(val listener: EventListener) {
val treeParser = mock[TreeParser]
val treeParser = mock[TreeScanner]
val calculationParser = mock[CalculationParsingEngine]
val resultWriter = mock[ParsingResultsProcessingManager]
}
......@@ -32,7 +32,7 @@ trait EventListenerBehaviour extends Matchers with MockitoSugar with TestDataBui
"accept (multiple) registrations for each EventReporterType" in { () =>
val f = fixture()
(1 to 3).foreach(_ => f.listener.registerReporter(mock[TreeParser], None))
(1 to 3).foreach(_ => f.listener.registerReporter(mock[TreeScanner], None))
(1 to 3).foreach(_ => f.listener.registerReporter(mock[CalculationParsingEngine], None))
(1 to 3).foreach(_ => f.listener.registerReporter(mock[ParsingResultsProcessingManager], None))
succeed
......@@ -40,7 +40,7 @@ trait EventListenerBehaviour extends Matchers with MockitoSugar with TestDataBui
"throw an exception if the same event reporter is registered twice" in { () =>
val f = fixture()
val treeParser = mock[TreeParser]
val treeParser = mock[TreeScanner]
val calculationParser = mock[CalculationParsingEngine]
val resultWriter = mock[ParsingResultsProcessingManager]
f.listener.registerReporter(treeParser, None)
......@@ -57,7 +57,7 @@ trait EventListenerBehaviour extends Matchers with MockitoSugar with TestDataBui
"process incoming events from the registered file tree parser normally" in { () =>
val f = fixture()
val id = TreeParserId(f.treeParser.toString, f.treeParser)
val id = TreeScannerId(f.treeParser.toString, f.treeParser)
sampleTreeParserEvents.foreach { message => f.listener.processEvent(id, message) }
succeed
}
......
......@@ -10,7 +10,7 @@ class EventLoggerSpec extends LoggingTestWrapper with MockitoSugar with EventLis
with CustomMatchers with TestDataBuilders {
class EventLoggerFixture(val logger: EventLogger) extends EventListenerFixture(logger) {
var treeParserId: Option[TreeParserId] = None
var treeParserId: Option[TreeScannerId] = None
var calculationParserId: Option[CalculationParserId] = None
var resultWriterId: Option[ResultWriterId] = None
}
......
package eu.nomad_lab.integrated_pipeline_tests
import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.integrated_pipeline.{ EventListener, ParsingTaskGenerator, TreeParser }
import eu.nomad_lab.integrated_pipeline.{ EventListener, ParsingTaskGenerator, TreeScanner }
import eu.nomad_lab.integrated_pipeline_tests.matchers._
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
......@@ -13,7 +13,7 @@ import org.scalatest.mockito.MockitoSugar
import scala.collection.JavaConverters._
class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
class TreeScannerSpec extends WordSpec with TestDataBuilders with MockitoSugar
with MessageProcessorBehaviour[FileTreeScanTask, FileParsingTaskSignal] {
private def argsCaptor(): ArgumentCaptor[TreeParserEvent] = ArgumentCaptor.forClass(classOf[TreeParserEvent])
......@@ -24,7 +24,7 @@ class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
class Fixture(sampleData: Iterator[Either[TreeParserEventScanError, FileParsingTask]]) {
val events = mock[EventListener]
val taskGenerator = mock[ParsingTaskGenerator]
val treeParser = new TreeParser {
val treeParser = new TreeScanner {
override val eventListener = events
override def createProcessor(task: FileTreeScanTask) = taskGenerator
override protected[this] val eventReporterName: Option[String] = Some("TreeParserSpec")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment