-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from goblint/server-recovery
Recover Goblint server automatically after crashing
- Loading branch information
Showing
7 changed files
with
144 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package api.util; | ||
|
||
import io.methvin.watcher.DirectoryWatcher; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class DirectoryWatchingUtility { | ||
|
||
private final DirectoryWatcher watcher; | ||
|
||
public DirectoryWatchingUtility(Path directoryToWatch) throws IOException { | ||
this.watcher = DirectoryWatcher.builder() | ||
.path(directoryToWatch) // or use paths(directoriesToWatch) | ||
.listener(event -> { | ||
switch (event.eventType()) { | ||
case CREATE: | ||
/* file created */ | ||
stopWatching(); | ||
return; | ||
case MODIFY: | ||
/* file modified */ | ||
break; | ||
case DELETE: | ||
/* file deleted */ | ||
break; | ||
} | ||
}) | ||
// .fileHashing(false) // defaults to true | ||
// .logger(logger) // defaults to LoggerFactory.getLogger(DirectoryWatcher.class) | ||
// .watchService(watchService) // defaults based on OS to either JVM WatchService or the JNA macOS WatchService | ||
.build(); | ||
} | ||
|
||
public void stopWatching() throws IOException { | ||
watcher.close(); | ||
} | ||
|
||
public CompletableFuture<Void> watch() { | ||
// you can also use watcher.watch() to block the current thread | ||
return watcher.watchAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters