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 protected Log logger = LogFactory.getLog(getClass());
18
19 private long timeStamp;
20 private File file;
21
22 public AbstractFileWatcher(File file)
23 {
24 this.file = file;
25 this.timeStamp = file.lastModified();
26 }
27
28 public final void run()
29 {
30 long timeStamp = file.lastModified();
31
32 if (this.timeStamp != timeStamp)
33 {
34 this.timeStamp = timeStamp;
35 try
36 {
37 onChange(file);
38 }
39 catch (Throwable t)
40 {
41 logger.error(String.format("Monitor for %s threw an exception", file), t);
42 }
43 }
44 }
45
46 protected abstract void onChange(File file);
47 }