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

Commit

Permalink
AutomationWatchService uses relative path.
Browse files Browse the repository at this point in the history
Adapting the code of AutomationWatchService to use relative path.
This change was necessary after #2342 was merged.

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
  • Loading branch information
Svilen Valkanov committed Nov 29, 2016
1 parent 4a489f8 commit 55c5606
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
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.Map;

import org.eclipse.smarthome.core.service.AbstractWatchQueueReader;
import org.eclipse.smarthome.core.service.AbstractWatchService;
Expand Down Expand Up @@ -49,8 +51,9 @@ protected String getSourcePath() {
}

@Override
protected AbstractWatchQueueReader buildWatchQueueReader(WatchService watchService, Path toWatch) {
return new WatchQueueReader(watchService, toWatch, provider);
protected AbstractWatchQueueReader buildWatchQueueReader(WatchService watchService, Path toWatch,
Map<WatchKey, Path> registredWatchKeys) {
return new WatchQueueReader(watchService, toWatch, provider, registredWatchKeys);
}

@Override
Expand All @@ -59,26 +62,29 @@ protected boolean watchSubDirectories() {
}

@Override
protected void registerDirectory(Path subDir) throws IOException {
subDir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
protected WatchKey registerDirectory(Path subDir) throws IOException {
return subDir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
}

private static class WatchQueueReader extends AbstractWatchQueueReader {

private AbstractFileProvider provider;

WatchQueueReader(WatchService watchService, Path dirToWatch, AbstractFileProvider provider) {
super(watchService, dirToWatch);
WatchQueueReader(WatchService watchService, Path dirToWatch, AbstractFileProvider provider,
Map<WatchKey, Path> registredWatchKeys) {
super(watchService, dirToWatch, registredWatchKeys);
this.provider = provider;
}

@Override
protected void processWatchEvent(WatchEvent<?> event, Kind<?> kind, Path path) {
if (!path.getFileName().startsWith(".")) {
if (kind.equals(ENTRY_DELETE)) {
provider.removeResources(new File(this.dir + File.separator + path.toString()));
provider.removeResources(
new File(baseWatchedDir.toAbsolutePath() + File.separator + path.toString()));
} else {
provider.importResources(new File(this.dir + File.separator + path.toString()));
provider.importResources(
new File(baseWatchedDir.toAbsolutePath() + File.separator + path.toString()));
}
}
}
Expand Down

0 comments on commit 55c5606

Please sign in to comment.