1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.launcher; |
8 | |
|
9 | |
import java.io.File; |
10 | |
|
11 | |
import org.apache.commons.logging.Log; |
12 | |
import org.apache.commons.logging.LogFactory; |
13 | |
|
14 | |
public abstract class AbstractFileWatcher implements Runnable |
15 | |
{ |
16 | |
|
17 | 0 | protected Log logger = LogFactory.getLog(getClass()); |
18 | |
|
19 | |
private long timeStamp; |
20 | |
private File file; |
21 | |
|
22 | |
public AbstractFileWatcher(File file) |
23 | 0 | { |
24 | 0 | this.file = file; |
25 | 0 | this.timeStamp = file.lastModified(); |
26 | 0 | } |
27 | |
|
28 | |
public final void run() |
29 | |
{ |
30 | 0 | long timeStamp = file.lastModified(); |
31 | |
|
32 | 0 | if (this.timeStamp != timeStamp) |
33 | |
{ |
34 | 0 | this.timeStamp = timeStamp; |
35 | |
try |
36 | |
{ |
37 | 0 | onChange(file); |
38 | |
} |
39 | 0 | catch (Throwable t) |
40 | |
{ |
41 | 0 | logger.error(String.format("Monitor for %s threw an exception", file), t); |
42 | 0 | } |
43 | |
} |
44 | 0 | } |
45 | |
|
46 | |
protected abstract void onChange(File file); |
47 | |
} |