forked from mirror/BlueMap
Fix use of implementation-specific exception
This commit is contained in:
parent
3db6833fc6
commit
8455b50fc3
@ -32,7 +32,6 @@
|
||||
import de.bluecolored.bluemap.core.util.WatchService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.ClosedWatchServiceException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
@ -67,7 +66,7 @@ public void run() {
|
||||
try {
|
||||
while (!closed)
|
||||
this.watchService.take().forEach(this::updateRegion);
|
||||
} catch (ClosedWatchServiceException ignore) {
|
||||
} catch (WatchService.ClosedException ignore) {
|
||||
} catch (InterruptedException iex) {
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.util;
|
||||
|
||||
import lombok.experimental.StandardException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
@ -35,11 +36,33 @@
|
||||
*/
|
||||
public interface WatchService<T> extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* Retrieves and consumes the next batch of events.
|
||||
* @throws ClosedException If the watch-service is closed
|
||||
*/
|
||||
@Nullable
|
||||
List<T> poll();
|
||||
|
||||
/**
|
||||
* Retrieves and consumes the next batch of events,
|
||||
* waiting if necessary up to the specified wait time if none are yet present.
|
||||
* @throws ClosedException If the watch-service is closed, or it is closed while waiting for the next event
|
||||
* @throws InterruptedException If interrupted while waiting
|
||||
*/
|
||||
@Nullable List<T> poll(long timeout, TimeUnit unit) throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Retrieves and consumes the next batch of events,
|
||||
* waiting if necessary until an event becomes available.
|
||||
* @throws ClosedException If the watch-service is closed, or it is closed while waiting for the next event
|
||||
* @throws InterruptedException If interrupted while waiting
|
||||
*/
|
||||
List<T> take() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Thrown when the WatchService is closed or gets closed when polling or while waiting for events
|
||||
*/
|
||||
@StandardException
|
||||
class ClosedException extends RuntimeException {}
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.ClosedWatchServiceException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardWatchEventKinds;
|
||||
import java.nio.file.WatchKey;
|
||||
@ -52,22 +53,34 @@ public MCAWorldRegionWatchService(Path regionFolder) throws IOException {
|
||||
|
||||
@Override
|
||||
public @Nullable List<Vector2i> poll() {
|
||||
WatchKey key = watchService.poll();
|
||||
if (key == null) return null;
|
||||
return processWatchKey(key);
|
||||
try {
|
||||
WatchKey key = watchService.poll();
|
||||
if (key == null) return null;
|
||||
return processWatchKey(key);
|
||||
} catch (ClosedWatchServiceException e) {
|
||||
throw new ClosedException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<Vector2i> poll(long timeout, TimeUnit unit) throws InterruptedException {
|
||||
WatchKey key = watchService.poll(timeout, unit);
|
||||
if (key == null) return null;
|
||||
return processWatchKey(key);
|
||||
try {
|
||||
WatchKey key = watchService.poll(timeout, unit);
|
||||
if (key == null) return null;
|
||||
return processWatchKey(key);
|
||||
} catch (ClosedWatchServiceException e) {
|
||||
throw new ClosedException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Vector2i> take() throws InterruptedException {
|
||||
WatchKey key = watchService.take();
|
||||
return processWatchKey(key);
|
||||
try {
|
||||
WatchKey key = watchService.take();
|
||||
return processWatchKey(key);
|
||||
} catch (ClosedWatchServiceException e) {
|
||||
throw new ClosedException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user