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

org.gridkit.jvmtool.stacktrace.LegacyStackReader Maven / Gradle / Ivy

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

import java.io.IOException;
import java.lang.Thread.State;

import org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent;
import org.gridkit.jvmtool.event.Event;
import org.gridkit.jvmtool.event.EventReader;
import org.gridkit.jvmtool.event.ShieldedEventReader;

public class LegacyStackReader implements StackTraceReader {

    private EventReader events;

    public LegacyStackReader(EventReader source) {
        events = new ShieldedEventReader(source, ThreadSnapshotEvent.class);
    }

    @Override
    public boolean isLoaded() {
        return events.hasNext();
    }

    @Override
    public long getThreadId() {
        return events.peekNext().threadId();
    }

    @Override
    public long getTimestamp() {
        return events.peekNext().timestamp();
    }

    @Override
    public String getThreadName() {
        return events.peekNext().threadName();
    }

    @Override
    public State getThreadState() {
        return events.peekNext().threadState();
    }

    @Override
    public CounterCollection getCounters() {
        return events.peekNext().counters();
    }

    @Override
    public StackTraceElement[] getTrace() {
        StackFrameList list = events.peekNext().stackTrace();
        if (list == null) {
            return null;
        }
        else {
            StackTraceElement[] strace = new StackTraceElement[list.depth()];
            for(int i = 0; i != strace.length; ++i) {
                strace[i] = list.frameAt(i).toStackTraceElement();
            }
            return strace;
        }
    }

    @Override
    public StackFrameList getStackTrace() {
        return events.peekNext().stackTrace();
    }

    @Override
    public boolean loadNext() throws IOException {
        if (events.hasNext()) {
            events.next();
        }
        return events.hasNext();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy