Export Common Base Event APIs
The common base event export service defines a set of APIs to export a set of common base events to various output formats such as XML, CSV, HTML, etc. Exporting a set of common base events follow a simple workflow:
-
Construct a data structure that contains a set of common base events.
-
Create a context object that will contain information needed by the export handler.
-
Create an export handler for a specific output format type (i.e. XML, CVS, HTML, etc).
-
Use the export handler to export the common base events .
-
Check the context status to determine if the export operation was successful.
The following code snippet illustrates this workflow and demonstrates how to export a set of common base events to a XML file.
1
|
TRCAgent agent = createAgent(); |
2
|
IOperationContext context = new OperationContextImpl();
OutputStream outputStream = new FileOutputStream(new File("MyFile.xml"));
context.setProperty(IExportHandler.CONTEXT_OUTPUT_STREAM, outputStream); |
3
|
IExportHandler handler = new XMLExportHandler(); |
4
|
handler.exportLog(agent, context); |
5
|
if (context.getStatus().isOK())
System.out.println("Export successful!");
|
1. Construct a data structure that contains a set of common base events
Each export handler will consume a certain data structure containing a set of common base events. For example, an export handler may consume a list of common base events, a TRCAgent object that contains a set of events, or a custom data structure. Consult the java doc for the export handler one is interested in to determine the data structure the export handler is expecting.
2. Create a context object that will contain information needed by an export handler
A context object must be created to contain the necessary data needed to export the common base event to an output format. At a minimum the context object must contain an output stream that the export handler will write to. Consult the java doc for the export handler one is interested in to determine any additional context data required to export the set of common base events. The java doc should list a set of context properties needed by the export handler.
3. Create an export handler for a specific output format type (i.e. XML, CVS, HTML, etc).
The common base event export service provides a list of export handlers classes. Each of these classes implement the org.eclipse.tptp.monitoring.log.provisional.export.IExportHandler interface. A set of export handlers can be found under the org.eclipse.tptp.monitoring.log.provisional.export package.
4. Use the export handler to export the common base events
The IExportHandler interface defines a simple API to export the common base events.
public abstract void exportLog(Object input, IOperationContext context);
The "input" parameter represents the data structure that contains the list of common base events. The context object contains context information needed by the export handler to complete the export operation.
5. Check the context status to determine if the export operation was successful
Once the export has completed status information should be checked to make sure the export operation was successful. The status information is stored in a org.eclipse.tptp.platform.common.provisional.IOperationStatus instance which can be extracted from the context object.
Related concepts
Common Base Event model