src/jdk.jfr/share/classes/jdk/jfr/Recording.java
changeset 50745 a390cbb82d47
parent 50113 caf115bb98ad
child 53016 9f13f8aad8dc
equal deleted inserted replaced
50744:6c306d54366d 50745:a390cbb82d47
    29 import java.io.IOException;
    29 import java.io.IOException;
    30 import java.io.InputStream;
    30 import java.io.InputStream;
    31 import java.nio.file.Path;
    31 import java.nio.file.Path;
    32 import java.time.Duration;
    32 import java.time.Duration;
    33 import java.time.Instant;
    33 import java.time.Instant;
    34 import java.util.Collections;
       
    35 import java.util.HashMap;
    34 import java.util.HashMap;
    36 import java.util.Map;
    35 import java.util.Map;
    37 import java.util.Objects;
    36 import java.util.Objects;
    38 
    37 
       
    38 import jdk.jfr.internal.PlatformRecorder;
    39 import jdk.jfr.internal.PlatformRecording;
    39 import jdk.jfr.internal.PlatformRecording;
    40 import jdk.jfr.internal.Type;
    40 import jdk.jfr.internal.Type;
    41 import jdk.jfr.internal.Utils;
    41 import jdk.jfr.internal.Utils;
    42 import jdk.jfr.internal.WriteableUserPath;
    42 import jdk.jfr.internal.WriteableUserPath;
    43 
    43 
    91         }
    91         }
    92     }
    92     }
    93 
    93 
    94     private final PlatformRecording internal;
    94     private final PlatformRecording internal;
    95 
    95 
    96     private Recording(PlatformRecording internal) {
    96     public Recording(Map<String, String> settings) {
    97         this.internal = internal;
    97         PlatformRecorder r = FlightRecorder.getFlightRecorder().getInternal();
    98         this.internal.setRecording(this);
    98         synchronized (r) {
    99         if (internal.getRecording() != this) {
    99             this.internal = r.newRecording(settings);
   100             throw new InternalError("Internal recording not properly setup");
   100             this.internal.setRecording(this);
       
   101             if (internal.getRecording() != this) {
       
   102                 throw new InternalError("Internal recording not properly setup");
       
   103             }
   101         }
   104         }
   102     }
   105     }
   103 
   106 
   104     /**
   107     /**
   105      * Creates a recording without any settings.
   108      * Creates a recording without any settings.
   113      *
   116      *
   114      * @throws SecurityException If a security manager is used and
   117      * @throws SecurityException If a security manager is used and
   115      *         FlightRecorderPermission "accessFlightRecorder" is not set.
   118      *         FlightRecorderPermission "accessFlightRecorder" is not set.
   116      */
   119      */
   117     public Recording() {
   120     public Recording() {
   118         this(FlightRecorder.getFlightRecorder().newInternalRecording(new HashMap<String, String>()));
   121         this(new HashMap<String, String>());
   119     }
   122      }
   120 
   123 
   121     /**
   124     /**
   122      * Creates a recording with settings from a configuration.
   125      * Creates a recording with settings from a configuration.
   123      * <p>
   126      * <p>
   124      * The following example shows how create a recording that uses a predefined configuration.
   127      * The following example shows how create a recording that uses a predefined configuration.
   143      *         FlightRecorderPermission "accessFlightRecorder" is not set.
   146      *         FlightRecorderPermission "accessFlightRecorder" is not set.
   144      *
   147      *
   145      * @see Configuration
   148      * @see Configuration
   146      */
   149      */
   147     public Recording(Configuration configuration) {
   150     public Recording(Configuration configuration) {
   148         this(FlightRecorder.getFlightRecorder().newInternalRecording(configuration.getSettings()));
   151         this(configuration.getSettings());
   149     }
   152     }
   150 
   153 
   151     /**
   154     /**
   152      * Starts this recording.
   155      * Starts this recording.
   153      * <p>
   156      * <p>
   368      * @throws SecurityException if a security manager exists and the caller doesn't
   371      * @throws SecurityException if a security manager exists and the caller doesn't
   369      *         have {@code FilePermission} to write to the destination path
   372      *         have {@code FilePermission} to write to the destination path
   370      */
   373      */
   371     public void dump(Path destination) throws IOException {
   374     public void dump(Path destination) throws IOException {
   372         Objects.requireNonNull(destination);
   375         Objects.requireNonNull(destination);
   373         internal.copyTo(new WriteableUserPath(destination), "Dumped by user", Collections.emptyMap());
   376         internal.dump(new WriteableUserPath(destination));
       
   377 
   374     }
   378     }
   375 
   379 
   376     /**
   380     /**
   377      * Returns {@code true} if this recording uses the disk repository, {@code false} otherwise.
   381      * Returns {@code true} if this recording uses the disk repository, {@code false} otherwise.
   378      * <p>
   382      * <p>