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);
}