Skip to content

Commit fee22fd

Browse files
committed
Rename in JDKBaseWatch: (a) start to open; (b) run to start
1 parent 5cf298c commit fee22fd

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.logging.log4j.LogManager;
3838
import org.apache.logging.log4j.Logger;
3939

40-
import engineering.swat.watch.impl.jdk.JDKBaseWatch;
4140
import engineering.swat.watch.impl.jdk.JDKDirectoryWatch;
4241
import engineering.swat.watch.impl.jdk.JDKFileWatch;
4342
import engineering.swat.watch.impl.jdk.JDKRecursiveDirectoryWatch;
@@ -161,26 +160,26 @@ public ActiveWatch start() throws IOException {
161160
switch (scope) {
162161
case PATH_AND_CHILDREN: {
163162
var result = new JDKDirectoryWatch(path, executor, eventHandler, false);
164-
result.start();
163+
result.open();
165164
return result;
166165
}
167166
case PATH_AND_ALL_DESCENDANTS: {
168167
try {
169168
var result = new JDKDirectoryWatch(path, executor, eventHandler, true);
170-
result.start();
169+
result.open();
171170
return result;
172171
} catch (Throwable ex) {
173172
// no native support, use the simulation
174173
logger.debug("Not possible to register the native watcher, using fallback for {}", path);
175174
logger.trace(ex);
176175
var result = new JDKRecursiveDirectoryWatch(path, executor, eventHandler);
177-
result.start();
176+
result.open();
178177
return result;
179178
}
180179
}
181180
case PATH_ONLY: {
182181
var result = new JDKFileWatch(path, executor, eventHandler);
183-
result.start();
182+
result.open();
184183
return result;
185184
}
186185
default:

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ public abstract class JDKBaseWatch implements ActiveWatch {
4646
protected final Path path;
4747
protected final Executor exec;
4848
protected final Consumer<WatchEvent> eventHandler;
49-
protected final AtomicBoolean running = new AtomicBoolean();
49+
protected final AtomicBoolean started = new AtomicBoolean();
5050

5151
protected JDKBaseWatch(Path path, Executor exec, Consumer<WatchEvent> eventHandler) {
5252
this.path = path;
5353
this.exec = exec;
5454
this.eventHandler = eventHandler;
5555
}
5656

57-
public void start() throws IOException {
57+
public void open() throws IOException {
5858
try {
59-
if (!runIfFirstTime()) {
59+
if (!startIfFirstTime()) {
6060
throw new IllegalStateException("Could not restart already-started watch for: " + path);
6161
}
6262
logger.debug("Started watch for: {}", path);
@@ -66,23 +66,23 @@ public void start() throws IOException {
6666
}
6767

6868
/**
69-
* Runs this watch.
69+
* Starts this watch.
7070
*
7171
* @throws IOException When an I/O exception of some sort has occurred
7272
* (e.g., a nested watch failed to start)
7373
*/
74-
protected abstract void run() throws IOException;
74+
protected abstract void start() throws IOException;
7575

7676
/**
77-
* Runs this watch if it's the first time.
77+
* Starts this watch if it's the first time.
7878
*
7979
* @return `true` iff it's the first time this method is called
8080
* @throws IOException When an I/O exception of some sort has occurred
8181
* (e.g., a nested watch failed to start)
8282
*/
83-
protected boolean runIfFirstTime() throws IOException {
84-
if (running.compareAndSet(false, true)) {
85-
run();
83+
protected boolean startIfFirstTime() throws IOException {
84+
if (started.compareAndSet(false, true)) {
85+
start();
8686
return true;
8787
} else {
8888
return false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public synchronized void close() throws IOException {
8282
}
8383

8484
@Override
85-
protected synchronized void run() throws IOException {
85+
protected synchronized void start() throws IOException {
8686
assert bundledJDKWatcher == null;
8787
var key = new SubscriptionKey(path, nativeRecursive);
8888
bundledJDKWatcher = BUNDLED_JDK_WATCHERS.subscribe(key, this::handleChanges);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public synchronized void close() throws IOException {
8181
}
8282

8383
@Override
84-
protected synchronized void run() throws IOException {
84+
protected synchronized void start() throws IOException {
8585
assert parentWatch == null;
8686
parentWatch = new JDKDirectoryWatch(parent, exec, this::filter);
87-
parentWatch.start();
87+
parentWatch.open();
8888
logger.debug("File watch (for: {}) is in reality a directory watch (for: {}) with a filter (for: {})", path, parent, fileName);
8989
}
9090
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public FileVisitResult postVisitDirectory(Path subdir, IOException exc) throws I
150150
private void addNewDirectory(Path dir) throws IOException {
151151
var watch = activeWatches.computeIfAbsent(dir, d -> new JDKDirectoryWatch(d, exec, relocater(dir)));
152152
try {
153-
if (!watch.runIfFirstTime()) {
153+
if (!watch.startIfFirstTime()) {
154154
logger.debug("We lost the race on starting a nested watch, that shouldn't be a problem, but it's a very busy, so we might have lost a few events in {}", dir);
155155
}
156156
} catch (IOException ex) {
@@ -324,7 +324,7 @@ public void close() throws IOException {
324324
}
325325

326326
@Override
327-
protected void run() throws IOException {
327+
protected void start() throws IOException {
328328
logger.debug("Running recursive watch for: {}", path);
329329
registerInitialWatches(path);
330330
}

0 commit comments

Comments
 (0)