Skip to content

INT-3989: Add FileReadingMessageSource.WatchServiceDirectoryScanner #1774

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

Closed
wants to merge 5 commits into from

Conversation

artembilan
Copy link
Member

JIRA: https://jira.spring.io/browse/INT-3989,
https://jira.spring.io/browse/INT-3990,
https://jira.spring.io/browse/INT-3988

  • Deprecate top-level WatchServiceDirectoryScanner because of inconsistency around Lifecycle and shared directory property
  • Copy/paste its logic into the FileReadingMessageSource.WatchServiceDirectoryScanner to hide that inconsistency, but still get a gain from the WatchService benefits
  • Add support for the StandardWatchEventKinds.ENTRY_MODIFY and StandardWatchEventKinds.ENTRY_DELETE events in the FileReadingMessageSource.WatchServiceDirectoryScanner
  • Introduce useWatchService option to switch to the internal FileReadingMessageSource.WatchServiceDirectoryScanner
  • Make CompositeFileListFilter also as ResettableFileListFilter
  • Deprecate weird FileReadingMessageSource.onSend() method and remove its usage from tests
  • Modify WatchServiceDirectoryScannerTests for the new logic
  • Document changes

@artembilan
Copy link
Member Author

Pushed some optimization and testing.

@artembilan
Copy link
Member Author

Pushed the watch-events support.

*/
public void setWatchEvents(WatchEventType... watchEvents) {
Assert.notEmpty(watchEvents, "'watchEvents' must not be empty.");
this.watchEvents = watchEvents;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrays.copyOf(watchEvents, watchEvents.length)

@artembilan
Copy link
Member Author

Pushed.

consider add + remove between polls

See commit comments.

else {
files.remove(file);
files.add(file);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a debug log here "File removed since watch event received".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! 👍

JIRA: https://jira.spring.io/browse/INT-3989,
https://jira.spring.io/browse/INT-3990,
https://jira.spring.io/browse/INT-3988

* Deprecate top-level `WatchServiceDirectoryScanner` because of inconsistency around `Lifecycle` and shared `directory` property
* Copy/paste its logic into the `FileReadingMessageSource.WatchServiceDirectoryScanner` to hide that inconsistency, but still get a gain from the `WatchService` benefits
* Add support for the `StandardWatchEventKinds.ENTRY_MODIFY` and `StandardWatchEventKinds.ENTRY_DELETE` events in the `FileReadingMessageSource.WatchServiceDirectoryScanner`
* Introduce `useWatchService` option to switch to the internal `FileReadingMessageSource.WatchServiceDirectoryScanner`
* Make `CompositeFileListFilter` also as `ResettableFileListFilter`
* Deprecate weird `FileReadingMessageSource.onSend()` method and remove its usage from tests
* Modify `WatchServiceDirectoryScannerTests` for the new logic
* Document changes
Optimize the `filesFromEvents()` logic replacing item with the fresh event sources.
Remove the item from the result set in case of `DELETE` event, because file removal generates both `MODIFY` and `DELETE` events.
… the specific events,

not only `CREATE` or all of them.
* Modify tests and docs to reflect the new API
* Improve `FileReadingMessageSource.setWatchEvents()`
* Add `file.exists()` before adding file from event.
With the fact of those logs provide more optimizations:
* Don't register the same directory for watching:
  - use the `ConcurrentMap<Path, WatchKey> pathKeys` to track registrations
  - any modification within the directory causes the `ENTRY_MODIFY` for the directory as well.
    So, skip such an event exactly for the directory during `walkDirectory`
* Add debug logs in case of `ENTRY_DELETE`
@artembilan
Copy link
Member Author

Pushed.

@garyrussell
Copy link
Contributor

Merged as 7b1f77a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants