1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.googlecode.t7mp.scanner;
17
18 import java.util.Timer;
19
20 import com.googlecode.t7mp.PluginLog;
21 import com.googlecode.t7mp.Stoppable;
22
23
24
25
26
27
28
29 public final class Scanner implements Stoppable {
30
31 private static final int DEFAULT_DELAY = 10000;
32 private static final int MILLIS = 1000;
33
34 private final ScannerConfiguration scannerConfiguration;
35 private Timer timer;
36 private final PluginLog log;
37
38 public Scanner(ScannerConfiguration scannerConfiguration, PluginLog log) {
39 this.scannerConfiguration = scannerConfiguration;
40 this.log = log;
41 }
42
43 public void start() {
44 log.info("Starting Scanner ....");
45 this.timer = new Timer();
46 this.timer.scheduleAtFixedRate(new ModifiedFileTimerTask(scannerConfiguration.getRootDirectory(),
47 scannerConfiguration.getWebappDirectory(), scannerConfiguration.getEndingsAsList(), log),
48 DEFAULT_DELAY, scannerConfiguration.getInterval() * MILLIS);
49 log.info("Scanner started");
50 }
51
52 public void stop() {
53 log.info("Stopping Scanner ...");
54 if (this.timer == null) {
55 return;
56 }
57 this.timer.cancel();
58 log.info("Scanner stopped");
59 }
60
61 }