elguardian commented on code in PR #3946:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3946#discussion_r2128803435


##########
jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceFactoryRegistry.java:
##########
@@ -30,18 +27,26 @@
 import org.slf4j.LoggerFactory;
 
 public class NodeInstanceFactoryRegistry {
+    public static final String NODE_INSTANCE_FACTORY_REGISTRY_KEY = 
"NodeInstanceFactoryRegistry";
+
     private static final Logger LOGGER = 
LoggerFactory.getLogger(NodeInstanceFactoryRegistry.class);
     private static final NodeInstanceFactoryRegistry INSTANCE = new 
NodeInstanceFactoryRegistry();
 
-    private Map<Class<? extends Node>, NodeInstanceFactory> registry;
+    private static final Map<String, NodeInstanceFactoryRegistry> 
LOADED_NODE_INSTANCE_FACTORY_REGISTRIES = new HashMap<>();
+
+    private final Map<Class<? extends Node>, NodeInstanceFactory> registry;
 
     public static NodeInstanceFactoryRegistry getInstance(Environment 
environment) {
-        // allow custom NodeInstanceFactoryRegistry to be given as part of the 
environment - e.g simulation
-        if (environment != null && 
environment.get("NodeInstanceFactoryRegistry") != null) {
-            return (NodeInstanceFactoryRegistry) 
environment.get("NodeInstanceFactoryRegistry");
-        }
+        return getFactoryRegistryFromEnvironment(environment).orElse(INSTANCE);
+    }
 
-        return INSTANCE;
+    private static Optional<NodeInstanceFactoryRegistry> 
getFactoryRegistryFromEnvironment(Environment environment) {
+        if (environment != null && 
environment.get(NODE_INSTANCE_FACTORY_REGISTRY_KEY) != null) {
+            String factoryRegistryClassName = (String) 
environment.get(NODE_INSTANCE_FACTORY_REGISTRY_KEY);
+            return 
Optional.ofNullable(LOADED_NODE_INSTANCE_FACTORY_REGISTRIES.computeIfAbsent(factoryRegistryClassName,
+                    className -> 
CodegenNodeInstanceFactoryRegistry.class.getName().equals(className) ? new 
CodegenNodeInstanceFactoryRegistry() : null));

Review Comment:
   a bit strange. Class.forName().getConstructor().newInstance()
   don't compute null. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to