Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging to the StartLevelService #4577

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
package org.openhab.core.service;

import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SequencedMap;
import java.util.Set;
import java.util.TreeSet;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -98,7 +100,7 @@ public class StartLevelService {

private int openHABStartLevel = 0;

private Map<Integer, Set<ReadyMarker>> startlevels = Map.of();
private SequencedMap<Integer, Set<ReadyMarker>> startlevels = Collections.emptySortedMap();

@Activate
public StartLevelService(BundleContext bundleContext, @Reference ReadyService readyService,
Expand All @@ -116,9 +118,11 @@ protected void activate(Map<String, Object> configuration) {
handleOSGiStartlevel();

if (openHABStartLevel >= 10) {
for (Integer level : new TreeSet<>(startlevels.keySet())) {
for (Entry<Integer, Set<ReadyMarker>> entry : startlevels.entrySet()) {
Integer level = entry.getKey();
if (openHABStartLevel < level) {
boolean reached = isStartLevelReached(startlevels.get(level));
Set<ReadyMarker> markerSet = entry.getValue();
boolean reached = isStartLevelReached(level, markerSet);
if (reached) {
setStartLevel(level);
} else {
Expand All @@ -142,12 +146,13 @@ public int getStartLevel() {
return openHABStartLevel;
}

private boolean isStartLevelReached(@Nullable Set<ReadyMarker> markerSet) {
private boolean isStartLevelReached(Integer level, @Nullable Set<ReadyMarker> markerSet) {
if (markerSet == null) {
return true;
}
for (ReadyMarker m : markerSet) {
if (!markers.contains(m)) {
logger.debug("Missing marker {} for start level {}", m, level);
return false;
}
}
Expand All @@ -173,7 +178,7 @@ protected void modified(Map<String, Object> configuration) {
trackers.clear();

// set up trackers and markers
startlevels = parseConfig(configuration);
startlevels = Collections.unmodifiableSequencedMap(new TreeMap<>(parseConfig(configuration)));
startlevels.keySet()
.forEach(sl -> slmarker.put(sl, new ReadyMarker(STARTLEVEL_MARKER_TYPE, Integer.toString(sl))));
slmarker.put(STARTLEVEL_COMPLETE,
Expand Down