-
Notifications
You must be signed in to change notification settings - Fork 0
Improved overflow support: Scaffolding #18
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
Changes from all commits
c1d3622
27cad30
9fe5be0
f559c1c
a00cc9a
bead33e
6b92693
eab398f
ff91702
c365b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ on: | |
| pull_request: | ||
| branches: | ||
| - main | ||
| - improved-overflow-support-main | ||
|
|
||
| jobs: | ||
| test: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,6 @@ | |
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.checkerframework.checker.nullness.qual.MonotonicNonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| import engineering.swat.watch.WatchEvent; | ||
|
|
@@ -45,17 +44,23 @@ | |
| */ | ||
| public class JDKFileWatch extends JDKBaseWatch { | ||
| private final Logger logger = LogManager.getLogger(); | ||
| private final Path parent; | ||
| private final Path fileName; | ||
| private volatile @MonotonicNonNull JDKDirectoryWatch parentWatch; | ||
| private final JDKBaseWatch internal; | ||
sungshik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public JDKFileWatch(Path file, Executor exec, Consumer<WatchEvent> eventHandler) { | ||
| super(file, exec, eventHandler); | ||
|
|
||
| var message = "The root path is not a valid path for a file watch"; | ||
| this.parent = requireNonNull(path.getParent(), message); | ||
| this.fileName = requireNonNull(path.getFileName(), message); | ||
| assert !parent.equals(path); | ||
| var parent = requireNonNull(file.getParent(), message); | ||
| var fileName = requireNonNull(file.getFileName(), message); | ||
| assert !parent.equals(file); | ||
|
|
||
| this.internal = new JDKDirectoryWatch(parent, exec, e -> { | ||
| if (fileName.equals(e.getRelativePath())) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if an overflow happens for the whole directory, we would still need to deal with that event and mark this file as overflow? or is that bugfix happening later?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think this will/should be "magically" covered by one of the next PRs. But, we'll need a test to check this. I added a reminder for this to #12. |
||
| eventHandler.accept(e); | ||
| } | ||
| }); | ||
sungshik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.debug("File watch (for: {}) is in reality a directory watch (for: {}) with a filter (for: {})", file, parent, fileName); | ||
| } | ||
|
|
||
| private static Path requireNonNull(@Nullable Path p, String message) { | ||
|
|
@@ -65,26 +70,15 @@ private static Path requireNonNull(@Nullable Path p, String message) { | |
| return p; | ||
| } | ||
|
|
||
| private void filter(WatchEvent event) { | ||
| if (fileName.equals(event.getRelativePath())) { | ||
| eventHandler.accept(event); | ||
| } | ||
| } | ||
|
|
||
| // -- JDKBaseWatch -- | ||
|
|
||
| @Override | ||
| public synchronized void close() throws IOException { | ||
| if (parentWatch != null) { | ||
| parentWatch.close(); | ||
| } | ||
| internal.close(); | ||
| } | ||
|
|
||
| @Override | ||
| protected synchronized void start() throws IOException { | ||
| assert parentWatch == null; | ||
| parentWatch = new JDKDirectoryWatch(parent, exec, this::filter); | ||
| parentWatch.open(); | ||
| logger.debug("File watch (for: {}) is in reality a directory watch (for: {}) with a filter (for: {})", path, parent, fileName); | ||
| internal.open(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.