in data-orchestrator/data-orchestrator-clients/directory-monitor/src/main/java/org/apache/airavata/datalake/dmonitor/SaturationGauge.java [40:88]
public void start(EventNotifier eventNotifier) {
scheduledExecutorService.scheduleWithFixedDelay(() -> {
List<Future<Boolean>> submitFutures = new ArrayList<>();
for (String key : directorySizes.keySet()) {
Future<Boolean> submitFuture = monitoringService.submit(() -> {
monitorCount.put(key, monitorCount.get(key) + 1);
try {
long oldSize = directorySizes.get(key);
long newSize = getFolderSize(new File(key));
directorySizes.put(key, newSize);
logger.info("Directory : " + key + " Size : " + newSize + " Scan count : " + monitorCount.get(key));
if (oldSize == newSize && monitorCount.get(key) > saturationCount) {
logger.info("Directory " + key + " is saturated. Final size " + oldSize);
monitorCount.remove(key);
directorySizes.remove(key);
eventNotifier.notify(key);
}
if (oldSize != newSize) {
monitorCount.put(key, 0);
}
return true;
} catch (Exception e) {
e.printStackTrace();
if (monitorCount.get(key) > 3) {
monitorCount.remove(key);
directorySizes.remove(key);
}
return false;
}
});
submitFutures.add(submitFuture);
}
for (Future<Boolean> submitFuture: submitFutures) {
try {
submitFuture.get();
} catch (Exception e) {
e.printStackTrace();
}
}
logger.debug("All monitor threads were completed");
}, 1, 20, TimeUnit.SECONDS);
}