All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gridkit.jvmtool.stacktrace.codec.json.JfrEventReader Maven / Gradle / Ivy

There is a newer version: 0.23
Show newest version
package org.gridkit.jvmtool.stacktrace.codec.json;

import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;

import org.gridkit.jvmtool.event.CommonEvent;
import org.gridkit.jvmtool.event.Event;
import org.gridkit.jvmtool.event.EventMorpher;
import org.gridkit.jvmtool.event.EventReader;
import org.gridkit.jvmtool.event.MorphingEventReader;
import org.gridkit.jvmtool.spi.parsers.JsonEventSource;

public class JfrEventReader implements EventReader {

	private final JsonEventSource source;
	private final JsonEventAdapter adapter;
	private CommonEvent next;
	
	public JfrEventReader(JsonEventSource source, JsonEventAdapter adapter) {
		this.source = source;
		this.adapter = adapter;
	}
	
	@Override
	public boolean hasNext() {
		try {
			if (next == null) {
				next = adapter.parseNextEvent(source);
			}
			return next != null;
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public CommonEvent next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		CommonEvent e = next;
		next = null;
		return e;
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException();		
	}

	@Override
	public Iterator iterator() {
		return this;
	}

	@Override
	public  EventReader morph(EventMorpher morpher) {
		return MorphingEventReader.morph(this, morpher);
	}

	@Override
	public CommonEvent peekNext() {
		return next;
	}

	@Override
	public void dispose() {
		// TODO
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy