You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/01/11 13:37:51 UTC

[GitHub] markap14 commented on a change in pull request #3241: NIFI-5922: NiFi-Fn, an alternative runtime for NiFi flows

markap14 commented on a change in pull request #3241: NIFI-5922: NiFi-Fn, an alternative runtime for NiFi flows
URL: https://github.com/apache/nifi/pull/3241#discussion_r247117341
 
 

 ##########
 File path: nifi-fn/src/main/java/org/apache/nifi/fn/core/FnConfigurationContext.java
 ##########
 @@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.fn.core;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.PropertyValue;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.controller.ControllerService;
+import org.apache.nifi.controller.ControllerServiceLookup;
+import org.apache.nifi.registry.VariableRegistry;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public class FnConfigurationContext implements ConfigurationContext {
+
+    private final Map<PropertyDescriptor, String> properties;
+    private final ControllerServiceLookup serviceLookup;
+    private final ControllerService service;
+    private final VariableRegistry variableRegistry;
+
+    public FnConfigurationContext(final ControllerService service,
+                                  final Map<PropertyDescriptor, String> properties,
+                                  final ControllerServiceLookup serviceLookup,
+                                  final VariableRegistry variableRegistry) {
+        this.service = service;
+        this.properties = properties;
+        this.serviceLookup = serviceLookup;
+        this.variableRegistry = variableRegistry;
+    }
+
+    @Override
+    public PropertyValue getProperty(final PropertyDescriptor property) {
+        String value = properties.get(property);
+        if (value == null) {
+            value = getActualDescriptor(property).getDefaultValue();
+        }
+        return new FnPropertyValue(value, serviceLookup, variableRegistry);
+    }
+
+    @Override
+    public Map<PropertyDescriptor, String> getProperties() {
+        return new HashMap<>(this.properties);
 
 Review comment:
   Given that `properties` is injected in and never modified, we should probably just use `this.properties = Collections.unmodifiableMap(properties);` in the constructor and avoid copying the map here. As-is, this can result in quite a lot of garbage.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services