net.logAnalyzer.handlers
Class AbstractLogHandler

java.lang.Object
  extended bynet.logAnalyzer.handlers.AbstractLogHandler
All Implemented Interfaces:
LALogHandler, java.lang.Runnable
Direct Known Subclasses:
ForwardOnlyLogHandler, MemoryLogHandler, OnDemandLogHandler

public abstract class AbstractLogHandler
extends java.lang.Object
implements LALogHandler

This class defines a template for log file handlers. A log file handler is used to apply filters and analyzers on a log file. Filters dans analyzers can be added before and/or after log file parsing.

Version:
0.1
Author:
Karim REFEYTON

Constructor Summary
AbstractLogHandler(FilesSetReader input, java.lang.String pattern)
          Constructs a log handler for the specified input files parsed with the specified converters.
 
Method Summary
 void addLogHandlerListener(LALogHandlerListener listener)
          Adds a listener.
 void fireEndParsing()
          Fires an end parsing event.
 void fireStartParsing()
          Fires a start parsing event.
 void fireStepParsing()
          Fires a step parsing event.
 LAAnalyzer[] getAnalyzers()
          Returns log analyzers added to the handler with setAnalyzers(LAAnalyzer[]).
 LAConverter getConverter(int index)
          Returns the converter at the specified index.
 LAConverter getConverter(java.lang.String literal)
          Returns the converter identified by the specified literal.
 int getConverterIndex(java.lang.String literal)
          Returns the index of the converter identified by the specified literal.
 LAConverter[] getConverters()
          Returns pattern converters.
protected  long getFileLength()
          Returns the length of the parsed file.
protected  long getFilePointer()
          Returns the current position in the parsed file.
 java.lang.Exception getLastException()
          Returns the last exception thrown by the parsing process.
 int getMaxRecords()
          Returns the number of records to parse; 0 for no limitation.
 LAMessage getMessage(int index)
          Returns the messageLabel at the specified position.
 LAConverter getMessageConverter()
          Returns the current messageLabel converter used to extend messageLabel text with unparsed lines.
 LAMessage[] getMessages(int start, int end)
          Returns the messages between specified positions.
 int getPercentDone()
          Returns the done percentage of the parsed file.
protected  FilesSetReader getReader()
          Returns the current reader.
abstract  int getSize()
          Returns the real number of messages in the log, not only in cache in case of a load on demand parsed log.
protected  void initParsing()
          Makes the intialization before parsing.
 boolean isParsing()
          Returns true if the handler is currently parsing the log.
protected abstract  LAMessage loadMessage(int index)
          Loads the messageLabel at the specified index.
 void parse()
          Parses the log content of the FilesSetReader returned by getReader().
protected  LAMessage parseMessage(java.lang.String message, LAConverter[] convertersToUse)
          Parses a string messageLabel in a LAMessageusing LAConverter.parse(StringBuffer, LALogHandler)method.
protected  java.lang.String readNextLine()
          Reads a line form the input.
protected  void releaseParsing()
          Makes the releases after parsing.
 void removeLogHandlerListener(LALogHandlerListener listener)
          Removes a listener.
 void run()
          Called by running the handler in a thread.
protected abstract  void saveMessage(LAMessage message, long pointer)
          Saves the messageLabel after parsing.
 void setAnalyzers(LAAnalyzer[] newAnalyzers)
          Adds new analyzers to the log handler.
 void setMaxRecords(int maxRecords)
          Number of records to parse; 0 for no limitation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractLogHandler

public AbstractLogHandler(FilesSetReader input,
                          java.lang.String pattern)
                   throws java.io.FileNotFoundException,
                          NoConverterException
Constructs a log handler for the specified input files parsed with the specified converters.

Parameters:
input - Log file(s) to parse.
pattern - Pattern used to parse file.
Throws:
NoConverterException - If no converter is specified.
java.io.FileNotFoundException - If file handled by input not found.
Method Detail

