From 7990a14c20622b50a0c2aa73be7a6d4b0165914a Mon Sep 17 00:00:00 2001 From: Jimmy Tanagra Date: Mon, 3 Apr 2023 02:12:25 +1000 Subject: [PATCH] Use the engineFactory as the hash key Signed-off-by: Jimmy Tanagra --- .../ScriptTransformationServiceFactory.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationServiceFactory.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationServiceFactory.java index b489b33e462..fdcd21adc52 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationServiceFactory.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationServiceFactory.java @@ -44,7 +44,7 @@ public class ScriptTransformationServiceFactory { private final ComponentFactory scriptTransformationFactory; - private final Map> scriptTransformations = new ConcurrentHashMap<>(); + private final Map> scriptTransformations = new ConcurrentHashMap<>(); @Activate public ScriptTransformationServiceFactory( @@ -69,28 +69,22 @@ public void setScriptEngineFactory(ScriptEngineFactory engineFactory) { return; } - scriptTransformations.computeIfAbsent(scriptType.get(), type -> { - ScriptEngine scriptEngine = engineFactory.createScriptEngine(type); + scriptTransformations.computeIfAbsent(engineFactory, factory -> { + ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptType.get()); if (scriptEngine == null) { return null; } String languageName = ScriptEngineFactoryHelper.getLanguageName(scriptEngine.getFactory()); Dictionary properties = new Hashtable<>(); - properties.put(TransformationService.SERVICE_PROPERTY_NAME, type.toUpperCase()); + properties.put(TransformationService.SERVICE_PROPERTY_NAME, scriptType.get().toUpperCase()); properties.put(TransformationService.SERVICE_PROPERTY_LABEL, "SCRIPT " + languageName); - properties.put(ScriptTransformationService.SCRIPT_TYPE_PROPERTY_NAME, type); + properties.put(ScriptTransformationService.SCRIPT_TYPE_PROPERTY_NAME, scriptType.get()); return scriptTransformationFactory.newInstance(properties); }); } public void unsetScriptEngineFactory(ScriptEngineFactory engineFactory) { - Optional scriptType = ScriptEngineFactoryHelper.getPreferredExtension(engineFactory); - if (scriptType.isEmpty()) { - return; - } - - ComponentInstance toBeUnregistered = scriptTransformations - .remove(scriptType.get()); + ComponentInstance toBeUnregistered = scriptTransformations.remove(engineFactory); if (toBeUnregistered != null) { unregisterService(toBeUnregistered); }