use of org.apereo.cas.support.events.config.CasConfigurationCreatedEvent in project cas by apereo.
the class ConfigurationDirectoryPathWatchService method watch.
/**
* Watch the directory for changes.
*/
public void watch() {
long lastModified = System.currentTimeMillis();
while (true) {
final WatchKey key;
try {
key = watcher.take();
} catch (final InterruptedException e) {
LOGGER.warn(e.getMessage(), e);
return;
}
for (final WatchEvent<?> event : key.pollEvents()) {
final WatchEvent.Kind<?> kind = event.kind();
if (kind == OVERFLOW) {
LOGGER.warn("An overflow event occurred. File system events may be lost or discarded.");
continue;
}
final WatchEvent<Path> ev = (WatchEvent<Path>) event;
final Path filename = ev.context();
try {
final Path child = this.directory.resolve(filename);
if (System.currentTimeMillis() - lastModified >= MONITOR_INTERVAL) {
LOGGER.debug("Detected configuration change [{}]", kind.name());
if (StringUtils.equalsIgnoreCase(StandardWatchEventKinds.ENTRY_CREATE.name(), kind.name())) {
this.eventPublisher.publishEvent(new CasConfigurationCreatedEvent(this, child));
}
if (StringUtils.equalsIgnoreCase(StandardWatchEventKinds.ENTRY_DELETE.name(), kind.name())) {
this.eventPublisher.publishEvent(new CasConfigurationDeletedEvent(this, child));
}
if (StringUtils.equalsIgnoreCase(StandardWatchEventKinds.ENTRY_MODIFY.name(), kind.name())) {
this.eventPublisher.publishEvent(new CasConfigurationModifiedEvent(this, child));
}
lastModified = System.currentTimeMillis();
}
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
continue;
}
}
final boolean valid = key.reset();
if (!valid) {
break;
}
}
}
Aggregations