20: More refresher logic
This commit is contained in:
+44
-5
@@ -1,7 +1,13 @@
|
|||||||
package com.r35157.jupiterperpsalarm.impl.ref;
|
package com.r35157.jupiterperpsalarm.impl.ref;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.StandardWatchEventKinds;
|
||||||
|
import java.nio.file.WatchEvent;
|
||||||
|
import java.nio.file.WatchKey;
|
||||||
|
import java.nio.file.WatchService;
|
||||||
|
|
||||||
public final class JupiterPerpsEntryPriceVariableRefreshWatcher {
|
public final class JupiterPerpsEntryPriceVariableRefreshWatcher {
|
||||||
|
|
||||||
@@ -24,10 +30,43 @@ public final class JupiterPerpsEntryPriceVariableRefreshWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void run() {
|
private void run() {
|
||||||
System.out.println(
|
try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
|
||||||
"Jupiter Perps entry price variable refresh watcher started for directory: "
|
|
||||||
+ confDirectory
|
confDirectory.register(
|
||||||
);
|
watchService,
|
||||||
|
StandardWatchEventKinds.ENTRY_CREATE
|
||||||
|
);
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Jupiter Perps entry price variable refresh watcher started for directory: "
|
||||||
|
+ confDirectory
|
||||||
|
);
|
||||||
|
while (true) {
|
||||||
|
WatchKey key = watchService.take();
|
||||||
|
|
||||||
|
for (WatchEvent<?> event : key.pollEvents()) {
|
||||||
|
System.out.println("WatchService event: " + event.context());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!key.reset()) {
|
||||||
|
System.err.println(
|
||||||
|
"Jupiter Perps entry price variable refresh watcher stopped: watch key is no longer valid"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException exception) {
|
||||||
|
System.err.println(
|
||||||
|
"Could not start Jupiter Perps entry price variable refresh watcher: "
|
||||||
|
+ exception.getMessage()
|
||||||
|
);
|
||||||
|
} catch (InterruptedException exception) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
|
||||||
|
System.err.println(
|
||||||
|
"Jupiter Perps entry price variable refresh watcher interrupted"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String REFRESH_TRIGGER_FILE_NAME =
|
private static final String REFRESH_TRIGGER_FILE_NAME =
|
||||||
|
|||||||
Reference in New Issue
Block a user