private void checkSrcLogFiles() throws IOException {
    List<FileStatus> srcLogFiles = new ArrayList<>();

    for (Path logDirPath: this.srcLogDirs) {
      srcLogFiles.addAll(FileListUtils.listFilesRecursively(this.srcFs, logDirPath, new PathFilter() {
        @Override
        public boolean accept(Path path) {
          return LogCopier.this.logFileExtensions.contains(Files.getFileExtension(path.getName()));
        }
      }));
    }

    if (srcLogFiles.isEmpty()) {
      LOGGER.warn("No log file found under directories " + this.srcLogDirs);
      return;
    }

    Set<Path> newLogFiles = Sets.newHashSet();
    for (FileStatus srcLogFile : srcLogFiles) {
      newLogFiles.add(srcLogFile.getPath());
    }

    HashSet<Path> deletedLogFiles = Sets.newHashSet(getSourceFiles());
    // Compute the set of deleted log files since the last check
    deletedLogFiles.removeAll(newLogFiles);
    // Compute the set of new log files since the last check
    newLogFiles.removeAll(getSourceFiles());

    // Schedule a copy task for each new log file
    for (final Path srcLogFile : newLogFiles) {
      String destLogFileName = this.logFileNamePrefix.isPresent()
          ? this.logFileNamePrefix.get() + "." + srcLogFile.getName() : srcLogFile.getName();
      final Path destLogFile = new Path(this.destLogDir, destLogFileName);

      this.scheduler.schedule(new LogCopyTask(srcLogFile, destLogFile), this.copyInterval, this.timeUnit);
    }

    // Cancel the copy task for each deleted log file
    for (Path deletedLogFile : deletedLogFiles) {
      Optional<LogCopyTask> logCopyTask = this.scheduler.getScheduledTask(deletedLogFile);
      if (logCopyTask.isPresent()) {
        this.scheduler.cancel(logCopyTask.get());
      }
    }
  }
private void checkSrcLogFiles ( ) throws IOException { List < FileStatus > srcLogFiles = new ArrayList < > ( ) ; for ( Path logDirPath : this . srcLogDirs ) { srcLogFiles . addAll ( FileListUtils . listFilesRecursively ( this . srcFs , logDirPath , new PathFilter ( ) { @ Override public boolean accept ( Path path ) { return LogCopier . this . logFileExtensions . contains ( Files . getFileExtension ( path . getName ( ) ) ) ; } } ) ) ; } if ( srcLogFiles . isEmpty ( ) ) { LOGGER . warn ( "No log file found under directories " + this . srcLogDirs ) ; return ; } Set < Path > newLogFiles = Sets . newHashSet ( ) ; for ( FileStatus srcLogFile : srcLogFiles ) { newLogFiles . add ( srcLogFile . getPath ( ) ) ; } HashSet < Path > deletedLogFiles = Sets . newHashSet ( getSourceFiles ( ) ) ; deletedLogFiles . removeAll ( newLogFiles ) ; newLogFiles . removeAll ( getSourceFiles ( ) ) ; for ( final Path srcLogFile : newLogFiles ) { String destLogFileName = this . logFileNamePrefix . isPresent ( ) ? this . logFileNamePrefix . get ( ) + "." + srcLogFile . getName ( ) : srcLogFile . getName ( ) ; final Path destLogFile = new Path ( this . destLogDir , destLogFileName ) ; this . scheduler . schedule ( new LogCopyTask ( srcLogFile , destLogFile ) , this . copyInterval , this . timeUnit ) ; } for ( Path deletedLogFile : deletedLogFiles ) { Optional < LogCopyTask > logCopyTask = this . scheduler . getScheduledTask ( deletedLogFile ) ; if ( logCopyTask . isPresent ( ) ) { this . scheduler . cancel ( logCopyTask . get ( ) ) ; } } }
Perform a check on new source log files and submit copy tasks for new log files.