equal
deleted
inserted
replaced
27 |
27 |
28 import java.io.IOException; |
28 import java.io.IOException; |
29 import java.security.AccessControlContext; |
29 import java.security.AccessControlContext; |
30 import java.security.AccessController; |
30 import java.security.AccessController; |
31 import java.time.Duration; |
31 import java.time.Duration; |
|
32 import java.time.Instant; |
32 import java.util.Map; |
33 import java.util.Map; |
33 import java.util.function.Consumer; |
34 import java.util.function.Consumer; |
34 |
35 |
35 import jdk.jfr.Configuration; |
36 import jdk.jfr.Configuration; |
36 import jdk.jfr.Event; |
37 import jdk.jfr.Event; |
40 import jdk.jfr.internal.PlatformRecording; |
41 import jdk.jfr.internal.PlatformRecording; |
41 import jdk.jfr.internal.PrivateAccess; |
42 import jdk.jfr.internal.PrivateAccess; |
42 import jdk.jfr.internal.Utils; |
43 import jdk.jfr.internal.Utils; |
43 |
44 |
44 /** |
45 /** |
45 * An event stream produces events from a file, directory or a running JVM (Java |
46 * An recording stream produces events from a running JVM (Java Virtual |
46 * Virtual Machine). |
47 * Machine). |
47 */ |
48 */ |
48 public class RecordingStream implements AutoCloseable, EventStream { |
49 public class RecordingStream implements AutoCloseable, EventStream { |
49 |
50 |
50 private final Recording recording; |
51 private final Recording recording; |
51 private final EventDirectoryStream stream; |
52 private final EventDirectoryStream stream; |
79 Utils.checkAccessFlightRecorder(); |
80 Utils.checkAccessFlightRecorder(); |
80 AccessControlContext acc = AccessController.getContext(); |
81 AccessControlContext acc = AccessController.getContext(); |
81 this.recording = new Recording(); |
82 this.recording = new Recording(); |
82 this.recording.setFlushInterval(Duration.ofMillis(1000)); |
83 this.recording.setFlushInterval(Duration.ofMillis(1000)); |
83 try { |
84 try { |
84 this.stream = new EventDirectoryStream(acc, null); |
85 this.stream = new EventDirectoryStream(acc, null, null); |
85 } catch (IOException ioe) { |
86 } catch (IOException ioe) { |
86 throw new IllegalStateException(ioe.getMessage()); |
87 throw new IllegalStateException(ioe.getMessage()); |
87 } |
88 } |
88 } |
89 } |
89 |
90 |
154 * </pre> |
155 * </pre> |
155 * |
156 * |
156 * The following example shows how to merge settings. |
157 * The following example shows how to merge settings. |
157 * |
158 * |
158 * <pre> |
159 * <pre> |
159 * {@code |
160 * { |
|
161 * @code |
160 * Map<String, String> settings = recording.getSettings(); |
162 * Map<String, String> settings = recording.getSettings(); |
161 * settings.putAll(additionalSettings); |
163 * settings.putAll(additionalSettings); |
162 * recordingStream.setSettings(settings); |
164 * recordingStream.setSettings(settings); |
163 * } |
165 * } |
164 * </pre> |
166 * </pre> |
212 * |
214 * |
213 */ |
215 */ |
214 public EventSettings disable(Class<? extends Event> eventClass) { |
216 public EventSettings disable(Class<? extends Event> eventClass) { |
215 return recording.disable(eventClass); |
217 return recording.disable(eventClass); |
216 } |
218 } |
217 /** |
219 |
218 * Determines how far back data is kept for the stream if the stream can't |
220 /** |
|
221 * Determines how far back data is kept for the stream, if the stream can't |
219 * keep up. |
222 * keep up. |
220 * <p> |
223 * <p> |
221 * To control the amount of recording data stored on disk, the maximum |
224 * To control the amount of recording data stored on disk, the maximum |
222 * length of time to retain the data can be specified. Data stored on disk |
225 * length of time to retain the data can be specified. Data stored on disk |
223 * that is older than the specified length of time is removed by the Java |
226 * that is older than the specified length of time is removed by the Java |
312 |
315 |
313 /** |
316 /** |
314 * Determines how often events are made available for streaming. |
317 * Determines how often events are made available for streaming. |
315 * |
318 * |
316 * @param interval the interval at which events are made available to the |
319 * @param interval the interval at which events are made available to the |
317 * stream |
320 * stream, no {@code null} |
318 * |
321 * |
319 * @throws IllegalArgumentException if <code>interval</code> is negative |
322 * @throws IllegalArgumentException if <code>interval</code> is negative |
320 * |
323 * |
321 * @throws IllegalStateException if the stream is closed |
324 * @throws IllegalStateException if the stream is closed |
322 */ |
325 */ |
336 |
339 |
337 @Override |
340 @Override |
338 public void setOrdered(boolean ordered) { |
341 public void setOrdered(boolean ordered) { |
339 stream.setOrdered(ordered); |
342 stream.setOrdered(ordered); |
340 } |
343 } |
|
344 |
|
345 @Override |
|
346 public void setStartTime(Instant startTime) { |
|
347 stream.setStartTime(startTime); |
|
348 } |
341 } |
349 } |