Search in sources :

Example 1 with CasConfigurationCreatedEvent

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;
        }
    }
}
Also used : Path(java.nio.file.Path) CasConfigurationCreatedEvent(org.apereo.cas.support.events.config.CasConfigurationCreatedEvent) WatchKey(java.nio.file.WatchKey) CasConfigurationModifiedEvent(org.apereo.cas.support.events.config.CasConfigurationModifiedEvent) WatchEvent(java.nio.file.WatchEvent) CasConfigurationDeletedEvent(org.apereo.cas.support.events.config.CasConfigurationDeletedEvent)

Aggregations

Path (java.nio.file.Path)1 WatchEvent (java.nio.file.WatchEvent)1 WatchKey (java.nio.file.WatchKey)1 CasConfigurationCreatedEvent (org.apereo.cas.support.events.config.CasConfigurationCreatedEvent)1 CasConfigurationDeletedEvent (org.apereo.cas.support.events.config.CasConfigurationDeletedEvent)1 CasConfigurationModifiedEvent (org.apereo.cas.support.events.config.CasConfigurationModifiedEvent)1