Skip to content

Commit 982ce65

Browse files
committed
Make sure to have a dedicated interface, to allow for future additions without breaking binary compatibility
1 parent d392f1c commit 982ce65

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package engineering.swat.watch;
2+
3+
import java.io.Closeable;
4+
5+
/**
6+
* <p>Marker interface for an active watch, in the future might get properties you can inspect.</p>
7+
*
8+
* <p>For now, make sure to close the watch when not interested in new events</p>
9+
*/
10+
public interface ActiveWatch extends Closeable {
11+
12+
}

src/main/java/engineering/swat/watch/Watcher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package engineering.swat.watch;
22

3-
import java.io.Closeable;
43
import java.io.IOException;
54
import java.nio.file.Files;
65
import java.nio.file.LinkOption;
@@ -96,7 +95,7 @@ public Watcher withExecutor(Executor callbackHandler) {
9695
* @throws IOException in case the starting of the watcher caused an underlying IO exception
9796
* @throws IllegalStateException the watchers is not configured correctly (for example, missing {@link #onEvent(Consumer)}, or a watcher is started twice)
9897
*/
99-
public Closeable start() throws IOException {
98+
public ActiveWatch start() throws IOException {
10099
if (this.eventHandler == NULL_HANDLER) {
101100
throw new IllegalStateException("There is no onEvent handler defined");
102101
}

src/main/java/engineering/swat/watch/impl/jdk/JDKDirectoryWatcher.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package engineering.swat.watch.impl;
1+
package engineering.swat.watch.impl.jdk;
22

33
import java.io.Closeable;
44
import java.io.IOException;
@@ -13,9 +13,12 @@
1313
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
1414
import org.checkerframework.checker.nullness.qual.Nullable;
1515

16+
import engineering.swat.watch.ActiveWatch;
1617
import engineering.swat.watch.WatchEvent;
18+
import engineering.swat.watch.impl.util.BundledSubscription;
19+
import engineering.swat.watch.impl.util.SubscriptionKey;
1720

18-
public class JDKDirectoryWatcher implements Closeable {
21+
public class JDKDirectoryWatcher implements ActiveWatch {
1922
private final Logger logger = LogManager.getLogger();
2023
private final Path directory;
2124
private final Executor exec;
@@ -95,7 +98,7 @@ else if (ev.kind() == StandardWatchEventKinds.OVERFLOW) {
9598
@Override
9699
public synchronized void close() throws IOException {
97100
if (activeWatch != null) {
98-
logger.debug("Closing watch for: {}", this.directory);
101+
logger.trace("Closing watch for: {}", this.directory);
99102
activeWatch.close();
100103
}
101104
}

src/main/java/engineering/swat/watch/impl/jdk/JDKFileWatcher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package engineering.swat.watch.impl;
1+
package engineering.swat.watch.impl.jdk;
22

33
import java.io.Closeable;
44
import java.io.IOException;
@@ -10,14 +10,15 @@
1010
import org.apache.logging.log4j.Logger;
1111
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
1212

13+
import engineering.swat.watch.ActiveWatch;
1314
import engineering.swat.watch.WatchEvent;
1415

1516
/**
1617
* It's not possible to monitor a single file (or directory), so we have to find a directory watcher, and connect to that
1718
*
1819
* Note that you should take care to call start only once.
1920
*/
20-
public class JDKFileWatcher implements Closeable {
21+
public class JDKFileWatcher implements ActiveWatch {
2122
private final Logger logger = LogManager.getLogger();
2223
private final Path file;
2324
private final Path fileName;

src/main/java/engineering/swat/watch/impl/jdk/JDKRecursiveDirectoryWatcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import org.apache.logging.log4j.LogManager;
2323
import org.apache.logging.log4j.Logger;
2424

25+
import engineering.swat.watch.ActiveWatch;
2526
import engineering.swat.watch.WatchEvent;
2627

27-
public class JDKRecursiveDirectoryWatcher implements Closeable {
28+
public class JDKRecursiveDirectoryWatcher implements ActiveWatch {
2829
private final Logger logger = LogManager.getLogger();
2930
private final Path root;
3031
private final Executor exec;

0 commit comments

Comments
 (0)