FileDocCategorySizeDatePackage
WarWatcher.javaAPI DocApache Tomcat 6.0.146947Fri Jul 20 04:20:32 BST 2007org.apache.catalina.ha.deploy

WarWatcher

public class WarWatcher extends Object

The WarWatcher watches the deployDir for changes made to the directory (adding new WAR files->deploy or remove WAR files->undeploy) And notifies a listener of the changes made

author
Filip Hanik
author
Peter Rossbach
version
1.1

Fields Summary
public static org.apache.juli.logging.Log
log
protected File
watchDir
Directory to watch for war files
protected FileChangeListener
listener
Parent to be notified of changes
protected Map
currentStatus
Currently deployed files
Constructors Summary
public WarWatcher()


    /*--Constructor---------------------------------------------*/

      
    
public WarWatcher(FileChangeListener listener, File watchDir)

        this.listener = listener;
        this.watchDir = watchDir;
    
Methods Summary
protected voidaddWarInfo(java.io.File warfile)
add cluster war to the watcher state

param
warfile

        WarInfo info = (WarInfo) currentStatus.get(warfile.getAbsolutePath());
        if (info == null) {
            info = new WarInfo(warfile);
            info.setLastState(-1); //assume file is non existent
            currentStatus.put(warfile.getAbsolutePath(), info);
        }
    
public voidcheck()
check for modification and send notifcation to listener

        if (log.isInfoEnabled())
            log.info("check cluster wars at " + watchDir);
        File[] list = watchDir.listFiles(new WarFilter());
        if (list == null)
            list = new File[0];
        //first make sure all the files are listed in our current status
        for (int i = 0; i < list.length; i++) {
            addWarInfo(list[i]);
        }

        //check all the status codes and update the FarmDeployer
        for (Iterator i = currentStatus.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();
            WarInfo info = (WarInfo) entry.getValue();
            int check = info.check();
            if (check == 1) {
                listener.fileModified(info.getWar());
            } else if (check == -1) {
                listener.fileRemoved(info.getWar());
                //no need to keep in memory
                currentStatus.remove(info.getWar());
            }
        }

    
public voidclear()
clear watcher state

        currentStatus.clear();
    
public FileChangeListenergetListener()

return
Returns the listener.

        return listener;
    
public java.io.FilegetWatchDir()

return
Returns the watchDir.

        return watchDir;
    
public voidsetListener(FileChangeListener listener)

param
listener The listener to set.

        this.listener = listener;
    
public voidsetWatchDir(java.io.File watchDir)

param
watchDir The watchDir to set.

        this.watchDir = watchDir;