APIdia Launch Partner
Top Fields Constructors Methods
jdk.jfr.internal.consumer

public abstract Class AbstractEventStream

extends Object
implements EventStream
Class Inheritance
All Implemented Interfaces
jdk.jfr.consumer.EventStream, java.lang.AutoCloseable
Known Direct Subclasses
jdk.jfr.internal.consumer.EventDirectoryStream, jdk.jfr.internal.consumer.EventFileStream
Imports
java.io.IOException, java.time.Duration, .Instant, java.util.List, .Objects, java.util.concurrent.CountDownLatch, .TimeUnit, java.util.concurrent.atomic.AtomicLong, java.util.function.Consumer, jdk.jfr.Configuration, .EventType, jdk.jfr.consumer.EventStream, .MetadataEvent, .RecordedEvent, jdk.jfr.internal.LogLevel, .LogTag, .Logger

Field Summary

Modifier and TypeField and Description
private volatile boolean
private final List<Configuration>
private static final AtomicLong
private boolean
private Dispatcher
private final Runnable
private final ParserState
private final StreamConfiguration
private final CountDownLatch
private volatile boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public final void
awaitTermination()

Implements jdk.jfr.consumer.EventStream.awaitTermination.

Blocks until all actions are completed, or the stream is closed, or the current thread is interrupted, whichever happens first.

public final void
awaitTermination(Duration timeout)

Implements jdk.jfr.consumer.EventStream.awaitTermination.

Blocks until all actions are completed, or the stream is closed, or the timeout occurs, or the current thread is interrupted, whichever happens first.

public abstract void
close()

Redeclares jdk.jfr.consumer.EventStream.close.

Releases all resources associated with this stream.

protected final void
protected final Dispatcher
private void
protected final Runnable
protected final boolean
protected final boolean
protected abstract boolean
private String
public final void
onClose(Runnable action)

Implements jdk.jfr.consumer.EventStream.onClose.

Registers an action to perform when the stream is closed.

public final void
onError(Consumer<Throwable> action)

Implements jdk.jfr.consumer.EventStream.onError.

Registers an action to perform if an exception occurs.

public final void
onEvent(Consumer<RecordedEvent> action)

Implements jdk.jfr.consumer.EventStream.onEvent.

Registers an action to perform on all events in the stream.

public final void
onEvent(String eventName, Consumer<RecordedEvent> action)

Implements jdk.jfr.consumer.EventStream.onEvent.

Registers an action to perform on all events matching a name.

public final void
onFlush(Runnable action)

Implements jdk.jfr.consumer.EventStream.onFlush.

Registers an action to perform after the stream has been flushed.

protected final void
public void
onMetadata(Consumer<MetadataEvent> action)

Overrides default jdk.jfr.consumer.EventStream.onMetadata.

Registers an action to perform when new metadata arrives in the stream.

protected final void
protected final ParserState
protected abstract void
public final boolean
remove(Object action)

Implements jdk.jfr.consumer.EventStream.remove.

Unregisters an action.

public final void
setCloseOnComplete(boolean closeOnComplete)

public final void
setDaemon(boolean daemon)

public final void
setEndTime(Instant endTime)

Implements jdk.jfr.consumer.EventStream.setEndTime.

Specifies the end time of the stream.

public final void
setOrdered(boolean ordered)

Implements jdk.jfr.consumer.EventStream.setOrdered.

Specifies that events arrive in chronological order, sorted by the time they were committed to the stream.

public final void
setReuse(boolean reuse)

Implements jdk.jfr.consumer.EventStream.setReuse.

Specifies that the event object in an onEvent(Consumer) action can be reused.

public final void
setStartTime(Instant startTime)

Implements jdk.jfr.consumer.EventStream.setStartTime.

Specifies the start time of the stream.

public final void
setWaitForChunks(boolean wait)

public abstract void
start()

Redeclares jdk.jfr.consumer.EventStream.start.

Starts processing of actions.

public final void
start(long startNanos)

public abstract void
startAsync()

Redeclares jdk.jfr.consumer.EventStream.startAsync.

Starts asynchronous processing of actions.

public final void
startAsync(long startNanos)

