src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RepositoryFiles.java
branchJEP-349-branch
changeset 57946 b77540d274f9
parent 57920 de358b994ad9
child 58197 0ef79bd7fb5c
equal deleted inserted replaced
57944:f1610739fe86 57946:b77540d274f9
    31 import java.util.Collections;
    31 import java.util.Collections;
    32 import java.util.HashMap;
    32 import java.util.HashMap;
    33 import java.util.HashSet;
    33 import java.util.HashSet;
    34 import java.util.List;
    34 import java.util.List;
    35 import java.util.Map;
    35 import java.util.Map;
    36 import java.util.Map.Entry;
       
    37 import java.util.NavigableMap;
    36 import java.util.NavigableMap;
    38 import java.util.Set;
    37 import java.util.Set;
    39 import java.util.SortedMap;
    38 import java.util.SortedMap;
    40 import java.util.TreeMap;
    39 import java.util.TreeMap;
    41 
    40 
    44 import jdk.jfr.internal.Logger;
    43 import jdk.jfr.internal.Logger;
    45 import jdk.jfr.internal.Repository;
    44 import jdk.jfr.internal.Repository;
    46 import jdk.jfr.internal.SecuritySupport.SafePath;
    45 import jdk.jfr.internal.SecuritySupport.SafePath;
    47 
    46 
    48 public final class RepositoryFiles {
    47 public final class RepositoryFiles {
       
    48     private static final Object WAIT_OBJECT = new Object();
       
    49     public static void notifyNewFile() {
       
    50         synchronized (WAIT_OBJECT) {
       
    51             WAIT_OBJECT.notifyAll();
       
    52         }
       
    53     }
       
    54 
    49     private final FileAccess fileAccess;
    55     private final FileAccess fileAccess;
    50     private final NavigableMap<Long, Path> pathSet = new TreeMap<>();
    56     private final NavigableMap<Long, Path> pathSet = new TreeMap<>();
    51     private final Map<Path, Long> pathLookup = new HashMap<>();
    57     private final Map<Path, Long> pathLookup = new HashMap<>();
    52     private final Path repository;
    58     private final Path repository;
    53     private volatile boolean closed;
    59     private volatile boolean closed;
       
    60     private final Object waitObject;
    54 
    61 
    55     public RepositoryFiles(FileAccess fileAccess, Path repository) {
    62     public RepositoryFiles(FileAccess fileAccess, Path repository) {
    56         this.repository = repository;
    63         this.repository = repository;
    57         this.fileAccess = fileAccess;
    64         this.fileAccess = fileAccess;
       
    65         this.waitObject = repository == null ? WAIT_OBJECT : new Object();
    58     }
    66     }
    59 
    67 
    60     public long getTimestamp(Path p) {
    68     public long getTimestamp(Path p) {
    61         return pathLookup.get(p);
    69         return pathLookup.get(p);
    62     }
    70     }
   121         }
   129         }
   122     }
   130     }
   123 
   131 
   124     private void nap() {
   132     private void nap() {
   125         try {
   133         try {
   126             synchronized (pathSet) {
   134             synchronized (waitObject) {
   127                 pathSet.wait(1000);
   135                 waitObject.wait(1000);
   128             }
   136             }
   129         } catch (InterruptedException e) {
   137         } catch (InterruptedException e) {
   130             // ignore
   138             // ignore
   131         }
   139         }
   132     }
   140     }
   191             return c.getStartNanos();
   199             return c.getStartNanos();
   192         }
   200         }
   193     }
   201     }
   194 
   202 
   195     public void close() {
   203     public void close() {
   196         synchronized (pathSet) {
   204         synchronized (waitObject) {
   197             this.closed = true;
   205             this.closed = true;
   198             pathSet.notify();
   206             waitObject.notify();
   199         }
   207         }
   200     }
   208     }
   201 
       
   202 }
   209 }