diff --git a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/YamlThingProvider.java b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/YamlThingProvider.java index e11653db2f7..f686272295c 100644 --- a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/YamlThingProvider.java +++ b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/YamlThingProvider.java @@ -103,16 +103,19 @@ public class YamlThingProvider extends AbstractProvider private final Map> thingsMap = new ConcurrentHashMap<>(); private final List queue = new CopyOnWriteArrayList<>(); + private final Object queueLock = new Object(); private final Runnable lazyRetryRunnable = new Runnable() { @Override public void run() { logger.debug("Starting lazy retry thread"); while (!queue.isEmpty()) { - for (QueueContent qc : queue) { - if (retryCreateThing(qc.thingHandlerFactory, qc.thingTypeUID, qc.configuration, qc.thingUID, - qc.bridgeUID)) { - queue.remove(qc); + synchronized (queueLock) { + for (QueueContent qc : queue) { + if (retryCreateThing(qc.thingHandlerFactory, qc.thingTypeUID, qc.configuration, qc.thingUID, + qc.bridgeUID)) { + queue.remove(qc); + } } } if (!queue.isEmpty()) { @@ -198,6 +201,11 @@ public void addedModel(String modelName, Collection elements) { @Override public void updatedModel(String modelName, Collection elements) { boolean isolated = isIsolatedModel(modelName); + if (!isolated) { + elements.stream().map(this::buildThingUID).filter(Objects::nonNull).forEach(uid -> { + removeFromRetryQueue(uid); + }); + } List updated = elements.stream().map(t -> mapThing(t, isolated)).filter(Objects::nonNull).toList(); Collection modelThings = Objects .requireNonNull(thingsMap.computeIfAbsent(modelName, k -> new ArrayList<>())); @@ -224,6 +232,9 @@ public void removedModel(String modelName, Collection elements) { boolean isolated = isIsolatedModel(modelName); Collection modelThings = thingsMap.getOrDefault(modelName, List.of()); elements.stream().map(this::buildThingUID).filter(Objects::nonNull).forEach(uid -> { + if (!isolated) { + removeFromRetryQueue(uid); + } modelThings.stream().filter(th -> th.getUID().equals(uid)).findFirst().ifPresentOrElse(oldThing -> { modelThings.remove(oldThing); logger.debug("model {} removed thing {}", modelName, uid); @@ -544,7 +555,9 @@ private void mergeThing(Thing target, Thing source, boolean keepSourceConfig) { private void queueRetryThingCreation(ThingHandlerFactory handlerFactory, ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID, @Nullable ThingUID bridgeUID) { - queue.add(new QueueContent(handlerFactory, thingTypeUID, configuration, thingUID, bridgeUID)); + synchronized (queueLock) { + queue.add(new QueueContent(handlerFactory, thingTypeUID, configuration, thingUID, bridgeUID)); + } Thread thread = lazyRetryThread; if (thread == null || !thread.isAlive()) { thread = new Thread(lazyRetryRunnable); @@ -553,6 +566,16 @@ private void queueRetryThingCreation(ThingHandlerFactory handlerFactory, ThingTy } } + private void removeFromRetryQueue(ThingUID thingUID) { + synchronized (queueLock) { + for (QueueContent qc : queue) { + if (thingUID.equals(qc.thingUID)) { + queue.remove(qc); + } + } + } + } + private Configuration processThingConfiguration(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration) { Set thingStringParams = !configuration.keySet().isEmpty()