Repository navigation
Implement WatchService for changes made inside the VM #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
997f450
Implement VFS backed Linux watch service
Project516 310519f
Poll watch descriptors for readable events
Project516 bf2d6d9
Support separate watch service instances
Project516 a788e51
Invalidate watches when their directories are removed
Project516 a45d3ee
Resolve relative paths for inotify watches
Project516 26bbe6f
Enable passing OpenJDK WatchService tests
Project516 0f9bc5f
Merge remote-tracking branch 'origin/master' into p516/watch-service
Project516 40d3a64
Keep one close0 native and document what WatchService sees
Project516 063eb65
Name the supported inotify events apart from the IN_MASK_ADD flag
Project516 0f128c5
Report ENOTDIR for watches on files and bound the watch path read
Project516 a69b989
Keep queued inotify events on overflow, as Linux does
Project516 19183e3
Merge master into p516/watch-service
Project516 aaa1088
Report EFAULT for a watch path address outside VM memory
Project516 78bd09a
Cap the watch path read at PATH_MAX
Project516 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,35 @@ | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardWatchEventKinds; | ||
| import java.nio.file.WatchKey; | ||
| import java.util.TreeSet; | ||
|
|
||
| public class WatchService { | ||
| private static void collect(java.nio.file.WatchService watch, TreeSet<String> events) throws Exception { | ||
| WatchKey key; | ||
| while ((key = watch.poll()) != null) { | ||
| for (var event : key.pollEvents()) { | ||
| if (event.kind() != StandardWatchEventKinds.OVERFLOW) | ||
| events.add(event.kind().name() + " " + event.context()); | ||
| } | ||
| key.reset(); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| Path dir = Files.createTempDirectory(Path.of("."), "watch"); | ||
| Path file = dir.resolve("item"); | ||
| TreeSet<String> events = new TreeSet<>(); | ||
| try (java.nio.file.WatchService watch = dir.getFileSystem().newWatchService()) { | ||
| dir.register(watch, StandardWatchEventKinds.ENTRY_CREATE, | ||
| StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); | ||
| Files.writeString(file, "first"); | ||
| Files.writeString(file, "second"); | ||
| Files.delete(file); | ||
| Thread.sleep(100); | ||
| collect(watch, events); | ||
| } | ||
| for (String event : events) System.out.println(event); | ||
| Files.delete(dir); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.