Writng a Java class for the static adapter
In creating a static log parser, the extractor, parser and formatter components
of the adapter configuration file are replaced with a Java class. The static parser class should
implement the interface org.eclipse.hyades.logging.parser.IParser.
This can be done by extending one of the abstract classes org.eclipse.hyades.logging.parser.Parser or
org.eclipse.hyades.logging.parser.MonitoringParser.
Extending the Parser class
This class should be used when you are creating a static parser to parse log
files that are no longer being updated or to parse a log file once during the execution of the context.
If this class is used, the Context Instance must be configured with the Continuous operation check box not selected.
- Add an import statement import org.eclipse.hyades.logging.parsers.Parser;.
- Add the following methods to the class:
- public void setConfiguration(Hashtable)
This method is called by the Generic Log Adapter to provide configuration information
to the static parser class that is specified by the user in the Import Log File wizard
or is provided in the adapter configuration file.
- public void preParse()
This is where the initialization work (if applicable) such as
estabilishing connections is executed.
- pubic void parser(Log)
Implementation of this method is not required.
It can be inherited from org.eclipse.hyades.logging.parsers.Parser.
- public ICommonBaseEvent[] parseNext()
This method will execute the majority of the logic to parse the log file, such as parsing
a set of records and returning an array of Common Base Event objects that represent
the data in that set of records.
- public void postParse()
This is where any clean up tasks are executed.
Note: The protected method Parser.readALine() can be used to read data from the log file. This method reads a line from the log file and it will throw an exception if an error occurs when it is reading the file. The exception will contain information about why the read failed. The existing readLine() method which returns null if an error occurs has been deprecated in this release.
Extending the MonitoringParser class
This class should be used when you need to create a static parser that can continuously
monitor a log file. Note: This class will allow a log file to be monitored
even if the log file does not exist at the time that monitoring is started.
The abstract class org.eclipse.hyades.logging.parser.MonitoringParser
must be extended. This class extends the Parser class.
Implement the methods as described for the Parser class but note the following:
- Add an import statement import org.eclipse.hyades.logging.parser.MonitoringParser.
- If the following Parser methods are overridden, ensure that the corresponding methods of the super class are called by the overriding methods:
- setConfiguration()
- readALine()
- postParse()
- Add a call to setEndOfFile() in the parseNext()
method before it returns null to indicate that there are currently no more parsed records to return.
This will ensure that the next time readALine() is called,
the log file will be examined to determine if the file has changed and has new records to parse
- If the static parser requires a command to convert the log file to a
format more easily parsed or to generate the log file, it must be specified to the
MonitoringParser class using one of the following methods calls after setConfiguration() is called:
setConverterCommand(String) or setConverterCommand(String[]).
If the command writes the log data to a file with a
name different that that specified in the configuration parameters in setConfiguration(),
the new log file name must be specified to the MonitoringParser class using the setFilename(String) method.
Note:
- org.eclipse.hyades.logging.parsers plug-in now has a dependency on
org.eclipse.hyades.logging.adapter plug-in.
- The MonitoringParser class provides no direct access to the
log file except for the readALine() method.
Static parsers that currently use the logFile member of Parser class to directly read data from the log file
should be modified to use the readALine() method.
Once you have written and tested your Java parser class, you can configure the sensor
component of the adapter configuration file to refer to this class.
.
Related Concepts
Overview of the Hyades Generic Log Adapter
Common Base Event format specification
Related tasks
Creating a log parser
Creating a static adapter
Configuring the sensor component
Related references
Adapter Configuration File structure
Adapter Configuration Editor
Regular expression grammar
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.