in core/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java [627:679]
private void monitorDirectory(final File root, final Map<String, ArchiveEntry> fileMap) {
/*
* if (LOGGER.isTraceEnabled()) { if (root != null) LOGGER.trace("Monitoring
* directory " + root.getAbsolutePath() + " for new or modified
* archives"); else LOGGER.trace("No directory to monitor for new or
* modified archives for " + ((fileMap==installFileMap) ? "Installation" :
* "Deployment") + "."); }
*/
List<String> tmpList = new ArrayList<String>();
if (root != null && root.exists() && root.isDirectory()) {
File[] files = root.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
final File file = files[i];
tmpList.add(file.getName());
if (isAllowedExtension(file.getName()) && isAvailable(file)) {
ArchiveEntry lastEntry = fileMap.get(file.getName());
if (lastEntry == null || file.lastModified() > lastEntry.lastModified.getTime()) {
try {
final ArchiveEntry entry = new ArchiveEntry();
entry.location = file.getName();
entry.lastModified = new Date(file.lastModified());
fileMap.put(file.getName(), entry);
LOGGER.info("Directory: {}: Archive changed: processing {}...", root.getName(), file.getName());
updateArchive(file.getAbsolutePath(), entry, true);
LOGGER.info("Directory: {}: Finished installation of archive: {}", root.getName(), file.getName());
} catch (Exception e) {
LOGGER.warn("Directory: " + root.getName() + ": Automatic install of " + file + " failed", e);
} finally {
persistState(root, fileMap);
}
}
}
}
}
// now remove any locations no longer here
Map<String, ArchiveEntry> map = new HashMap<String, ArchiveEntry>(fileMap);
for (String location : map.keySet()) {
if (!tmpList.contains(location)) {
ArchiveEntry entry = fileMap.remove(location);
try {
LOGGER.info("Location {} no longer exists - removing ...", location);
removeArchive(entry);
} catch (DeploymentException e) {
LOGGER.error("Failed to removeArchive: {}", location, e);
}
}
}
if (!map.equals(fileMap)) {
persistState(root, fileMap);
}
}
}