little fixes 7

This commit is contained in:
2024-06-21 23:50:38 +02:00
parent 3f91c4dc67
commit 0a9f3f4e1f
2 changed files with 5 additions and 28 deletions

View File

@@ -20,7 +20,6 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
@ApplicationScoped @ApplicationScoped
public class RemoteHostManager { public class RemoteHostManager {
@@ -30,6 +29,9 @@ public class RemoteHostManager {
@Inject @Inject
PersistentRemoteHostsService persistentRemoteHostsService; PersistentRemoteHostsService persistentRemoteHostsService;
@Inject
SyncHandler syncHandler;
TransientPeersState _transientPeersState = new TransientPeersState(); TransientPeersState _transientPeersState = new TransientPeersState();
void init(@Observes @Priority(350) StartupEvent event) throws IOException { void init(@Observes @Priority(350) StartupEvent event) throws IOException {
@@ -57,9 +59,6 @@ public class RemoteHostManager {
} }
} }
private final ArrayList<Function<String, Void>> _connectionSuccessHandlers = new ArrayList<>();
private final ArrayList<Function<String, Void>> _connectionErrorHandlers = new ArrayList<>();
public void handleConnectionSuccess(String host) { public void handleConnectionSuccess(String host) {
Log.info("Connected to " + host); Log.info("Connected to " + host);
if (_transientPeersState.runReadLocked(d -> d.getStates().getOrDefault( if (_transientPeersState.runReadLocked(d -> d.getStates().getOrDefault(
@@ -71,9 +70,7 @@ public class RemoteHostManager {
curState.setState(TransientPeersStateData.TransientPeerState.ConnectionState.REACHABLE); curState.setState(TransientPeersStateData.TransientPeerState.ConnectionState.REACHABLE);
return null; return null;
}); });
for (var h : _connectionSuccessHandlers) { syncHandler.doInitialResync(host);
h.apply(host);
}
} }
public void handleConnectionError(String host) { public void handleConnectionError(String host) {
@@ -84,18 +81,8 @@ public class RemoteHostManager {
curState.setState(TransientPeersStateData.TransientPeerState.ConnectionState.UNREACHABLE); curState.setState(TransientPeersStateData.TransientPeerState.ConnectionState.UNREACHABLE);
return null; return null;
}); });
for (var h : _connectionErrorHandlers) {
h.apply(host);
}
} }
public void addConnectionSuccessHandler(Function<String, Void> handler) {
_connectionSuccessHandlers.add(handler);
}
public void addConnectionErrorHandler(Function<String, Void> handler) {
_connectionErrorHandlers.add(handler);
}
@FunctionalInterface @FunctionalInterface
public interface ClientFunction<R> { public interface ClientFunction<R> {

View File

@@ -40,17 +40,7 @@ public class SyncHandler {
@Inject @Inject
Instance<ConflictResolver> conflictResolvers; Instance<ConflictResolver> conflictResolvers;
void init(@Observes @Priority(340) StartupEvent event) throws IOException { public void doInitialResync(String host) {
remoteHostManager.addConnectionSuccessHandler((host) -> {
doInitialResync(host);
return null;
});
}
void shutdown(@Observes @Priority(240) ShutdownEvent event) throws IOException {
}
private void doInitialResync(String host) {
var got = remoteObjectServiceClient.getIndex(host); var got = remoteObjectServiceClient.getIndex(host);
for (var h : got.getObjectsList()) { for (var h : got.getObjectsList()) {
handleRemoteUpdate(IndexUpdatePush.newBuilder() handleRemoteUpdate(IndexUpdatePush.newBuilder()