mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(LocalRunnerClient): co-locate watch service builder internals
Context: Group WatchService build interfaces and registry implementation into a single internal structure for better cohesion.
This commit is contained in:
@@ -272,72 +272,71 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
}));
|
||||
}
|
||||
|
||||
private WatchServiceBuild registerWatchService(Path path) {
|
||||
return new LocalWatchServiceRegistry(path, watchService, executor);
|
||||
private LocalWatchServiceBuild registerWatchService(Path path) {
|
||||
return new LocalWatchServiceBuild.BuildRegistry(path, watchService, executor);
|
||||
}
|
||||
|
||||
private interface WatchServiceBuild {
|
||||
WatchServiceBuild registerCreate(WatchEventHandler handler);
|
||||
private interface LocalWatchServiceBuild {
|
||||
LocalWatchServiceBuild registerCreate(EventHandler handler);
|
||||
|
||||
WatchServiceBuild registerModify(WatchEventHandler handler);
|
||||
LocalWatchServiceBuild registerModify(EventHandler handler);
|
||||
|
||||
WatchServiceBuild registerDelete(WatchEventHandler handler);
|
||||
LocalWatchServiceBuild registerDelete(EventHandler handler);
|
||||
|
||||
WatchServiceBuild registerOverflow(WatchEventHandler handler);
|
||||
LocalWatchServiceBuild registerOverflow(EventHandler handler);
|
||||
|
||||
WatchServiceBuild initialLoad(WatchInitLoader loader);
|
||||
LocalWatchServiceBuild initialLoad(InitLoader loader);
|
||||
|
||||
void commit();
|
||||
}
|
||||
|
||||
private interface WatchEventHandler {
|
||||
interface EventHandler {
|
||||
void handle(Path thisDir, Path context);
|
||||
}
|
||||
|
||||
private interface WatchInitLoader {
|
||||
interface InitLoader {
|
||||
void load(Path path);
|
||||
}
|
||||
|
||||
private static class LocalWatchServiceRegistry implements WatchServiceBuild {
|
||||
class BuildRegistry implements LocalWatchServiceBuild {
|
||||
|
||||
private final Map<WatchEvent.Kind<?>, WatchEventHandler> handlers = new HashMap<>();
|
||||
private final Map<WatchEvent.Kind<?>, EventHandler> handlers = new HashMap<>();
|
||||
private final Path path;
|
||||
private final WatchService watchService;
|
||||
private final ExecutorService executor;
|
||||
private WatchInitLoader initLoader;
|
||||
private InitLoader initLoader;
|
||||
|
||||
private LocalWatchServiceRegistry(Path path, WatchService watchService, ExecutorService executor) {
|
||||
private BuildRegistry(Path path, WatchService watchService, ExecutorService executor) {
|
||||
this.path = path;
|
||||
this.watchService = watchService;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchServiceBuild registerCreate(WatchEventHandler handler) {
|
||||
public LocalWatchServiceBuild registerCreate(EventHandler handler) {
|
||||
handlers.put(StandardWatchEventKinds.ENTRY_CREATE, handler);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchServiceBuild registerModify(WatchEventHandler handler) {
|
||||
public LocalWatchServiceBuild registerModify(EventHandler handler) {
|
||||
handlers.put(StandardWatchEventKinds.ENTRY_MODIFY, handler);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchServiceBuild registerDelete(WatchEventHandler handler) {
|
||||
public LocalWatchServiceBuild registerDelete(EventHandler handler) {
|
||||
handlers.put(StandardWatchEventKinds.ENTRY_DELETE, handler);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchServiceBuild registerOverflow(WatchEventHandler handler) {
|
||||
public LocalWatchServiceBuild registerOverflow(EventHandler handler) {
|
||||
handlers.put(StandardWatchEventKinds.OVERFLOW, handler);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchServiceBuild initialLoad(WatchInitLoader loader) {
|
||||
public LocalWatchServiceBuild initialLoad(InitLoader loader) {
|
||||
initLoader = loader;
|
||||
return this;
|
||||
}
|
||||
@@ -366,7 +365,7 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
// 若事件所在目录不为为 path,忽略并步入下一轮循环
|
||||
continue;
|
||||
}
|
||||
WatchEventHandler handler = handlers.get(kind);
|
||||
EventHandler handler = handlers.get(kind);
|
||||
if (handler == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -385,6 +384,7 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private sealed static abstract class LocalWatchServiceHelper permits LocalWatchServiceHelper.Dynamic, LocalWatchServiceHelper.Desc, LocalWatchServiceHelper.Common {
|
||||
|
||||
@@ -394,15 +394,15 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
this.existedMetaActions = existedMetaActions;
|
||||
}
|
||||
|
||||
protected abstract @NotNull WatchInitLoader buildLoad();
|
||||
protected abstract @NotNull LocalWatchServiceBuild.InitLoader buildLoad();
|
||||
|
||||
protected abstract @NotNull WatchEventHandler buildModify();
|
||||
protected abstract @NotNull LocalWatchServiceBuild.EventHandler buildModify();
|
||||
|
||||
protected abstract @NotNull WatchEventHandler buildCreate();
|
||||
protected abstract @NotNull LocalWatchServiceBuild.EventHandler buildCreate();
|
||||
|
||||
protected abstract @NotNull WatchEventHandler buildDelete();
|
||||
protected abstract @NotNull LocalWatchServiceBuild.EventHandler buildDelete();
|
||||
|
||||
protected abstract @NotNull WatchEventHandler buildOverflow();
|
||||
protected abstract @NotNull LocalWatchServiceBuild.EventHandler buildOverflow();
|
||||
|
||||
private static final class Dynamic extends LocalWatchServiceHelper {
|
||||
|
||||
@@ -417,29 +417,31 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
@NotNull
|
||||
protected WatchInitLoader buildLoad() {
|
||||
return null;
|
||||
protected LocalWatchServiceBuild.InitLoader buildLoad() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildModify() {
|
||||
return null;
|
||||
protected LocalWatchServiceBuild.EventHandler buildModify() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildCreate() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildCreate() {
|
||||
return buildModify();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected LocalWatchServiceBuild.EventHandler buildDelete() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildDelete() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildOverflow() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildOverflow() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -455,31 +457,31 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchInitLoader buildLoad() {
|
||||
protected LocalWatchServiceBuild.InitLoader buildLoad() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildModify() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildModify() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildCreate() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildCreate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildDelete() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildDelete() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildOverflow() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildOverflow() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -495,31 +497,31 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchInitLoader buildLoad() {
|
||||
protected LocalWatchServiceBuild.InitLoader buildLoad() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildModify() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildModify() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildCreate() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildCreate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildDelete() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildDelete() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected WatchEventHandler buildOverflow() {
|
||||
protected LocalWatchServiceBuild.EventHandler buildOverflow() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user