Skip to content

Commit ac9c73e

Browse files
committed
Extended readme with example and description
1 parent 5bcf1ce commit ac9c73e

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
11
# java-watch
2-
a java file watcher that works across platforms and supports recursion and single file watches
2+
a java file watcher that works across platforms and supports recursion, single file watches, and tries to make sure no events are missed.
33

4+
## Features
5+
6+
Currently working features in java-watch:
7+
8+
- Recursive watches, even if platform doesn't support it natively.
9+
- Recursive watches also work inside directories created after the watch started
10+
- On overflow events no **new** directories (and it's recursive files) are missed, modification events will however not be simulated
11+
- Single file watches
12+
- Multiple watches for the same directory are merged to avoid overloading the kernel
13+
- Events are process on a worker pool, which you can customize.
14+
15+
Future features:
16+
17+
- Avoid poll based watcher in macOS/OSX that only detects changes every 2 seconds
18+
- Support file watches natively in linux
19+
- Monitor only specific events (such as only CREATES)
20+
21+
## Usage
22+
23+
Import dependency in pom.xml:
24+
25+
```xml
26+
<dependency>
27+
<groupId>engineering.swat</groupId>
28+
<artifactId>java-watch</artifactId>
29+
<version>${java-watch-version}</version>
30+
</dependency>
31+
```
32+
33+
Start using java-watch:
34+
35+
```java
36+
var directory = Path.of("tmp", "test-dir");
37+
var watcherSetup = Watcher.watch(directory, WatchScope.PATH_AND_CHILDREN)
38+
.withExecutor(Executors.newCachedThreadPool()) // optionally configure a custom thread pool
39+
.onEvent(watchEvent -> {
40+
System.err.println(watchEvent);
41+
});
42+
43+
try(var active = watcherSetup.start()) {
44+
System.out.println("Monitoring files, press any key to stop");
45+
System.in.read();
46+
}
47+
// after active.close(), the watch is stopped and
48+
// no new events will be scheduled on the threadpool
49+
```
450

551
## Related work
52+
53+
Before starting this library, we wanted to use existing libraries, but they all lacked proper support for recursive file watches or lacked configurability. This library now has a growing collection of tests and a small API that should allow for future improvements without breaking compatibility.
54+
55+
The following section describes the related work research on the libraries and underlying limitations.
56+
657
After reading the documentation of the following discussion on file system watches:
758

859
- [Paul Millr's nodejs chokidar](https://github.com/paulmillr/chokidar)

0 commit comments

Comments
 (0)