Add mechanism för new file notification JEP-349-branch
authoregahlin
Thu, 29 Aug 2019 19:30:32 +0200
branchJEP-349-branch
changeset 57946 b77540d274f9
parent 57944 f1610739fe86
child 57947 5c8039344562
Add mechanism för new file notification
src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataRepository.java
src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RepositoryFiles.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataRepository.java	Thu Aug 29 19:00:41 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataRepository.java	Thu Aug 29 19:30:32 2019 +0200
@@ -46,6 +46,7 @@
 import jdk.jfr.Threshold;
 import jdk.jfr.ValueDescriptor;
 import jdk.jfr.internal.RequestEngine.RequestHook;
+import jdk.jfr.internal.consumer.RepositoryFiles;
 import jdk.jfr.internal.handlers.EventHandler;
 
 public final class MetadataRepository {
@@ -267,7 +268,9 @@
     // to storeDescriptorInJVM
     synchronized void setOutput(String filename) {
         jvm.setOutput(filename);
-        Utils.notifyFlush();
+        if (filename != null) {
+            RepositoryFiles.notifyNewFile();
+        }
         flushMetadata = false;
         unregisterUnloaded();
         if (unregistered) {
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RepositoryFiles.java	Thu Aug 29 19:00:41 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RepositoryFiles.java	Thu Aug 29 19:30:32 2019 +0200
@@ -33,7 +33,6 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.NavigableMap;
 import java.util.Set;
 import java.util.SortedMap;
@@ -46,15 +45,24 @@
 import jdk.jfr.internal.SecuritySupport.SafePath;
 
 public final class RepositoryFiles {
+    private static final Object WAIT_OBJECT = new Object();
+    public static void notifyNewFile() {
+        synchronized (WAIT_OBJECT) {
+            WAIT_OBJECT.notifyAll();
+        }
+    }
+
     private final FileAccess fileAccess;
     private final NavigableMap<Long, Path> pathSet = new TreeMap<>();
     private final Map<Path, Long> pathLookup = new HashMap<>();
     private final Path repository;
     private volatile boolean closed;
+    private final Object waitObject;
 
     public RepositoryFiles(FileAccess fileAccess, Path repository) {
         this.repository = repository;
         this.fileAccess = fileAccess;
+        this.waitObject = repository == null ? WAIT_OBJECT : new Object();
     }
 
     public long getTimestamp(Path p) {
@@ -123,8 +131,8 @@
 
     private void nap() {
         try {
-            synchronized (pathSet) {
-                pathSet.wait(1000);
+            synchronized (waitObject) {
+                waitObject.wait(1000);
             }
         } catch (InterruptedException e) {
             // ignore
@@ -193,10 +201,9 @@
     }
 
     public void close() {
-        synchronized (pathSet) {
+        synchronized (waitObject) {
             this.closed = true;
-            pathSet.notify();
+            waitObject.notify();
         }
     }
-
-}
\ No newline at end of file
+}