[
https://issues.apache.org/jira/browse/NIFI-5673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16671893#comment-16671893
]
ASF GitHub Bot commented on NIFI-5673:
--------------------------------------
Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/3119#discussion_r230120979
--- Diff:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-nar-loading-utils/src/main/java/org/apache/nifi/nar/NarAutoLoader.java
---
@@ -0,0 +1,89 @@
+/*
+ * 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.nar;
+
+import org.apache.nifi.util.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.nio.file.StandardWatchEventKinds;
+import java.nio.file.WatchService;
+import java.util.Objects;
+
+/**
+ * Starts a thread to monitor the auto-load directory for new NARs.
+ */
+public class NarAutoLoader {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(NarAutoLoader.class);
+
+ private static final long POLL_INTERVAL_MS = 5000;
+
+ private final File autoLoadDir;
+ private final NarLoader narLoader;
+
+ private volatile NarAutoLoaderTask narAutoLoaderTask;
+ private volatile boolean started = false;
+
+ public NarAutoLoader(final File autoLoadDir, final NarLoader
narLoader) {
+ this.autoLoadDir = autoLoadDir;
+ this.narLoader = narLoader;
+ Objects.requireNonNull(this.autoLoadDir);
+ Objects.requireNonNull(this.narLoader);
+ }
+
+ public synchronized void start() throws IOException {
+ if (started) {
+ return;
+ }
+
+ FileUtils.ensureDirectoryExistAndCanReadAndWrite(autoLoadDir);
+
+ final WatchService watcher =
FileSystems.getDefault().newWatchService();
+
+ final Path autoLoadPath = autoLoadDir.toPath();
+ autoLoadPath.register(watcher,
StandardWatchEventKinds.ENTRY_CREATE);
+
+ narAutoLoaderTask = new NarAutoLoaderTask.Builder()
+ .autoLoadPath(autoLoadPath)
+ .watchService(watcher)
+ .pollIntervalMillis(POLL_INTERVAL_MS)
+ .narLoader(narLoader)
+ .build();
+
+ LOGGER.info("Starting NAR Auto-Loader for directory {} ...", new
Object[]{autoLoadPath});
+
+ final Thread thread = new Thread(narAutoLoaderTask);
+ thread.setName("NAR Auto-Loader");
+ thread.setDaemon(true);
+ thread.start();
+
+ LOGGER.info("NAR Auto-Loader started");
+ started = true;
+ }
+
+ public synchronized void stop() {
+ started = false;
+ narAutoLoaderTask.stop();;
--- End diff --
Extra semi-colon at the end :)
> Support auto loading of new NARs
> --------------------------------
>
> Key: NIFI-5673
> URL: https://issues.apache.org/jira/browse/NIFI-5673
> Project: Apache NiFi
> Issue Type: Improvement
> Reporter: Bryan Bende
> Assignee: Bryan Bende
> Priority: Minor
>
> We should be able to detect when new NARs have been added to any of the NAR
> directories and automatically load them and make the components available for
> use without restarting the whole NiFi instance.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)