setAnalyzers

public final void setAnalyzers(LAAnalyzer[] newAnalyzers)
Adds new analyzers to the log handler.

Specified by:
setAnalyzers in interface LALogHandler
Parameters:
newAnalyzers - Analyzers to add.

getAnalyzers

public final LAAnalyzer[] getAnalyzers()
Returns log analyzers added to the handler with setAnalyzers(LAAnalyzer[]).

Specified by:
getAnalyzers in interface LALogHandler
Returns:
Log analyzers.

getConverters

public final LAConverter[] getConverters()
Returns pattern converters.

Specified by:
getConverters in interface LALogHandler
Returns:
Pattern converters.

getConverter

public final LAConverter getConverter(int index)
Returns the converter at the specified index.

Specified by:
getConverter in interface LALogHandler
Parameters:
index - Converter index.
Returns:
Converter or null if unknown.

getConverter

public final LAConverter getConverter(java.lang.String literal)
                               throws UnknownOrLiteralConverterException
Returns the converter identified by the specified literal.

Specified by:
getConverter in interface LALogHandler
Parameters:
literal - Converter literal.
Returns:
Converter or null if unknown.
Throws:
UnknownOrLiteralConverterException - If the literal does not identify a non literal converter.
See Also:
getConverter(int), getConverterIndex(String)

getConverterIndex

public final int getConverterIndex(java.lang.String literal)
                            throws UnknownOrLiteralConverterException
Returns the index of the converter identified by the specified literal.

Specified by:
getConverterIndex in interface LALogHandler
Parameters:
literal - Converter literal.
Returns:
Converter or null if unknown.
Throws:
UnknownOrLiteralConverterException - If the literal does not identify a non literal converter.
See Also:
getConverter(int)

getMessageConverter

public final LAConverter getMessageConverter()
Returns the current messageLabel converter used to extend messageLabel text with unparsed lines.

Specified by:
getMessageConverter in interface LALogHandler
Returns:
Message converter.
See Also:
parse(), LAMessage.extendsMessage(String)

getLastException

public final java.lang.Exception getLastException()
Returns the last exception thrown by the parsing process.

Specified by:
getLastException in interface LALogHandler
Returns:
Last exception or null parsing was succesfull.

getFileLength

protected final long getFileLength()
Returns the length of the parsed file.

Returns:
Length.
See Also:
FilesSetReader.length()

getFilePointer

protected final long getFilePointer()
Returns the current position in the parsed file.

Returns:
Pointer.

getMaxRecords

public final int getMaxRecords()
Returns the number of records to parse; 0 for no limitation.

Specified by:
getMaxRecords in interface LALogHandler
Returns:
maxRecords Number of records.

setMaxRecords

public final void setMaxRecords(int maxRecords)
Number of records to parse; 0 for no limitation.

Specified by:
setMaxRecords in interface LALogHandler
Parameters:
maxRecords - Number of records.

getPercentDone

public final int getPercentDone()
Returns the done percentage of the parsed file. If the handler is not parsing, returns 0.

Specified by:
getPercentDone in interface LALogHandler
Returns:
Done percentage.

getMessage

public final LAMessage getMessage(int index)
Returns the messageLabel at the specified position.

Specified by:
getMessage in interface LALogHandler
Parameters:
index - Physical index of the messageLabel in the log file.
Returns:
Message.

getMessages

public final LAMessage[] getMessages(int start,
                                     int end)
Returns the messages between specified positions. Uses getMessage(int)to read messageLabel from the log file.

Specified by:
getMessages in interface LALogHandler
Parameters:
start - start physicial index (included in the result).
end - end physical index (included in the result).
Returns:
messages.

getReader

protected final FilesSetReader getReader()
Returns the current reader.

Returns:
Current reader.

getSize

public abstract int getSize()
Returns the real number of messages in the log, not only in cache in case of a load on demand parsed log.

