* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.config.loader.impl;
+package org.opendaylight.bgpcep.config.loader.impl;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.OVERFLOW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class BGPFileWatcher implements FileWatcher, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(BGPFileWatcher.class);
+public final class FileWatcherImpl implements FileWatcher, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(FileWatcherImpl.class);
private static final String INTERRUPTED = "InterruptedException";
private static final String BGPCEP_CONFIG_FOLDER = "bgpcep";
private static final String DEFAULT_APP_CONFIG_FILE_PATH = "etc" + File.separator + "opendaylight"
private static final Path PATH = Paths.get(DEFAULT_APP_CONFIG_FILE_PATH);
private final WatchService watchService;
- public BGPFileWatcher() throws IOException {
+ public FileWatcherImpl() throws IOException {
+ this.watchService = FileSystems.getDefault().newWatchService();
final File file = new File(DEFAULT_APP_CONFIG_FILE_PATH);
if (!file.exists()) {
- file.mkdirs();
+ if (file.mkdirs()) {
+ return;
+ }
}
- this.watchService = FileSystems.getDefault().newWatchService();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
- BGPFileWatcher.this.watchService.close();
+ FileWatcherImpl.this.watchService.close();
} catch (final IOException e) {
LOG.warn(INTERRUPTED, e);
}
}));
PATH.register(this.watchService, OVERFLOW, ENTRY_CREATE);
+ LOG.info("File Watcher service initiated");
}
@Override
}
@Override
- public WatchService getWatchService() {
+ public synchronized WatchService getWatchService() {
return this.watchService;
}