Skip to content

Commit

Permalink
Fix wrong ready marker in ScriptEngineFactoryBundleTracker (#3683)
Browse files Browse the repository at this point in the history
* Fix wrong ready marker in ScriptEngineFactoryBundleTracker
* fix ready marker handling

Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored Jul 6, 2023
1 parent e9719eb commit 6a0b268
Showing 1 changed file with 18 additions and 13 deletions.
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

0 comments on commit 6a0b268

Please sign in to comment.