6 Debugging Tools and Tips

This chapter describes the utilities and tips that may be used for debugging purposes when developing new nodes. The source code for NARMaker.java and NARViewer.java is available under the “Utilities" section of the CDK Development LiveLink site discussed earlier in this document

Running Nodes from the Command Line

You can run a node from the command line as a Java application, assuming that the main() method has been implemented. The basic syntax of running node from the command line is as follows:

  • java <fully-qualified class name> <nodeID> OMC_Home <configFile>

parameters are as follows:

nodeID Unique String identifier for this node.
OMC_Home   Location of Offline Mediation Controller installation

            (e.g. /ocomc)

configFile     Filename/location of this node's configuration file

Where OMC_Home is the directory in which you installed Offline Mediation Controller

Configuration files are generated by the Offline Mediation Controller Administration Client GUI and are generally located in OMC_Home/config/<nodeID>/general.cfg

Where OMC_Home is the directory in which you installed Offline Mediation Controller

The basic contents of the general.cfg file are as follows:

rulesfile'     com.nt.udc.rules.<majorType>.<minorType>.<NPL class name>'

  • ·numchannels'    0'

  • harbackup'     false'

  • idleosarwritetime'     60'

  • maxlogfilesize'     100000'

  • debuglevel'     1'

  • checkforosarstimer'     20'

  • osarsperfile'     500'

  • backup     'false'

  • narbackupdays     '7'

  • asCodeBase'     '

When running the node from the command line, the fully qualified class name should be specified by the rulesfile parameter. (That is the name of the class that was generated by the NPLCompiler.)

NAR Viewer

The NARViewer can be used to view the contents of the binary NAR files produced by a node. NAR files are found in the node's output directory (OMC_Home/output/node_id/, where OMC_Home is the directory in which you installed Offline Mediation Controller.) This utility will allow developers to verify the contents of the data that the node is producing.

The NARViewer is in the com.nt.udc.general package in the nodes.jar file.

USAGE:

java com.nt.udc.general.NARViewer <NAR file> <Output file>

ARGUMENTS:

NAR file       File Name of the NAR file to view

Output file    Name of file to print contents to (in ASCII)

Note:

The above usage statement assumes that the OMC_Home/web/htdocs/nodes.jar is included in the CLASSPATH environment variable, where OMC_Home is the directory in which you installed Offline Mediation Controller.

NAR Generator

There is a template NAR Generator class available. In order to provide meaningful data, developers will need to modify the template, or create a new class, according to their own requirements.

The sample NARMaker class, as described below, will generate the specified number of NARs in a file called nars.dat. The NARMaker will create NARs which include the following fields:

Table 6-1 NARs Created by NARMaker

ID Type Value

2

MillisField

<timestamp>

3

IntField

<Counter starting at 0>

4

StringField

"Test field"

The sample NARMaker class is in the com.nt.udc.general package in the nodes.jar file.

USAGE:

java com.nt.udc.general.NARMaker <# NARs>

ARGUMENTS:

# NARsNumber of NARs to generate

Note:

The above usage statement assumes that the OMC_Home/web/htdocs/nodes.jar is included in the CLASSPATH environment variable, where OMC_Home is the directory in which you installed Offline Mediation Controller.

The source code for the NARMaker class is included here for illustration purposes.

Example 6-1 NARMaker.java

·package com.nt.udc.general;
·
·import java.io.*;
·import java.util.*;
·import com.nt.udc.ndk.node.*;
·import com.nt.udc.nar.*;
·
·/**
· * This is a _very_ basic NAR file generator. It is intended to be
· * used as a template to generate specific NAR's that match the appropriate
· * node's rules. Modify this code as needed.
· *
· * In this example, the generated NAR's will hold the following fields
· * and values:
· *
· *   Field 2 - Time interval
· *   Field 3- Integer count
· *   Field 4- String
· */
·public class NARMaker
·{
·    /** Main method which takes 1 argument:
·     *    args[0]    number of NARs to generate   */
·    public static void main( String [] args )
·    {
·        int numNars = 0;
·
·        if(args.length != 1)
·        {
·            String usage = "Usage: \n" +
·                           "  java com.nt.udc.nar.NARMaker <num_nars>";
·            System.out.println( usage );
·            return;
·        }
·
·        try
·        {
·            numNars = Integer.parseInt( args[0] );
·        }
·        catch( Exception e )
·        {
·            System.out.println( "Exception: " + e );
·        }
·
·        // Create the NAR, and set up the initial attribute values
·        NAR nar = new NAR();
·
·        // Create 3 DCField objects to put into the NAR.
·        DCField[] fields = new DCField[3];
·
·        // Create a dummy time field.
·        long time = System.currentTimeMillis();
·        fields[0] = new MillisField( 2, time ); 
·        // Create a integer count
·        fields[1] = new IntField( 3, 0 );
·        // Create a sample String field
·        fields[2] = new StringField( 4, "Test field" );
·
·        // Put the fields in the NAR
·        for( int i = 0; i < fields.length; i++ )
·        {
·            nar.setField( fields[i] );
·        }
·
·        try
·        {
·            // Use the file called "nars.dat"
·            FileOutputStream fos = new FileOutputStream( "nars.dat" );
·
·            // Loop for "numNars", and create a new NAR.
·            for( int i = 0; i < numNars; i++ )
·            {
·                // Update the time field.
·                fields[0] = new MillisField( 2, time + ( i * 100 ) );
·
·                // Update the integer count
·                fields[1] = new IntField( 3, i );
·
·                nar.setField( fields[0] );
·                nar.setField( fields[1] );
·
·                nar.toStream( fos );
·            }
·        }
·        catch( Exception ex )
·        {
·            System.out.println( "Exception caught : " + ex );
·        }
·    }
·}