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

Fix wrong ready marker in ScriptEngineFactoryBundleTracker #3683

Merged
merged 3 commits into from
Jul 6, 2023
Merged
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 @@ -50,22 +50,19 @@ public class ScriptEngineFactoryBundleTracker extends BundleTracker<Bundle> impl
private final Logger logger = LoggerFactory.getLogger(ScriptEngineFactoryBundleTracker.class);

private final ReadyService readyService;
private final StartLevelService startLevelService;

private final Map<String, Integer> bundles = new ConcurrentHashMap<>();
private boolean startLevel = false;
private boolean ready = false;

@Activate
public ScriptEngineFactoryBundleTracker(final @Reference ReadyService readyService,
final @Reference StartLevelService startLevelService, BundleContext bc) {
public ScriptEngineFactoryBundleTracker(final @Reference ReadyService readyService, BundleContext bc) {
super(bc, STATE_MASK, null);
this.readyService = readyService;
this.startLevelService = startLevelService;

this.open();

readyService.registerTracker(this, new ReadyMarkerFilter().withType(StartLevelService.STARTLEVEL_MARKER_TYPE)
.withIdentifier(Integer.toString(StartLevelService.STARTLEVEL_OSGI)));
.withIdentifier(Integer.toString(StartLevelService.STARTLEVEL_MODEL)));
}

@Deactivate
Expand All @@ -85,8 +82,8 @@ public Bundle addingBundle(@NonNullByDefault({}) Bundle bundle, @Nullable Bundle
if (isScriptingBundle(bundle)) {
logger.debug("Added {}: {} ", bsn, stateToString(state));
bundles.put(bsn, state);
checkReady();
}
checkReady();

return bundle;
}
Expand All @@ -99,8 +96,8 @@ public void modifiedBundle(@NonNullByDefault({}) Bundle bundle, @Nullable Bundle
if (isScriptingBundle(bundle)) {
logger.debug("Modified {}: {}", bsn, stateToString(state));
bundles.put(bsn, state);
checkReady();
}
checkReady();
}

@Override
Expand All @@ -110,27 +107,35 @@ public void removedBundle(@NonNullByDefault({}) Bundle bundle, @Nullable BundleE
if (isScriptingBundle(bundle)) {
logger.debug("Removed {}", bsn);
bundles.remove(bsn);
checkReady();
}
checkReady();
}

@Override
public void onReadyMarkerAdded(ReadyMarker readyMarker) {
logger.debug("Readymarker {} added", readyMarker);
startLevel = true;
checkReady();
}

@Override
public void onReadyMarkerRemoved(ReadyMarker readyMarker) {
logger.debug("Readymarker {} removed", readyMarker);
startLevel = false;
ready = false;
readyService.unmarkReady(READY_MARKER);
}

private void checkReady() {
if (!ready && startLevelService.getStartLevel() > StartLevelService.STARTLEVEL_OSGI && allBundlesActive()) {
logger.info("All automation bundles ready.");
private synchronized void checkReady() {
boolean allBundlesActive = allBundlesActive();
logger.trace("ready: {}, startlevel: {}, allActive: {}", ready, startLevel, allBundlesActive);

if (!ready && startLevel && allBundlesActive) {
logger.debug("Adding ready marker: All automation bundles ready ({})", bundles);
readyService.markReady(READY_MARKER);
ready = true;
} else if (ready && !allBundlesActive()) {
} else if (ready && !allBundlesActive) {
logger.debug("Removing ready marker: Not all automation bundles ready ({})", bundles);
readyService.unmarkReady(READY_MARKER);
ready = false;
}
Expand Down