mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-01-25 01:31:22 +01:00
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 de.bluecolored.bluemap.core.util.WatchService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.ClosedWatchServiceException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
@ -67,7 +66,7 @@ public void run() {
|
|||||||
try {
|
try {
|
||||||
while (!closed)
|
while (!closed)
|
||||||
this.watchService.take().forEach(this::updateRegion);
|
this.watchService.take().forEach(this::updateRegion);
|
||||||
} catch (ClosedWatchServiceException ignore) {
|
} catch (WatchService.ClosedException ignore) {
|
||||||
} catch (InterruptedException iex) {
|
} catch (InterruptedException iex) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.bluecolored.bluemap.core.util;
|
package de.bluecolored.bluemap.core.util;
|
||||||
|
|
||||||
|
import lombok.experimental.StandardException;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,11 +36,33 @@
|
|||||||
*/
|
*/
|
||||||
public interface WatchService<T> extends AutoCloseable {
|
public interface WatchService<T> extends AutoCloseable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves and consumes the next batch of events.
|
||||||
|
* @throws ClosedException If the watch-service is closed
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
List<T> poll();
|
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;
|
@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;
|
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 org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.ClosedWatchServiceException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardWatchEventKinds;
|
import java.nio.file.StandardWatchEventKinds;
|
||||||
import java.nio.file.WatchKey;
|
import java.nio.file.WatchKey;
|
||||||
@ -52,22 +53,34 @@ public MCAWorldRegionWatchService(Path regionFolder) throws IOException {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<Vector2i> poll() {
|
public @Nullable List<Vector2i> poll() {
|
||||||
WatchKey key = watchService.poll();
|
try {
|
||||||
if (key == null) return null;
|
WatchKey key = watchService.poll();
|
||||||
return processWatchKey(key);
|
if (key == null) return null;
|
||||||
|
return processWatchKey(key);
|
||||||
|
} catch (ClosedWatchServiceException e) {
|
||||||
|
throw new ClosedException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<Vector2i> poll(long timeout, TimeUnit unit) throws InterruptedException {
|
public @Nullable List<Vector2i> poll(long timeout, TimeUnit unit) throws InterruptedException {
|
||||||
WatchKey key = watchService.poll(timeout, unit);
|
try {
|
||||||
if (key == null) return null;
|
WatchKey key = watchService.poll(timeout, unit);
|
||||||
return processWatchKey(key);
|
if (key == null) return null;
|
||||||
|
return processWatchKey(key);
|
||||||
|
} catch (ClosedWatchServiceException e) {
|
||||||
|
throw new ClosedException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Vector2i> take() throws InterruptedException {
|
public List<Vector2i> take() throws InterruptedException {
|
||||||
WatchKey key = watchService.take();
|
try {
|
||||||
return processWatchKey(key);
|
WatchKey key = watchService.take();
|
||||||
|
return processWatchKey(key);
|
||||||
|
} catch (ClosedWatchServiceException e) {
|
||||||
|
throw new ClosedException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user