38 import jdk.jfr.consumer.EventStream; |
38 import jdk.jfr.consumer.EventStream; |
39 import jdk.jfr.consumer.RecordedEvent; |
39 import jdk.jfr.consumer.RecordedEvent; |
40 import jdk.jfr.internal.LogLevel; |
40 import jdk.jfr.internal.LogLevel; |
41 import jdk.jfr.internal.LogTag; |
41 import jdk.jfr.internal.LogTag; |
42 import jdk.jfr.internal.Logger; |
42 import jdk.jfr.internal.Logger; |
|
43 import jdk.jfr.internal.PlatformRecording; |
43 import jdk.jfr.internal.SecuritySupport; |
44 import jdk.jfr.internal.SecuritySupport; |
44 |
45 |
45 /* |
46 /* |
46 * Purpose of this class is to simplify the implementation of |
47 * Purpose of this class is to simplify the implementation of |
47 * an event stream. |
48 * an event stream. |
48 */ |
49 */ |
49 abstract class AbstractEventStream implements EventStream { |
50 abstract class AbstractEventStream implements EventStream { |
50 private final static AtomicLong counter = new AtomicLong(1); |
51 private final static AtomicLong counter = new AtomicLong(1); |
51 |
52 |
52 private final Object terminated = new Object(); |
53 private final Object terminated = new Object(); |
53 private final boolean active; |
|
54 private final Runnable flushOperation = () -> dispatcher().runFlushActions(); |
54 private final Runnable flushOperation = () -> dispatcher().runFlushActions(); |
55 private final AccessControlContext accessControllerContext; |
55 private final AccessControlContext accessControllerContext; |
56 private final StreamConfiguration configuration = new StreamConfiguration(); |
56 private final StreamConfiguration configuration = new StreamConfiguration(); |
|
57 private final PlatformRecording recording; |
57 |
58 |
58 private volatile Thread thread; |
59 private volatile Thread thread; |
59 private Dispatcher dispatcher; |
60 private Dispatcher dispatcher; |
60 |
61 |
61 private volatile boolean closed; |
62 private volatile boolean closed; |
62 |
63 |
63 AbstractEventStream(AccessControlContext acc, boolean active) throws IOException { |
64 AbstractEventStream(AccessControlContext acc, PlatformRecording recording) throws IOException { |
64 this.accessControllerContext = Objects.requireNonNull(acc); |
65 this.accessControllerContext = Objects.requireNonNull(acc); |
65 this.active = active; |
66 this.recording = recording; |
66 } |
67 } |
67 |
68 |
68 @Override |
69 @Override |
69 abstract public void start(); |
70 abstract public void start(); |
70 |
71 |
227 private void startInternal(long startNanos) { |
228 private void startInternal(long startNanos) { |
228 synchronized (configuration) { |
229 synchronized (configuration) { |
229 if (configuration.started) { |
230 if (configuration.started) { |
230 throw new IllegalStateException("Event stream can only be started once"); |
231 throw new IllegalStateException("Event stream can only be started once"); |
231 } |
232 } |
232 if (active && configuration.startTime == null) { |
233 if (recording != null && configuration.startTime == null) { |
233 configuration.setStartNanos(startNanos); |
234 configuration.setStartNanos(startNanos); |
234 } |
235 } |
235 configuration.setStarted(true); |
236 configuration.setStarted(true); |
236 } |
237 } |
237 } |
238 } |