Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

2341-watch-service-relative-path #2432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.nio.file.Path;
import java.nio.file.WatchEvent;
import java.nio.file.WatchEvent.Kind;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -157,8 +158,9 @@ protected boolean watchSubDirectories() {
* (java.nio.file.Path)
*/
@Override
protected void registerDirectory(Path subDir) throws IOException {
subDir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
protected WatchKey registerDirectory(Path subDir) throws IOException {
WatchKey registrationKey = subDir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return registrationKey;
}

/*
Expand All @@ -169,8 +171,9 @@ protected void registerDirectory(Path subDir) throws IOException {
* (java.nio.file.WatchService, java.nio.file.Path)
*/
@Override
protected AbstractWatchQueueReader buildWatchQueueReader(WatchService watchService, Path toWatch) {
return new WatchQueueReader(watchService, toWatch);
protected AbstractWatchQueueReader buildWatchQueueReader(WatchService watchService, Path toWatch,
Map<WatchKey, Path> registredWatchKeys) {
return new WatchQueueReader(watchService, toWatch, registredWatchKeys);
}

private String getDefaultServiceConfigFile() {
Expand Down Expand Up @@ -315,15 +318,15 @@ private String[] parseLine(final String filePath, final String line) {

private class WatchQueueReader extends AbstractWatchQueueReader {

public WatchQueueReader(WatchService watchService, Path dir) {
super(watchService, dir);
public WatchQueueReader(WatchService watchService, Path dir, Map<WatchKey, Path> registeredKeys) {
super(watchService, dir, registeredKeys);
}

@Override
protected void processWatchEvent(WatchEvent<?> event, Kind<?> kind, Path path) {
if (kind == ENTRY_CREATE || kind == ENTRY_MODIFY) {
try {
processConfigFile(new File(dir.toAbsolutePath() + File.separator + path.toString()));
processConfigFile(new File(baseWatchedDir.toAbsolutePath() + File.separator + path.toString()));
} catch (IOException e) {
logger.warn("Could not process config file '{}': {}", path, e);
}
Expand Down
Loading