jacquard 1.12.0 by The Web Engineering Factory and Toolworks

uk.co.weft.alert
Class FileWatcher

java.lang.Object
  extended byuk.co.weft.alert.Watcher
      extended byuk.co.weft.alert.AbstractFileWatcher
          extended byuk.co.weft.alert.FileWatcher
All Implemented Interfaces:
java.lang.Runnable

public class FileWatcher
extends AbstractFileWatcher

An agent which watches for changes to a file and sends alerts based on those events. This class is primarily an example of how to use Watcher, although it is of course useful in its own right.

This agent knows about the following tokens which can be uses as either command-line parameters or configuration file properties:

f, watchedfile
String: The name of the file to watch (no wildcards)

These are in addition to the tokens known by Watcher.

In the alert context, this agent sets the following tokens which can be used to substitute into the template:

changedat
String: the time the file being watched last changed
watchedfile
String: The name of the file being watched.

If you use it you will typically set up a config file such as this:

debug: true
period: 10
mail_from_address: watcher@your.domain
mail_to_address: you@your.domain
subject: Watched file has changed
template: /home/you/tmp/watcher/watcher.template
watchedfile: /home/you/tmp/foo
    

However you could achieve exactly the same result by using java uk.co.weft.alert.FileWatcher -a watcher@your.domain -f ~/tmp/foo -i 10 -r you@your.domain -s "Watched file has changed" -t ~/tmp/watcher/watcher.template

Since:
Jacquard 1.9 This revision: $Author: simon $
Version:
$Revision: 1.10.4.1 $
Author:
Simon Brooke

Nested Class Summary
 
Nested classes inherited from class uk.co.weft.alert.AbstractFileWatcher
AbstractFileWatcher.FileValues
 
Field Summary
static java.lang.String FILETOKEN
           
protected  long lastModified
          when it last changed
protected  long lastSize
          how big it was
static java.lang.String OBSERVEDVALUESTOKEN
           
protected  java.lang.String path
          the path to the file I watch
protected  java.io.File watched
          the file I watch
static java.lang.String WHENCHANGEDTOKEN
           
 
Fields inherited from class uk.co.weft.alert.Watcher
alerter, alerts, configuration, debug, DEBUGTOKEN, ERRORTOKEN, INTERVALTOKEN, name, NAMETOKEN, recipient, resourceBundleName, sender, subject, SUBJECTTOKEN, template, TEMPLATETOKEN, thread, tooManyErrors, TOOMANYERRORS, whinges, winks
 
Constructor Summary
FileWatcher()
           
 
Method Summary
protected  java.util.Vector check()
          perform a check to see whether the event I am watching for has occurred.
 void init(java.util.Map config)
          initialise me with this configuration
static void main(java.lang.String[] args)
           
 
Methods inherited from class uk.co.weft.alert.AbstractFileWatcher
mark, maybeEscapePath
 
Methods inherited from class uk.co.weft.alert.Watcher
coerceToUrl, getAlerts, getArgs, getName, getNextCheck, getResource, getResourceString, getState, getStringWithDefault, getWhinges, grs, grs, maybeCheck, reset, resetWhinges, run, sendAlert, start, stop, usage, whinge
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILETOKEN

public static final java.lang.String FILETOKEN
See Also:
Constant Field Values

WHENCHANGEDTOKEN

public static final java.lang.String WHENCHANGEDTOKEN
See Also:
Constant Field Values

OBSERVEDVALUESTOKEN

public static final java.lang.String OBSERVEDVALUESTOKEN
See Also:
Constant Field Values

path

protected java.lang.String path
the path to the file I watch


watched

protected java.io.File watched
the file I watch


lastModified

protected long lastModified
when it last changed


lastSize

protected long lastSize
how big it was

Constructor Detail

FileWatcher

public FileWatcher()
Method Detail

init

public void init(java.util.Map config)
          throws AlertingException
initialise me with this configuration

Overrides:
init in class AbstractFileWatcher
Throws:
AlertingException

check

protected java.util.Vector check()
                          throws java.lang.Exception
perform a check to see whether the event I am watching for has occurred.

Specified by:
check in class Watcher
Returns:
a vector of maps each one of which represents an alert which should be sent.
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

jacquard 1.12.0 by The Web Engineering Factory and Toolworks