-
Notifications
You must be signed in to change notification settings - Fork 0
Improved overflow support: Overflow auto-handling for directory watches (non-recursive) #24
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
sungshik
merged 19 commits into
improved-overflow-support-main
from
improved-overflow-support/first-overflow-policy
Mar 7, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
04bfe11
Add `getScope` method to `ActiveWatch` interface
sungshik bcfa0dd
Add `getScope` method to `ActiveWatch` interface
sungshik c8ed7a8
Add `OverflowPolicy` enum to configure how overflow events should be …
sungshik 89e1b5f
Add overflow policy to watcher constructor
sungshik 2ff52a7
Add license
sungshik 15f8313
Add implementation of the `MEMORYLESS_RESCANS` overflow policy
sungshik bab08c0
Add auto-handling using the `MEMORYLESS_RESCANS` overflow policy to (…
sungshik a28ac94
Add function to ignore overflow events in the user-defined event hand…
sungshik 8d59be4
Fix comment
sungshik df81ecb
Improve test
sungshik 5d6e32f
Move configuration of overflow policy to separate method
sungshik ac2e212
Remove auto-gobbling of overflow events for all overflow policies
sungshik ec79d61
Update test
sungshik 96f4f5b
Use `walkFileTree` instead of `walk` to avoid redundant retrieval of …
sungshik 67ca923
Update test
sungshik 9744874
Fix test
sungshik 4beb950
Fix issue that `MODIFIED` events were issued for directories when aut…
sungshik f7a7a34
Rename overflow auto-handling approach constants
sungshik 9e71ad7
Switch order of overflow auto-handler and user-defined event handler
sungshik 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * BSD 2-Clause License | ||
| * | ||
| * Copyright (c) 2023, Swat.engineering | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * | ||
| * 1. Redistributions of source code must retain the above copyright notice, this | ||
| * list of conditions and the following disclaimer. | ||
| * | ||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| * this list of conditions and the following disclaimer in the documentation | ||
| * and/or other materials provided with the distribution. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package engineering.swat.watch; | ||
|
|
||
| /** | ||
| * Constants to indicate for which regular files/directories in the scope of the | ||
| * watch an <i>approximation</i> of synthetic events (of kinds | ||
| * {@link WatchEvent.Kind#CREATED}, {@link WatchEvent.Kind#MODIFIED}, and/or | ||
| * {@link WatchEvent.Kind#DELETED}) should be issued when an overflow event | ||
| * happens. These synthetic events, as well as the overflow event itself, are | ||
| * subsequently passed to the user-defined event handler of the watch. | ||
| * Typically, the user-defined event handler can ignore the original overflow | ||
| * event (i.e., handling the synthetic events is sufficient to address the | ||
| * overflow issue), but it doesn't have to (e.g., it may carry out additional | ||
| * overflow bookkeeping). | ||
| */ | ||
| public enum OnOverflow { | ||
|
|
||
| /** | ||
| * Synthetic events are issued for <b>no regular files/directories</b> in | ||
| * the scope of the watch. Thus, the user-defined event handler is fully | ||
| * responsible to handle overflow events. | ||
| */ | ||
| NONE, | ||
|
|
||
| /** | ||
| * <p> | ||
| * Synthetic events of kinds {@link WatchEvent.Kind#CREATED} and | ||
| * {@link WatchEvent.Kind#MODIFIED}, but not | ||
| * {@link WatchEvent.Kind#DELETED}, are issued for all regular | ||
| * files/directories in the scope of the watch. Specifically, when an | ||
| * overflow event happens: | ||
| * | ||
| * <ul> | ||
| * <li>CREATED events are issued for all regular files/directories | ||
| * (overapproximation). | ||
| * <li>MODIFIED events are issued for all non-empty, regular files | ||
| * (overapproximation) but for no directories (underapproximation). | ||
| * <li>DELETED events are issued for no regular files/directories | ||
| * (underapproximation). | ||
| * </ul> | ||
| * | ||
| * <p> | ||
| * This approach is relatively cheap in terms of memory usage (cf. | ||
| * {@link #DIRTY}), but it results in a large over/underapproximation of the | ||
| * actual events (cf. DIRTY). | ||
| */ | ||
| ALL, | ||
|
|
||
|
|
||
| /** | ||
| * <p> | ||
| * Synthetic events of kinds {@link WatchEvent.Kind#CREATED}, | ||
| * {@link WatchEvent.Kind#MODIFIED}, and {@link WatchEvent.Kind#DELETED} are | ||
| * issued for dirty regular files/directories in the scope of the watch, as | ||
| * determined using <i>last-modified-times</i>. Specifically, when an | ||
| * overflow event happens: | ||
| * | ||
| * <ul> | ||
| * <li>CREATED events are issued for all regular files/directories when the | ||
| * previous last-modified-time is unknown, but the current | ||
| * last-modified-time is known (i.e., the file started existing). | ||
| * <li>MODIFIED events are issued for all regular files/directories when the | ||
| * previous last-modified-time is before the current last-modified-time. | ||
| * <li>DELETED events are issued for all regular files/directories when the | ||
| * previous last-modified-time is known, but the current | ||
| * last-modified-time is unknown (i.e., the file stopped existing). | ||
| * </ul> | ||
| * | ||
| * <p> | ||
| * To keep track of last-modified-times, an internal <i>index</i> is | ||
| * populated with last-modified-times of all regular files/directories in | ||
| * the scope of the watch when the watch is started. Each time when any | ||
| * event happens, the index is updated accordingly, so when an overflow | ||
| * event happens, last-modified-times can be compared as described above. | ||
| * | ||
| * <p> | ||
| * This approach results in a small overapproximation (cf. {@link #ALL}), | ||
| * but it is relatively expensive in terms of memory usage (cf. ALL), as the | ||
| * watch needs to keep track of last-modified-times. | ||
| */ | ||
| DIRTY | ||
| } |
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
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.