mirror of https://github.com/zlatinb/muwire
do not print stacktrace on clean shutdown
parent
aef7533bd5
commit
d5eb65bdc2
|
@ -19,6 +19,7 @@ class DirectoryWatcher {
|
||||||
private final EventBus eventBus
|
private final EventBus eventBus
|
||||||
private final Thread watcherThread
|
private final Thread watcherThread
|
||||||
private WatchService watchService
|
private WatchService watchService
|
||||||
|
private volatile boolean shutdown
|
||||||
|
|
||||||
DirectoryWatcher(EventBus eventBus) {
|
DirectoryWatcher(EventBus eventBus) {
|
||||||
this.eventBus = eventBus
|
this.eventBus = eventBus
|
||||||
|
@ -32,6 +33,7 @@ class DirectoryWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop() {
|
void stop() {
|
||||||
|
shutdown = true
|
||||||
watcherThread.interrupt()
|
watcherThread.interrupt()
|
||||||
watchService.close()
|
watchService.close()
|
||||||
}
|
}
|
||||||
|
@ -47,13 +49,18 @@ class DirectoryWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void watch() {
|
private void watch() {
|
||||||
while(true) {
|
try {
|
||||||
WatchKey key = watchService.take()
|
while(!shutdown) {
|
||||||
key.pollEvents().each {
|
WatchKey key = watchService.take()
|
||||||
if (it.kind() == StandardWatchEventKinds.ENTRY_MODIFY)
|
key.pollEvents().each {
|
||||||
processModified(key.watchable(), it.context())
|
if (it.kind() == StandardWatchEventKinds.ENTRY_MODIFY)
|
||||||
|
processModified(key.watchable(), it.context())
|
||||||
|
}
|
||||||
|
key.reset()
|
||||||
}
|
}
|
||||||
key.reset()
|
} catch (InterruptedException e) {
|
||||||
|
if (!shutdown)
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue