[ https://issues.apache.org/jira/browse/MINIFI-2?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15232874#comment-15232874 ]
ASF GitHub Bot commented on MINIFI-2: ------------------------------------- Github user JPercivall commented on a diff in the pull request: https://github.com/apache/nifi-minifi/pull/7#discussion_r59085169 --- Diff: minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-runtime/src/main/java/org/apache/nifi/minifi/configuration/FileChangeNotifier.java --- @@ -0,0 +1,139 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.minifi.configuration; + +import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * FileChangeNotifier provides a simple FileSystem monitor for detecting changes for a specified file as generated from its corresponding {@link Path}. Upon modifications to the associated file, + * associated listeners receive notification of a change allowing configuration logic to be reanalyzed. The backing implementation is associated with a {@link ScheduledExecutorService} that + * ensures continuity of monitoring. + */ +public class FileChangeNotifier implements ConfigurationChangeNotifier, Closeable { + + private final ExecutorService executorService; + private final Path configFile; + private final WatchService configFileWatcher; + private final Set<ConfigurationChangeListener> configurationChangeListeners = new HashSet<>(); + + private static final int DEFAULT_POLLING_PERIOD_INTERVAL = 15; + private static final TimeUnit DEFAULT_POLLING_PERIOD_UNIT = TimeUnit.SECONDS; + + /** + * @param configFile to monitor for changes + * @throws IOException if there are any issues with accessing the specified config file or generating the associated {@link WatchService}. + */ + public FileChangeNotifier(Path configFile) throws IOException { + final File file = configFile.toFile(); + if (!file.exists() || !file.canRead() || !file.isFile()) { + throw new IllegalArgumentException(String.format("The specified path %s must be a readable file.", configFile)); --- End diff -- Should it be a valid state to start with no config file and wait for it to be put there? > File based implementation > ------------------------- > > Key: MINIFI-2 > URL: https://issues.apache.org/jira/browse/MINIFI-2 > Project: Apache NiFi MiNiFi > Issue Type: Sub-task > Components: Processing Configuration > Reporter: Aldrin Piri > Fix For: 0.0.1 > > Attachments: ConfigFileExplanation.xml, Properties_Guide.md, > config.yml > > > A defined schema for processing configuration will need to be defined. XML > or YAML seem like possible options for achieving this. > Agent configuration will come from two places, a bootstrap properties file > and a flow configuration file. The bootstrap will make use of some of the > original nifi.properties in order to start up the agent. The flow > configuration file will essentially be a stripped down version of a flow.xml > (with potentially S2S properties from nifi.properties). > The format for the bootstrap.properties should likely be similar to > nifi.properties. > Further, a way to incorporate this to leverage the libraries from core NiFi > will aid in achieving a proof of concept implementation more expediently. -- This message was sent by Atlassian JIRA (v6.3.4#6332)