1 | scope jdk_watchService_start. |
2 | |
3 | static new Flag #started; |
4 | static new MultiMap<WatchKey, O> #listeners; // values: voidfunc(File) |
5 | static int #interval = 50; // larger interval helps show less duplicate events (https://stackoverflow.com/questions/16777869/java-7-watchservice-ignoring-multiple-occurrences-of-the-same-event/34818620#34818620) |
6 | |
7 | static WatchService jdk_watchService_start() {
|
8 | final WatchService service = jdk_defaultWatchService(); |
9 | if (started.raise()) thread "Watch Service" {
|
10 | while licensed {
|
11 | WatchKey key = service.poll(10, TimeUnit.SECONDS); |
12 | if (key != null) {
|
13 | Path dir = cast key.watchable(); |
14 | sleep(interval); |
15 | L<WatchEvent<?>> events = key.pollEvents(); |
16 | new LinkedHashSet<File> changedFiles; |
17 | for (WatchEvent<?> event : reversedIterator(events)) pcall {
|
18 | final Path changed = (Path) event.context(); |
19 | File full = newFile(dir.toFile(), changed.toFile().getPath()); |
20 | changedFiles.add(full); |
21 | //print("WatchService Changed: " + full + ", " + event.kind());
|
22 | } |
23 | for (File f : changedFiles) |
24 | pcallFAll(listeners.get(key), f); |
25 | key.reset(); |
26 | } |
27 | } |
28 | } |
29 | ret service; |
30 | } |
31 | |
32 | end scope |
Began life as a copy of #1019342
download show line numbers debug dex old transpilations
Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1019344 |
| Snippet name: | jdk_watchService_start - starts background thread |
| Eternal ID of this version: | #1019344/13 |
| Text MD5: | 5de6931fa605fa97544942e7a352ca1c |
| Author: | stefan |
| Category: | javax / io |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-12-07 22:36:44 |
| Source code size: | 1254 bytes / 32 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 536 / 613 |
| Version history: | 12 change(s) |
| Referenced in: | [show references] |