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.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
@ApplicationScoped
public class RemoteHostManager {
@@ -30,6 +29,9 @@ public class RemoteHostManager {
@Inject
PersistentRemoteHostsService persistentRemoteHostsService;
@Inject
SyncHandler syncHandler;
TransientPeersState _transientPeersState = new TransientPeersState();
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) {
Log.info("Connected to " + host);
if (_transientPeersState.runReadLocked(d -> d.getStates().getOrDefault(
@@ -71,9 +70,7 @@ public class RemoteHostManager {
curState.setState(TransientPeersStateData.TransientPeerState.ConnectionState.REACHABLE);
return null;
});
for (var h : _connectionSuccessHandlers) {
h.apply(host);
}
syncHandler.doInitialResync(host);
}
public void handleConnectionError(String host) {
@@ -84,18 +81,8 @@ public class RemoteHostManager {
curState.setState(TransientPeersStateData.TransientPeerState.ConnectionState.UNREACHABLE);
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
public interface ClientFunction<R> {

View File

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