001/*
002 * $Id: FileWatcherExample.java,v 1.3 2002/07/05 14:25:09 Terry.Dye Exp $
003 *
004 * FileWatcherExample.java
005 *
006 * Created on 26. Juni 2002, 12:31
007 */
008
009package org.jconfig;
010
011import java.lang.Thread;
012
013import org.jconfig.event.FileListener;
014import org.jconfig.event.FileListenerEvent;
015/**
016 *
017 * @author  Terry R. Dye
018 */
019public class FileWatcherExample {
020
021    /** Creates a new instance of FileWatcherExample */
022    public FileWatcherExample() {
023    }
024
025    public static void main( String args[] ) throws Exception {
026        FileWatcher fileWatcher = new FileWatcher( "config.xml" );
027        fileWatcher.start();
028        fileWatcher.addFileListener( new DoSomething() );
029
030        FileWatcher fileWatcher2 = new FileWatcher( "config2.xml" );
031        fileWatcher2.start();
032        fileWatcher2.addFileListener( new DoSomethingElse() );
033    }
034    
035    public void run() {
036        int i = 10;
037        while( i-- > 0 ) {
038            System.out.println("waiting");
039            try {
040                Thread.sleep( 10000 );
041            } catch( Exception e ) {
042                return;
043            }
044        }
045        System.out.println("done waiting");
046    }
047}
048
049class DoSomething implements FileListener {
050
051    /**
052     * my little test
053     */
054    public DoSomething() {}
055
056    /** This method, once implemented, will be called when the File object
057     * itself changes.
058     *
059     * @param FileListener The FileListener object.
060     */
061    public void fileChanged( FileListenerEvent e ) {
062        System.out.println( "File changed: " + e );
063    }
064}
065
066class DoSomethingElse implements FileListener {
067
068    /**
069     * my little test
070     */
071    public DoSomethingElse() {}
072
073    /** This method, once implemented, will be called when the File object
074     * itself changes.
075     *
076     * @param FileListener The FileListener object.
077     */
078    public void fileChanged( FileListenerEvent e ) {
079        System.out.println( "Something else changed: " + e );
080    }
081}
082/**
083 * $Log: FileWatcherExample.java,v $
084 * Revision 1.3  2002/07/05 14:25:09  Terry.Dye
085 * Daily changes
086 *
087 * Revision 1.2  2002/06/28 09:53:25  Terry.Dye
088 * Example updated to shutdown thread properly/safely.
089 *
090 * Revision 1.1  2002/06/26 16:12:43  Terry.Dye
091 * Created
092 *
093 */