Search in sources :

Example 1 with ErrorHandler

use of org.gridkit.jvmtool.event.ErrorHandler in project jvm-tools by aragozin.

the class ThreadDumpSource method getUnclassifiedReader.

public EventReader<ThreadSnapshotEvent> getUnclassifiedReader() {
    if (files == null) {
        host.fail("No input files provided, used -f option");
    }
    final Iterator<String> it = files.iterator();
    ChainedEventReader<Event> reader = new ChainedEventReader<Event>() {

        @Override
        protected EventReader<Event> produceNext() {
            return it.hasNext() ? open(it.next()) : null;
        }

        private EventReader<Event> open(String next) {
            try {
                return ThreadEventCodec.createEventReader(new FileInputStream(next));
            } catch (IOException e) {
                return new SingleEventReader<Event>(new SimpleErrorEvent(e));
            }
        }
    };
    ShieldedEventReader<ThreadSnapshotEvent> shielderReader = new ShieldedEventReader<ThreadSnapshotEvent>(reader, ThreadSnapshotEvent.class, new ErrorHandler() {

        @Override
        public void onException(Exception e) {
            System.err.println("Stream reader error: " + e);
        }
    });
    return shielderReader;
}
Also used : ErrorHandler(org.gridkit.jvmtool.event.ErrorHandler) SimpleErrorEvent(org.gridkit.jvmtool.event.SimpleErrorEvent) IOException(java.io.IOException) ChainedEventReader(org.gridkit.jvmtool.event.ChainedEventReader) FileInputStream(java.io.FileInputStream) ParserException(org.gridkit.jvmtool.stacktrace.analytics.ParserException) IOException(java.io.IOException) ThreadSnapshotEvent(org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent) ShieldedEventReader(org.gridkit.jvmtool.event.ShieldedEventReader) SimpleErrorEvent(org.gridkit.jvmtool.event.SimpleErrorEvent) ThreadSnapshotEvent(org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent) Event(org.gridkit.jvmtool.event.Event)

Aggregations

FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ThreadSnapshotEvent (org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent)1 ChainedEventReader (org.gridkit.jvmtool.event.ChainedEventReader)1 ErrorHandler (org.gridkit.jvmtool.event.ErrorHandler)1 Event (org.gridkit.jvmtool.event.Event)1 ShieldedEventReader (org.gridkit.jvmtool.event.ShieldedEventReader)1 SimpleErrorEvent (org.gridkit.jvmtool.event.SimpleErrorEvent)1 ParserException (org.gridkit.jvmtool.stacktrace.analytics.ParserException)1