View Javadoc

1   /*
2    * Copyright 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }