org.apache.oozie.util
Class TimestampedMessageParser

java.lang.Object
  extended by org.apache.oozie.util.TimestampedMessageParser
Direct Known Subclasses:
HDFSTimestampedMessageParser, SimpleTimestampedMessageParser

public class TimestampedMessageParser
extends Object

Encapsulates the parsing and filtering of the log messages from a BufferedReader. It makes sure not to read in the entire log into memory at the same time; at most, it will have two messages (which can be multi-line in the case of exception stack traces).

To use this class: Calling increment() will tell the parser to read the next message from the Reader. It will return true if there are more messages and false if not. Calling getLastMessage() and getLastTimestamp() will return the last message and timestamp, respectively, that were parsed when increment() was called. Calling processRemaining(java.io.Writer) will write the remaining log messages to the given Writer.


Field Summary
 int count
           
protected  BufferedReader reader
           
 
Constructor Summary
TimestampedMessageParser(BufferedReader reader, XLogFilter filter)
          Creates a TimestampedMessageParser with the given BufferedReader and filter.
 
Method Summary
 void closeReader()
          Closes the Reader.
 String getLastMessage()
          Returns the message that was last parsed.
 String getLastTimestamp()
          Returns the timestamp from the last message that was parsed.
 boolean increment()
          Causes the next message and timestamp to be parsed from the BufferedReader.
protected  String parseNextLine()
          Reads the next line from the Reader and checks if it matches the filter.
 void processRemaining(Writer writer)
          Streams log messages to the passed in Writer, with default buffer len 4K and zero bytes already written
 void processRemaining(Writer writer, int bufferLen)
          Streams log messages to the passed in Writer, with zero bytes already written
 void processRemaining(Writer writer, int bufferLen, int bytesWritten)
          Streams log messages to the passed in Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reader

protected BufferedReader reader

count

public int count
Constructor Detail

TimestampedMessageParser

public TimestampedMessageParser(BufferedReader reader,
                                XLogFilter filter)
Creates a TimestampedMessageParser with the given BufferedReader and filter.

Parameters:
reader - The BufferedReader to get the log messages from
filter - The filter
Method Detail

increment

public boolean increment()
                  throws IOException
Causes the next message and timestamp to be parsed from the BufferedReader.

Returns:
true if there are more messages left; false if not
Throws:
IOException - If there was a problem reading from the Reader

getLastTimestamp

public String getLastTimestamp()
Returns the timestamp from the last message that was parsed.

Returns:
the timestamp from the last message that was parsed

getLastMessage

public String getLastMessage()
Returns the message that was last parsed.

Returns:
the message that was last parsed

closeReader

public void closeReader()
                 throws IOException
Closes the Reader.

Throws:
IOException

parseNextLine

protected String parseNextLine()
                        throws IOException
Reads the next line from the Reader and checks if it matches the filter. It can also handle multi-line messages (i.e. exception stack traces). If it returns null, then there are no lines left in the Reader.

Returns:
The next line, or null
Throws:
IOException

processRemaining

public void processRemaining(Writer writer,
                             int bufferLen,
                             int bytesWritten)
                      throws IOException
Streams log messages to the passed in Writer. Flushes the log writing based on buffer len

Parameters:
writer -
bufferLen - maximum len of log buffer
bytesWritten - num bytes already written to writer
Throws:
IOException

processRemaining

public void processRemaining(Writer writer,
                             int bufferLen)
                      throws IOException
Streams log messages to the passed in Writer, with zero bytes already written

Parameters:
writer -
bufferLen - maximum len of log buffer
Throws:
IOException

processRemaining

public void processRemaining(Writer writer)
                      throws IOException
Streams log messages to the passed in Writer, with default buffer len 4K and zero bytes already written

Parameters:
writer -
Throws:
IOException


Copyright © 2015 Apache Software Foundation. All Rights Reserved.