src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java
branchJEP-349-branch
changeset 58212 412d8e77f931
parent 58209 7993ced88081
child 58213 354c7790c548
equal deleted inserted replaced
58211:c4c0d44d1966 58212:412d8e77f931
    50  * To receive a notification when an event arrives, register an action using the
    50  * To receive a notification when an event arrives, register an action using the
    51  * {@link #onEvent(Consumer)} method. To filter the stream for an event with a
    51  * {@link #onEvent(Consumer)} method. To filter the stream for an event with a
    52  * specific name, use {@link #onEvent(String, Consumer)} method.
    52  * specific name, use {@link #onEvent(String, Consumer)} method.
    53  * <p>
    53  * <p>
    54  * By default, the same {@code RecordedEvent} object can be used for
    54  * By default, the same {@code RecordedEvent} object can be used for
    55  * representing two or more distinct events. The object can be delivered
    55  * representing two or more distinct events. That object can be delivered
    56  * multiple times to the same action as well as to other actions. If the life
    56  * multiple times to the same action as well as to other actions. To use an
    57  * span of the event object exceeds that of the action, the
    57  * event object after the action is completed, the
    58  * {@link #setReuse(boolean)} method should be set to {@code false} so that a
    58  * {@link #setReuse(boolean)} method should be set to {@code false} so a
    59  * new object is allocated for each event.
    59  * new object is allocated for each event.
    60  * <p>
    60  * <p>
    61  * Events are delivered in batches. To receive a notification when a batch is
    61  * Events are delivered in batches. To receive a notification when a batch is
    62  * complete, register an action using the {@link #onFlush(Runnable)} method.
    62  * complete, register an action using the {@link #onFlush(Runnable)} method.
    63  * This is an opportunity to aggregate or push data to external systems while
    63  * This is an opportunity to aggregate or push data to external systems while
    73  * <p>
    73  * <p>
    74  * To dispatch events to registered actions, the stream must be started. To
    74  * To dispatch events to registered actions, the stream must be started. To
    75  * start processing in the current thread, invoke the {@link #start()} method.
    75  * start processing in the current thread, invoke the {@link #start()} method.
    76  * To process actions asynchronously in a separate thread, invoke the
    76  * To process actions asynchronously in a separate thread, invoke the
    77  * {@link #startAsync()} method. To await completion of the stream, use the
    77  * {@link #startAsync()} method. To await completion of the stream, use the
    78  * awaitTermination {@link #awaitTermination()} or the {link
    78  * awaitTermination {@link #awaitTermination()} or the
    79  * {@link #awaitTermination(Duration)} method.
    79  * {@link #awaitTermination(Duration)} method.
    80  * <p>
    80  * <p>
    81  * When a stream ends it is automatically closed. To manually stop processing of
    81  * When a stream ends it is automatically closed. To manually stop processing of
    82  * events, close the stream by invoking the {@link #close()} method. A stream
    82  * events, close the stream by invoking the {@link #close()} method. A stream
    83  * can also be automatically closed in exceptional circumstances, for example if
    83  * can also be automatically closed in exceptional circumstances, for example if
   101  *     System.out.println("CPU Load " + event.getEndTime());
   101  *     System.out.println("CPU Load " + event.getEndTime());
   102  *     System.out.println(" Machine total: " + 100 * event.getFloat("machineTotal") + "%");
   102  *     System.out.println(" Machine total: " + 100 * event.getFloat("machineTotal") + "%");
   103  *     System.out.println(" JVM User: " + 100 * event.getFloat("jvmUser") + "%");
   103  *     System.out.println(" JVM User: " + 100 * event.getFloat("jvmUser") + "%");
   104  *     System.out.println(" JVM System: " + 100 * event.getFloat("jvmSystem") + "%");
   104  *     System.out.println(" JVM System: " + 100 * event.getFloat("jvmSystem") + "%");
   105  *     System.out.println();
   105  *     System.out.println();
   106  *     System.gc();
       
   107  *   });
   106  *   });
   108  *   es.onEvent("jdk.GarbageCollection", event -> {
   107  *   es.onEvent("jdk.GarbageCollection", event -> {
   109  *     System.out.println("Garbage collection: " + event.getLong("gcId"));
   108  *     System.out.println("Garbage collection: " + event.getLong("gcId"));
   110  *     System.out.println(" Cause: " + event.getString("cause"));
   109  *     System.out.println(" Cause: " + event.getString("cause"));
   111  *     System.out.println(" Total pause: " + event.getDuration("sumOfPauses"));
   110  *     System.out.println(" Total pause: " + event.getDuration("sumOfPauses"));