From f86652df7da00572782f029d5463bd1f01dc4ab23d73b0d6ef4202d8c6845bc6 Mon Sep 17 00:00:00 2001 From: Minimons Date: Sun, 28 Jun 2026 18:30:58 +0200 Subject: [PATCH] 20: More refresher logic --- ...erpsEntryPriceVariableRefreshWatcher.tjava | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/tjava/com/r35157/jupiterperpsalarm/impl/ref/JupiterPerpsEntryPriceVariableRefreshWatcher.tjava b/src/main/tjava/com/r35157/jupiterperpsalarm/impl/ref/JupiterPerpsEntryPriceVariableRefreshWatcher.tjava index 8e5e0a5..355542a 100644 --- a/src/main/tjava/com/r35157/jupiterperpsalarm/impl/ref/JupiterPerpsEntryPriceVariableRefreshWatcher.tjava +++ b/src/main/tjava/com/r35157/jupiterperpsalarm/impl/ref/JupiterPerpsEntryPriceVariableRefreshWatcher.tjava @@ -1,7 +1,13 @@ package com.r35157.jupiterperpsalarm.impl.ref; -import java.nio.file.Path; +import java.nio.file.*; 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 { @@ -24,10 +30,43 @@ public final class JupiterPerpsEntryPriceVariableRefreshWatcher { } private void run() { - System.out.println( - "Jupiter Perps entry price variable refresh watcher started for directory: " - + confDirectory - ); + try (WatchService watchService = FileSystems.getDefault().newWatchService()) { + + 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 =