Allow startlevel to increase past 80 when a bridge is disabled (#4640)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>pull/4693/head
parent
1960646a6d
commit
04b3890d03
|
@ -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)
|
// 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_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 ReadyMarker READY_MARKER_THINGS_LOADED = new ReadyMarker("things", "handler");
|
||||||
private static final String THING_STATUS_STORAGE_NAME = "thing_status_storage";
|
private static final String THING_STATUS_STORAGE_NAME = "thing_status_storage";
|
||||||
private static final String FORCE_REMOVE_THREAD_POOL_NAME = "forceRemove";
|
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()));
|
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
|
@Override
|
||||||
public void onReadyMarkerAdded(ReadyMarker readyMarker) {
|
public void onReadyMarkerAdded(ReadyMarker readyMarker) {
|
||||||
startLevelSetterJob = scheduler.scheduleWithFixedDelay(() -> {
|
startLevelSetterJob = scheduler.scheduleWithFixedDelay(() -> {
|
||||||
if (things.values().stream().anyMatch(t -> !ThingHandlerHelper.isHandlerInitialized(t) && t.isEnabled())) {
|
if (allEnabledThingsAreInitialized()) {
|
||||||
return;
|
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);
|
}, CHECK_INTERVAL, CHECK_INTERVAL, TimeUnit.SECONDS);
|
||||||
prerequisiteCheckerJob = scheduler.scheduleWithFixedDelay(this::checkMissingPrerequisites, CHECK_INTERVAL,
|
prerequisiteCheckerJob = scheduler.scheduleWithFixedDelay(this::checkMissingPrerequisites, CHECK_INTERVAL,
|
||||||
CHECK_INTERVAL, TimeUnit.SECONDS);
|
CHECK_INTERVAL, TimeUnit.SECONDS);
|
||||||
|
|
Loading…
Reference in New Issue