1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.goetz.domino.log4j.config;
18
19 import java.util.*;
20 import java.io.*;
21
22 /***
23 * Used to reload log4j configurations across different JVMs and class
24 * loaders.
25 *
26 * @author Bernd G?tz
27 */
28 public abstract class FileWatcher extends TimerTask {
29
30 private long timeStamp;
31
32 private File file;
33
34 public FileWatcher(File file) {
35 this.file = file;
36 this.timeStamp = file.lastModified();
37 }
38
39 public final void run() {
40 long timeStamp = file.lastModified();
41
42 if (this.timeStamp != timeStamp) {
43 this.timeStamp = timeStamp;
44 onChange(file);
45 }
46 }
47
48 /***
49 * Called only when the file changed.
50 *
51 * @param file referred file.
52 */
53 protected abstract void onChange(File file);
54 }