Ethanlm commented on a change in pull request #3269:
URL: https://github.com/apache/storm/pull/3269#discussion_r425273758



##########
File path: 
storm-webapp/src/main/java/org/apache/storm/daemon/common/FileWatcher.java
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.storm.daemon.common;
+
+import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
+
+import java.io.IOException;
+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.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FileWatcher implements Runnable {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(FileWatcher.class);
+
+    private final WatchService watcher;
+    private volatile boolean stopped = false;
+    private final Path watchedFile;
+    private final Callback callback;
+    List<WatchEvent.Kind<Path>> kinds;
+
+    public FileWatcher(final Path watchedFile, Callback callback) throws 
IOException {
+        this(watchedFile, callback, Collections.singletonList(ENTRY_MODIFY));
+    }
+
+    public FileWatcher(final Path watchedFile, Callback callback, 
List<WatchEvent.Kind<Path>> kinds) throws IOException {
+        this.watchedFile = watchedFile;
+        this.callback = callback;
+        Path parent = watchedFile.getParent();
+        this.watcher = parent.getFileSystem().newWatchService();
+        this.kinds = kinds;
+        parent.register(watcher, this.kinds.toArray(new WatchEvent.Kind[0]));
+    }
+
+    public void start() {
+        Thread t = new Thread(this);

Review comment:
       Good point. 
   Added the thread name.
   ```
   "FileWatcher-stormtest.keystore" #37 daemon prio=5 os_prio=0 
tid=0x00007f6039f51000 nid=0x7295 waiting on condition [0x00007f5fa3409000]
      java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000d05f7038> (a 
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at 
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at 
java.util.concurrent.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:492)
        at 
java.util.concurrent.LinkedBlockingDeque.take(LinkedBlockingDeque.java:680)
        at sun.nio.fs.AbstractWatchService.take(AbstractWatchService.java:118)
        at org.apache.storm.daemon.common.FileWatcher.run(FileWatcher.java:55)
        at java.lang.Thread.run(Thread.java:748)
   ```
   
   I didn't add the file's canonical name since it would be too long. But I am 
fine with short/long name. Please let me know which one you prefer




----------------------------------------------------------------
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.

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


Reply via email to