src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java
branchJEP-349-branch
changeset 58152 ed7e71dd188b
parent 58145 bc54ed8d908a
child 58180 0a8943b4d0dd
equal deleted inserted replaced
58151:7fd5766202ab 58152:ed7e71dd188b
    84  * exception in an error handler. An error handler can be registered using the
    84  * exception in an error handler. An error handler can be registered using the
    85  * {@link #onError(Runnable)} method. If no error handler is registered, the
    85  * {@link #onError(Runnable)} method. If no error handler is registered, the
    86  * default behavior is to print the exception and its backtrace to the standard
    86  * default behavior is to print the exception and its backtrace to the standard
    87  * error stream.
    87  * error stream.
    88  * <p>
    88  * <p>
    89  * The following example demonstrates how an {@code EventStream} can be used to
    89  * The following example shows how an {@code EventStream} can be used to
    90  * listen to garbage collection and CPU Load events
    90  * listen to events on a JVM running Flight Recorder
    91  * <p>
    91  * <pre>
       
    92  * <code>
       
    93  * try (EventStream es = EventStream.openRepository()) {
       
    94  *   es.onEvent("jdk.CPULoad", event -> {
       
    95  *     System.out.println("CPU Load " + event.getEndTime());
       
    96  *     System.out.println(" Machine total: " + 100 * event.getFloat("machineTotal") + "%");
       
    97  *     System.out.println(" JVM User: " + 100 * event.getFloat("jvmUser") + "%");
       
    98  *     System.out.println(" JVM System: " + 100 * event.getFloat("jvmSystem") + "%");
       
    99  *     System.out.println();
       
   100  *     System.gc();
       
   101  *   });
       
   102  *   es.onEvent("jdk.GarbageCollection", event -> {
       
   103  *     System.out.println("Garbage collection: " + event.getLong("gcId"));
       
   104  *     System.out.println(" Cause: " + event.getString("cause"));
       
   105  *     System.out.println(" Total pause: " + event.getDuration("sumOfPauses"));
       
   106  *     System.out.println(" Longest pause: " + event.getDuration("longestPause"));
       
   107  *     System.out.println();
       
   108  *   });
       
   109  *   es.start();
       
   110  * }
       
   111  * </code>
       
   112  * </pre>
       
   113  * <p>
       
   114  * To start recording together with the stream, see {@link RecordingStream}.
    92  *
   115  *
    93  */
   116  */
    94 public interface EventStream extends AutoCloseable {
   117 public interface EventStream extends AutoCloseable {
    95 
       
    96     /**
   118     /**
    97      * Creates a stream from the repository of the current Java Virtual Machine
   119      * Creates a stream from the repository of the current Java Virtual Machine
    98      * (JVM).
   120      * (JVM).
    99      * <p>
   121      * <p>
   100      * By default, the stream starts with the next event flushed by Flight
   122      * By default, the stream starts with the next event flushed by Flight