Express (Distributed operating systems), v8.0 > Troubleshoot and support > Analyzing application server Java system dumps with the IBM Monitoring and Diagnostic Tools for Java - Dump Analyzer > Write Dump Analyzer modules for WAS diagnostics - Tutorial
Tutorial: Writing Dump Analyzer modules for WAS diagnostics
The Hello World Analyzer
Here is the simplest possible analyzer. It reads the dump, but ignores its contents and simply prints "Hello World" as its output.
public class HelloWorldAnalyzer extends WASAnalyzerBase implements IReport {public IAnalysisReport produceReport() { IAnalysisReport out = allocateReport(null); out.printLiteral("Hello World"); return out; } }
Though obviously very simple, this analyzer actually illustrates several basic principles common to all analyzers:
Analyzers are Java classes
An analyzer is a simply a Java class that implements a particular set of interfaces and methods. End-users of the Dump Analyzer tool, and other analyzers, can invoke our new analyzer by specifying its class name (which serves as the analyzer name)
Notes:
- Note that it also possible to write analyzers using various scripting languages, such as the SML language or Jython. For more information on this, see the main API reference in the Dump Analyzer tool documentation.
Use a standard base class: WASAnalyzerBase
In principle, an analyzer may need to or wish to implement a wide variety of methods from several different interfaces in order to declare itself to the framework and to customize how the framework invokes it. But in practice, all these methods can have default implementations in various common base classes provided with the library. So our analyzer simply needs to extend one of these common base classes, in this case WASAnalyzerBase. WASAnalyzerBase contains common definitions suitable for most analyzers that are part of the collection of analyzers used to analyze WAS information from a dump.
Our analyzer only needs to override the methods from WASAnalyzerBase for which the default implementation is not appropriate for our analyzer. In this simplest case, we do not override any methods from WASAnalyzerBase.
Notes:
- For more information on the optional methods that an analyzer can define to customize its interaction with the framework, see Integrate the Analyzer into the Tool Menu
- WASAnalyzerBase is just one of several alternative base classes available in the library, that can be used to implement different flavors of analyzers (other examples include AnalyzerBase, SimpleAnalyzerBean, CollectionAnalyzerBase, ObjectWrapper, etc.). For more details, see the main API reference in the Dump Analyzer tool documentation.
Declare the main function of the analyzer: IReport
There are a few different styles of analyzers, which perform different functions and whose functions are invoked in different ways by the framework or by other analyzers. Our analyzer declares which style of function it performs by declaring that it implements a particular standard interface; in this case IReport.
The IReport interface corresponds to analyzers whose main function is to perform some analysis on the dump, and then generate a human-readable report that summarizes the information resulting from that analysis.
Notes:
- For more information on other possible styles of analyzer functions, and the corresponding interfaces (e.g. IAnalyze), see the main API reference in the Dump Analyzer tool documentation.
- Note that in practice, WASAnalyzerBase itself already declares that it implements IReport, because all analyzers constructed using the WASAnalyzerBase style produce reports. So the explicit declaration implements IReport here is actually unnecessary. But we include it for clarity and consistency.
Implement the main function: produceReport()
Since we declared that our analyzer was going to produce a report, it needs to provide an implementation of the method produceReport(), which is the only method declared in the IReport interface. produceReport() is the method that will be invoked from the framework when the tool actually invokes our analyzer to ask it to perform its role.
The body of produceReport() does the following:
- allocate an empty report object, using the allocateReport() utility method (provided by the common base class WASAnalyzerBase)
- put one line of text in the report object: the string "Hello World". Using the method printLiteral() in the report object, which is intended to write constant strings (literals) in a report. Other methods are available to write other types of information in a report.
- return the filled-in report object. The framework (which invoked our analyzer's produceReport() method) will take care of formatting and printing the report for the end-user of the tool to see.
Notes:
- All report objects (allocated by allocateReport() and related methods) implement the IAnalysisReport interface. This interface provides a variety of functions to write information in reports and to control the formatting of reports. See Write and Formatting Reports
Next Topic
A Simple Analyzer to Examine Data Structures