Clover coverage report - Alipes Project - 0.1
Coverage timestamp: Sat Sep 10 2005 21:25:58 BST
file stats: LOC: 112   Methods: 3
NCLOC: 65   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FileChangeConsoleAlerter.java 0% 0% 0% 0%
coverage
 1    /*
 2    * $Id: FileShowAllConsoleAlerter.java,v 1.3 2004/03/09 22:29:32
 3    * johndavidtaylor Exp $ Created on Mar 10, 2004 by John Taylor jdt@roe.ac.uk .
 4    */
 5    package org.abraracourcix.alipes.alerters;
 6    import java.io.File;
 7    import java.io.IOException;
 8    import org.abraracourcix.alipes.listeners.Listener;
 9    import org.abraracourcix.alipes.listeners.filter.EventFilterListener;
 10    import org.abraracourcix.alipes.listeners.logging.ConsoleListener;
 11    import org.abraracourcix.alipes.monitors.file.FileEvent;
 12    import org.abraracourcix.alipes.monitors.file.FileStateMonitor;
 13    /**
 14    * Takes a list of filenames, a stale interval, and watches those files to see
 15    * if they're deleted/stale/created or change
 16    *
 17    * @author jdt
 18    */
 19    public final class FileChangeConsoleAlerter {
 20    /**
 21    * Hide public Constructor
 22    *
 23    */
 24  0 private FileChangeConsoleAlerter() {
 25    }
 26    /**
 27    * Set the wheels in motion
 28    *
 29    * @param args
 30    * staletime(seconds) files
 31    * @throws InterruptedException
 32    * if you hit ctrl-C
 33    * @throws IOException
 34    * if there's a prob finding the files
 35    */
 36  0 public static void main(final String[] args)
 37    throws InterruptedException, IOException {
 38  0 if (args.length < 2) {
 39  0 giveHelp();
 40  0 return;
 41    }
 42  0 final String interval = args[0];
 43  0 final File[] files = new File[args.length - 1];
 44  0 for (int i = 0; i < args.length - 1; ++i) {
 45  0 files[i] = new File(args[i + 1]);
 46    }
 47  0 final int maxFiles2Show = 5;
 48  0 System.out.println("Monitoring " + files.length + " files:");
 49  0 for (int i = 0; i < Math.min(files.length, maxFiles2Show); ++i) {
 50  0 System.out.println(files[i]);
 51    }
 52  0 System.out.println("...");
 53  0 int intervalSecs;
 54  0 try {
 55  0 intervalSecs = Integer.parseInt(interval);
 56    } catch (NumberFormatException nfe) {
 57  0 throw new NumberFormatException("3rd argument must be an integer number of seconds ");
 58    }
 59  0 System.out.println("Ctrl-C when you're bored");
 60  0 final ConsoleListener listener = new ConsoleListener();
 61  0 final FileEvent[] interestingEvents =
 62    {
 63    FileEvent.CREATED,
 64    FileEvent.DELETED,
 65    FileEvent.GONE_STALE,
 66    FileEvent.UPDATED };
 67  0 final Listener filter =
 68    new EventFilterListener(
 69    listener,
 70    interestingEvents,
 71    EventFilterListener.FilterType.INCLUDED);
 72  0 final int pollFrequency = 10; //in seconds
 73  0 final FileStateMonitor mon =
 74    new FileStateMonitor(filter, pollFrequency);
 75  0 mon.addFiles(files);
 76  0 mon.setStaleInterval(intervalSecs);
 77  0 mon.start();
 78  0 Thread.sleep(24 * 60 * 60 * 1000); //wait forever, well a day anyway
 79    }
 80    /**
 81    *
 82    */
 83  0 private static void giveHelp() {
 84  0 System.out.println(
 85    "Usage:\n java -jar your_uber_jar_here.jar staleInt file1 file2 ...");
 86  0 System.out.println("where:");
 87  0 System.out.println(
 88    "staleInt is the time in seconds before a file is considered stale");
 89  0 System.out.println(
 90    "file1 etc are the files you want to watch (can use wildcard expressions in Windows and maybe unix");
 91    }
 92    }
 93    /*
 94    * $Log: FileChangeConsoleAlerter.java,v $
 95    * Revision 1.1 2004/04/27 10:57:51 johndavidtaylor
 96    * changed package name
 97    *
 98    * Revision 1.1 2004/03/17 21:16:51 johndavidtaylor
 99    * Copied across from incubation in beanpeeler
 100    *
 101    * Revision 1.3 2004/03/11 15:46:34 johndavidtaylor
 102    * Applied coding standards
 103    * Revision 1.2 2004/03/11 11:33:46
 104    * johndavidtaylor Refactored the way that the PollingMonitor worked.
 105    * Previously it got started in its ctor, but this allowed access to subclass
 106    * resources that hadn't yet been initialised. Bad. Now needs to be started
 107    * explicitly post-construction.
 108    *
 109    * Revision 1.1 2004/03/11 09:49:22 johndavidtaylor Loads of updates
 110    *
 111    *
 112    */