private void
startInternal(long startNanos)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closeOnCompleteback to summary
private volatile boolean closeOnComplete
configurationsback to summary
private final List<Configuration> configurations
counterback to summary
private static final AtomicLong counter
daemonback to summary
private boolean daemon
dispatcherback to summary
private Dispatcher dispatcher
flushOperationback to summary
private final Runnable flushOperation
parserStateback to summary
private final ParserState parserState
streamConfigurationback to summary
private final StreamConfiguration streamConfiguration
terminatedback to summary
private final CountDownLatch terminated
waitForChunksback to summary
private volatile boolean waitForChunks

Constructor Detail

AbstractEventStreamback to summary
pack-priv AbstractEventStream(List<Configuration> configurations) throws IOException

Method Detail

awaitTerminationback to summary
public final void awaitTermination() throws InterruptedException

Implements jdk.jfr.consumer.EventStream.awaitTermination.

Doc from jdk.jfr.consumer.EventStream.awaitTermination.

Blocks until all actions are completed, or the stream is closed, or the current thread is interrupted, whichever happens first.

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
awaitTerminationback to summary
public final void awaitTermination(Duration timeout) throws InterruptedException

Implements jdk.jfr.consumer.EventStream.awaitTermination.

Doc from jdk.jfr.consumer.EventStream.awaitTermination.

Blocks until all actions are completed, or the stream is closed, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
closeback to summary
public abstract void close()

Redeclares jdk.jfr.consumer.EventStream.close.

Doc from jdk.jfr.consumer.EventStream.close.

Releases all resources associated with this stream.

If a stream is started, asynchronously or synchronously, it is stopped immediately or after the next flush. This method does NOT guarantee that all registered actions are completed before return.

Closing a previously closed stream has no effect.

Annotations
@Override
closeParserback to summary
protected final void closeParser()
dispatcherback to summary
protected final Dispatcher dispatcher()
executeback to summary
private void execute()
getFlushOperationback to summary
protected final Runnable getFlushOperation()
getWaitForChunksback to summary
protected final boolean getWaitForChunks()
isClosedback to summary
protected final boolean isClosed()
isRecordingStreamback to summary
protected abstract boolean isRecordingStream()
nextThreadNameback to summary
private String nextThreadName()
onCloseback to summary
public final void onClose(Runnable action)

Implements jdk.jfr.consumer.EventStream.onClose.

Doc from jdk.jfr.consumer.EventStream.onClose.

Registers an action to perform when the stream is closed.

If the stream is already closed, the action will be performed immediately in the current thread.

Annotations
@Override
onErrorback to summary
public final void onError(Consumer<Throwable> action)

Implements jdk.jfr.consumer.EventStream.onError.

Doc from jdk.jfr.consumer.EventStream.onError.

Registers an action to perform if an exception occurs.

If an action is not registered, an exception stack trace is printed to standard error.

Registering an action overrides the default behavior. If multiple actions have been registered, they are performed in the order of registration.

If this method itself throws an exception, resulting behavior is undefined.

Annotations
@Override
onEventback to summary
public final void onEvent(Consumer<RecordedEvent> action)

Implements jdk.jfr.consumer.EventStream.onEvent.

Doc from jdk.jfr.consumer.EventStream.onEvent.

Registers an action to perform on all events in the stream.

To perform an action on a subset of event types, consider using onEvent(String, Consumer) and onMetadata(Consumer) as it is likely more performant than any selection or filtering mechanism implemented in a generic action.

Annotations
@Override
onEventback to summary
public final void onEvent(String eventName, Consumer<RecordedEvent> action)

Implements jdk.jfr.consumer.EventStream.onEvent.

Doc from jdk.jfr.consumer.EventStream.onEvent.

Registers an action to perform on all events matching a name.

Annotations
@Override
onFlushback to summary
public final void onFlush(Runnable action)

Implements jdk.jfr.consumer.EventStream.onFlush.

Doc from jdk.jfr.consumer.EventStream.onFlush.

Registers an action to perform after the stream has been flushed.

Annotations
@Override
onFlushback to summary
protected final void onFlush()
onMetadataback to summary
public void onMetadata(Consumer<MetadataEvent> action)

Overrides default jdk.jfr.consumer.EventStream.onMetadata.

Doc from jdk.jfr.consumer.EventStream.onMetadata.

