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