Specified by:
getSize in interface LALogHandler
Returns:
physical number of messages.

isParsing

public final boolean isParsing()
Returns true if the handler is currently parsing the log.

Specified by:
isParsing in interface LALogHandler
Returns:
true if parsing; false otherwise.

loadMessage

protected abstract LAMessage loadMessage(int index)
Loads the messageLabel at the specified index.

Parameters:
index - Index of the messageLabel to load.
Returns:
Message.

parse

public final void parse()
                 throws ParsingException
Parses the log content of the FilesSetReader returned by getReader(). Calls, in order :

Because a LALogHandler is a Runnable, for a threaded parsing you must start it in a new Thread :

 handler.addLogHandlerListener(myLALogHandlerListener);
 Thread handlerThread = new Thread(handler);
 handlerThread.start();
 

Specified by:
parse in interface LALogHandler
Throws:
ParsingException - If can't parse messageLabel.
See Also:
LALogHandler.parse()

parseMessage

protected final LAMessage parseMessage(java.lang.String message,
                                       LAConverter[] convertersToUse)
                                throws ParsingException
Parses a string messageLabel in a LAMessageusing LAConverter.parse(StringBuffer, LALogHandler)method.

Parameters:
message - Messate to parse.
convertersToUse - Converters used to parse the messageLabel.
Returns:
Parsed messageLabel.
Throws:
ParsingException - If can't parse messageLabel.

readNextLine

protected final java.lang.String readNextLine()
                                       throws java.io.IOException
Reads a line form the input. Could be called many times by LAConverter.parse(StringBuffer, LALogHandler)to read the messageLabel and the next lines. This is usefull when the messageLabel is written on more than one line (for example when the result of Throwable.printStackTrace()is added to the logged messageLabel}.

Returns:
Next line from the handled log.
Throws:
java.io.IOException - If an error occures.

saveMessage

protected abstract void saveMessage(LAMessage message,
                                    long pointer)
Saves the messageLabel after parsing.

Parameters:
message - Parsed messageLabel.
pointer - File pointer to the start of the messageLabel.

initParsing

protected void initParsing()
                    throws java.io.IOException
Makes the intialization before parsing. Calls LAAnalyzer.initAnalyze(LALogHandler) on each analyzer. If overwritten, you must call it with super.initParsing(). Calls fireStartParsing().

Throws:
java.io.IOException - If an error occures.

releaseParsing

protected void releaseParsing()
                       throws java.io.IOException
Makes the releases after parsing. Calls LAAnalyzer.releaseAnalyze(LALogHandler)on each analyzer.If overwritten, you must call it with super.releaseParsing(). Calls fireEndParsing().

Throws:
java.io.IOException - If an error occures.

run

public final void run()
Called by running the handler in a thread. Calls parse().
Example :
 Thread thread = new Thread(handler);
 thread.start();
 

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

addLogHandlerListener

public final void addLogHandlerListener(LALogHandlerListener listener)
Adds a listener.

Specified by:
addLogHandlerListener in interface LALogHandler
Parameters:
listener - Lister to add.
See Also:
LALogHandler.addLogHandlerListener(LALogHandlerListener)

removeLogHandlerListener

public final void removeLogHandlerListener(LALogHandlerListener listener)
Removes a listener.

Specified by:
removeLogHandlerListener in interface LALogHandler
Parameters:
listener - Lister to remove.
See Also:
LALogHandler.removeLogHandlerListener(LALogHandlerListener)

fireStartParsing

public final void fireStartParsing()
Fires a start parsing event.

Specified by:
fireStartParsing in interface LALogHandler

fireStepParsing

public final void fireStepParsing()
Fires a step parsing event.


fireEndParsing

public final void fireEndParsing()
Fires an end parsing event.

Specified by:
fireEndParsing in interface LALogHandler


Copyright © 2006 null. All Rights Reserved.