feat(#119): add RouteStateRegistry for tracking route operational state

In-memory registry that infers route state (started/stopped/suspended)
from successful route-control command ACKs. Updates state only when all
agents in a group confirm success.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-02 19:15:35 +02:00
parent ca1d472b78
commit 0acceaf1a9
3 changed files with 72 additions and 2 deletions

View File

@@ -0,0 +1,36 @@
package com.cameleer3.server.core.agent;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* In-memory registry tracking the operational state of routes.
* State is inferred from successful route-control command ACKs.
* On server restart, all states reset to STARTED (default Camel behavior).
*/
public class RouteStateRegistry {
public enum RouteState { STARTED, STOPPED, SUSPENDED }
// Key: "applicationId:routeId"
private final ConcurrentHashMap<String, RouteState> states = new ConcurrentHashMap<>();
public void setState(String applicationId, String routeId, RouteState state) {
states.put(applicationId + ":" + routeId, state);
}
public RouteState getState(String applicationId, String routeId) {
return states.getOrDefault(applicationId + ":" + routeId, RouteState.STARTED);
}
public Map<String, RouteState> getStatesForApplication(String applicationId) {
Map<String, RouteState> result = new LinkedHashMap<>();
states.forEach((key, state) -> {
if (key.startsWith(applicationId + ":")) {
result.put(key.substring(applicationId.length() + 1), state);
}
});
return result;
}
}