Allow startlevel to increase past 80 when a bridge is disabled (#4640)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
pull/4693/head
jimtng 2025-04-02 09:06:21 +10:00 committed by GitHub
parent 1960646a6d
commit 04b3890d03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 36 additions and 7 deletions

View File

@ -129,6 +129,7 @@ public class ThingManagerImpl implements ReadyTracker, ThingManager, ThingTracke
// time after we try to initialize a thing even if the thing-type is not registered (in s)
private static final int MAX_CHECK_PREREQUISITE_TIME = 120;
private static final int MAX_BRIDGE_NESTING = 50;
private static final ReadyMarker READY_MARKER_THINGS_LOADED = new ReadyMarker("things", "handler");
private static final String THING_STATUS_STORAGE_NAME = "thing_status_storage";
private static final String FORCE_REMOVE_THREAD_POOL_NAME = "forceRemove";
@ -1172,17 +1173,45 @@ public class ThingManagerImpl implements ReadyTracker, ThingManager, ThingTracke
updateInstructions.keySet().removeIf(key -> thingHandlerFactory.equals(key.factory()));
}
private boolean allEnabledThingsAreInitialized() {
for (Thing thing : things.values()) {
if (!thing.isEnabled() || ThingHandlerHelper.isHandlerInitialized(thing)) {
continue;
}
int bridgeNestingLevel = 0;
boolean bridgeDisabled = false;
Bridge bridge = getBridge(thing.getBridgeUID());
while (bridge != null) {
if (!bridge.isEnabled()) {
bridgeDisabled = true;
break;
}
bridge = getBridge(bridge.getBridgeUID());
if (bridgeNestingLevel++ > MAX_BRIDGE_NESTING) {
logger.warn("Bridge nesting is too deep for thing '{}'", thing.getUID());
return false;
}
}
if (bridgeDisabled) {
logger.debug("Thing '{}' is not ready because its bridge is disabled.", thing.getUID());
continue;
}
return false;
}
return true;
}
@Override
public void onReadyMarkerAdded(ReadyMarker readyMarker) {
startLevelSetterJob = scheduler.scheduleWithFixedDelay(() -> {
if (things.values().stream().anyMatch(t -> !ThingHandlerHelper.isHandlerInitialized(t) && t.isEnabled())) {
return;
if (allEnabledThingsAreInitialized()) {
readyService.markReady(READY_MARKER_THINGS_LOADED);
if (startLevelSetterJob != null) {
startLevelSetterJob.cancel(false);
}
readyService.unregisterTracker(this);
}
readyService.markReady(READY_MARKER_THINGS_LOADED);
if (startLevelSetterJob != null) {
startLevelSetterJob.cancel(false);
}
readyService.unregisterTracker(this);
}, CHECK_INTERVAL, CHECK_INTERVAL, TimeUnit.SECONDS);
prerequisiteCheckerJob = scheduler.scheduleWithFixedDelay(this::checkMissingPrerequisites, CHECK_INTERVAL,
CHECK_INTERVAL, TimeUnit.SECONDS);