private void scanDirectory(final File directory) { if (this.isKiekerDirectory(directory)) { this.logger.debug("Reading log data from {}", directory.getAbsolutePath()); this.numOfDirectories++; this.getOutputPort().send(directory); } else { for (final File subDirectory : directory.listFiles()) { // NOFB is guaranteed to be a directory if (subDirectory.isDirectory()) { this.scanDirectory(subDirectory); } } } }
/** * Execute the directory scanner. */ @Override protected void execute() { if (this.directories != null) { for (final File directory : this.directories) { this.logger.debug("Scanning directories in {} for Kieker logs", directory); if (directory.isDirectory()) { this.scanDirectory(directory); } } } else { this.logger.error("Cannot process an empty array of directories."); } this.logger.debug("Processed {} directories.", this.numOfDirectories); this.workCompleted(); }
/** * Creates a composite stage to scan and read a set of Kieker log directories. * * @param configuration configuration for the enclosed filters */ public LogsReaderCompositeStage(final Configuration configuration) { final String[] directoryNames = configuration.getStringArrayProperty(LOG_DIRECTORIES, ":"); final File[] directories = new File[directoryNames.length]; int i = 0; for (final String name : directoryNames) { directories[i++] = new File(name); } this.directoryScannerStage = new DirectoryScannerStage(directories); this.directoryReaderStage = new DirectoryReaderStage(configuration); this.connectPorts(this.directoryScannerStage.getOutputPort(), this.directoryReaderStage.getInputPort()); }
/** * Check whether the scanner produces a File handle for each directory. There should be three * directories. However, the sequence can vary depending on the operating system and file system * properties. therefore, we use our own matcher. */ @Test public void testPopulatedArrayOfDirectories() { final DirectoryScannerStage producer = new DirectoryScannerStage(this.directories); StageTester.test(producer).start(); Assert.assertThat(producer.getOutputPort(), new RandomContentMatcher(this.results)); }
/** * Check whether the scanner produces nothing and terminates. */ @Test public void testEmptyArrayOfDirectories() { final DirectoryScannerStage producer = new DirectoryScannerStage(null); StageTester.test(producer).start(); Assert.assertThat(producer.getOutputPort(), StageTester.producesNothing()); }