Registers an action to perform when new metadata arrives in the stream. The event type of an event always arrives sometime before the actual event. The action must be registered before the stream is started.

The following example shows how to listen to new event types, register an action if the event type name matches a regular expression and increase a counter if a matching event is found. A benefit of using an action per event type, instead of the generic onEvent(Consumer) method, is that a stream implementation can avoid reading events that are of no interest.

static long count = 0; public static void main(String... args) throws IOException { Path file = Path.of(args[0]); String regExp = args[1]; var pr = Pattern.compile(regExp).asMatchPredicate(); try (var s = EventStream.openFile(file)) { s.setOrdered(false); s.onMetadata(metadata -> metadata.getAddedEventTypes() .stream().map(EventType::getName).filter(pr) .forEach(eventName -> s.onEvent(eventName, event -> count++))); s.start(); System.out.println(count + " events matches " + regExp); } }
static long count = 0;
public static void main(String... args) throws IOException {
    Path file = Path.of(args[0]);
    String regExp = args[1];
    var pr = Pattern.compile(regExp).asMatchPredicate();
    try (var s = EventStream.openFile(file)) {
        s.setOrdered(false);
        s.onMetadata(metadata -> metadata.getAddedEventTypes()
         .stream().map(EventType::getName).filter(pr)
         .forEach(eventName -> s.onEvent(eventName, event -> count++)));
        s.start();
        System.out.println(count + " events matches " + regExp);
    }
}
Annotations
@Override
onMetadataback to summary
protected final void onMetadata(ChunkParser parser)
parserStateback to summary
protected final ParserState parserState()
processback to summary
protected abstract void process() throws IOException
removeback to summary
public final boolean remove(Object action)

Implements jdk.jfr.consumer.EventStream.remove.

Doc from jdk.jfr.consumer.EventStream.remove.

Unregisters an action.

If the action has been registered multiple times, all instances are unregistered.

Annotations
@Override
setCloseOnCompleteback to summary
public final void setCloseOnComplete(boolean closeOnComplete)
setDaemonback to summary
public final void setDaemon(boolean daemon)
setEndTimeback to summary
public final void setEndTime(Instant endTime)

Implements jdk.jfr.consumer.EventStream.setEndTime.

Doc from jdk.jfr.consumer.EventStream.setEndTime.

Specifies the end time of the stream.

The end time must be set before starting the stream.

At end time, the stream is closed.

Annotations
@Override
setOrderedback to summary
public final void setOrdered(boolean ordered)

Implements jdk.jfr.consumer.EventStream.setOrdered.

Doc from jdk.jfr.consumer.EventStream.setOrdered.

Specifies that events arrive in chronological order, sorted by the time they were committed to the stream.

Annotations
@Override
setReuseback to summary
public final void setReuse(boolean reuse)

Implements jdk.jfr.consumer.EventStream.setReuse.

Doc from jdk.jfr.consumer.EventStream.setReuse.

Specifies that the event object in an onEvent(Consumer) action can be reused.

If reuse is set to true, an action should not keep a reference to the event object after the action has completed.

Annotations
@Override
setStartTimeback to summary
public final void setStartTime(Instant startTime)

Implements jdk.jfr.consumer.EventStream.setStartTime.

Doc from jdk.jfr.consumer.EventStream.setStartTime.

Specifies the start time of the stream.

The start time must be set before starting the stream

Annotations
@Override
setWaitForChunksback to summary
public final void setWaitForChunks(boolean wait)
startback to summary
public abstract void start()

Redeclares jdk.jfr.consumer.EventStream.start.

Doc from jdk.jfr.consumer.EventStream.start.

Starts processing of actions.

Actions are performed in the current thread.

To stop the stream, use the close() method.

Annotations
@Override
startback to summary
public final void start(long startNanos)
startAsyncback to summary
public abstract void startAsync()

Redeclares jdk.jfr.consumer.EventStream.startAsync.

Doc from jdk.jfr.consumer.EventStream.startAsync.

Starts asynchronous processing of actions.

Actions are performed in a single separate thread.

To stop the stream, use the close() method.

Annotations
@Override
startAsyncback to summary
public final void startAsync(long startNanos)
startInternalback to summary
private void startInternal(long startNanos)