FileDocCategorySizeDatePackage
AutoDeployMonitor.javaAPI DocGlassfish v2 API7320Fri May 04 22:35:40 BST 2007com.sun.enterprise.server

AutoDeployMonitor

public class AutoDeployMonitor extends AbstractMonitor
Monitors the auto deploy directory for new archives.
atuthor
Nazrul Islam
since
JDK 1.4

Fields Summary
static Logger
_logger
logger for this auto deploy monitor
private static AutoDeployMonitor
_instance
singleton instance
private static ArchiveFilter
_archiveFilter
filter for the archives
private static final String
SUCCESS_EXT
suffix added to the archives when deployed successfully
private static final String
ERROR_EXT
suffix added to the archives when not deployed
Constructors Summary
private AutoDeployMonitor(long pollInterval)
Constructor - prohibits anyone from constructing this object.

param
pollInterval polling interval


                           
       
        super(pollInterval);
    
Methods Summary
static synchronized com.sun.enterprise.server.AutoDeployMonitorgetInstance(long pollInterval)
Returns the singleton instance. If the object was not created already, it uses the given polling interval.

param
pollInterval polling interval

        if (_instance == null) {
            _instance       = new AutoDeployMonitor(pollInterval);
            _archiveFilter  = new ArchiveFilter();
        }
        return _instance;
    
public voidrun()
Periodically monitors the auto deploy directory of a server. If any new archive is detected, this monitor makes a callback to the listener provided in the monitorable entry.

This method checks the file extension of the archives found under the auto deploy directory. If the file extensions are .ear, .jar, .war, or .rar, it makes a callback to the listener. It is assumed that after processing the callback the handler will rename the archive with proper extension. For example, for a successful deployment, foo.ear may be renamed to foo.ear.deployed.


        try {
            synchronized (_monitoredEntries) {
                Iterator iter = _monitoredEntries.iterator();
                MonitorableEntry entry = null;

                // should be only one entry encapsulating the auto deploy dir
                while (iter.hasNext()) {
                    entry                = (MonitorableEntry) iter.next();
                    File autoDeployDir   = entry.getMonitoredFile();

                    File[] archives = autoDeployDir.listFiles(_archiveFilter);

                    if ( (archives == null) || (archives.length == 0) ) {
                        // no new archive
                        return;
                    }

                    MonitorListener l = entry.getListener();

                    for (int i=0; i<archives.length; i++) {

                        _logger.log(Level.FINE,
                            "[AutoDeployMonitor] Found " + archives[i]);

                        boolean success = l.deploy(entry, archives[i]);
                        if (success) {
                            File successExt = 
                                new File(archives[i].getParentFile(),
                                         archives[i].getName()+SUCCESS_EXT);
                            archives[i].renameTo(successExt);
                        } else {
                            File errorExt = 
                                new File(archives[i].getParentFile(),
                                         archives[i].getName()+ERROR_EXT);
                            archives[i].renameTo(errorExt);
                        }
                    }
                }
            }
        } catch (Throwable t) { 
            // catches any uncaught exceptions thrown from the handlers
            _logger.log(Level.WARNING, "core.exception", t);
        }