8239584: EventStream::close should state that stream will be stopped

Reviewed-by: mgronlun, mseledtsov
This commit is contained in:
Erik Gahlin 2020-03-09 21:43:01 +01:00
parent 672992f6ac
commit f09cda2c70
2 changed files with 34 additions and 0 deletions

View File

@ -242,6 +242,10 @@ public interface EventStream extends AutoCloseable {
/**
* Releases all resources associated with this stream.
* <p>
* If a stream is started, asynchronously or synchronously, it is stopped
* immediately or after the next flush. This method does <em>NOT</em>
* guarantee that all registered actions are completed before return.
* <p>
* Closing a previously closed stream has no effect.
*/
void close();
@ -320,6 +324,8 @@ public interface EventStream extends AutoCloseable {
* Start processing of actions.
* <p>
* Actions are performed in the current thread.
* <p>
* To stop the stream, use the {@code #close()} method.
*
* @throws IllegalStateException if the stream is already started or closed
*/
@ -329,6 +335,8 @@ public interface EventStream extends AutoCloseable {
* Start asynchronous processing of actions.
* <p>
* Actions are performed in a single separate thread.
* <p>
* To stop the stream, use the {@code #close()} method.
*
* @throws IllegalStateException if the stream is already started or closed
*/

View File

@ -329,6 +329,32 @@ public final class RecordingStream implements AutoCloseable, EventStream {
directoryStream.start(startNanos);
}
/**
* Start asynchronous processing of actions.
* <p>
* Actions are performed in a single separate thread.
* <p>
* To stop the stream, use the {@code #close()} method.
* <p>
* The following example prints the CPU usage for ten seconds. When
* the current thread leaves the try-with-resources block the
* stream is stopped/closed.
* <pre>
* <code>
* try (var stream = new RecordingStream()) {
* stream.enable("jdk.CPULoad").withPeriod(Duration.ofSeconds(1));
* stream.onEvent("jdk.CPULoad", event -> {
* System.out.println(event);
* });
* stream.startAsync();
* Thread.sleep(10_000);
* }
* </code>
* </pre>
*
* @throws IllegalStateException if the stream is already started or closed
*
*/
@Override
public void startAsync() {
PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);