JBLADE Tutorial

HOME

Overview

The API for JBLADE is very similar to that of BLADE. It also consists of two classes JBlade and JBladeParams whose public methods are exactly like those of Blade and BladeParams respectively. The Blade and BladeParams classes are described in the BLADE tutorial .

Example

The following is the Java counterpart of the C++ program shown in the BLADE tutorial .

import JBlade;
import JBladeParams;
import JBladeHelper;

public class jb
{
    public static void main(String[] args)
    {
      //set the parameters to blade
      JBladeParams params = new JBladeParams();
      params.SetPort(new Integer(9999));
      params.SetNotify(new Boolean("true"));

      //create the blade object
      JBlade blade = new JBlade(params);

      //start the broker
      try {
        blade.Start();
      } catch(Exception e) {
        e.printStackTrace();
        System.exit(0);
      }

      //keep waiting
      while(true) {}
    }
}

Assuming that the program is saved in a file jb.java, it can be compiled as follows:

$ javac jb.java

A point to note is that in addition to JBlade and JBladeParams, the program also imports the class JBladeHelper. This is because JBlade works by firing up a program call blade_wrapper in a separate process. This program actually runs the broker. In essense it is a wrapper around BLADE that accepts options via command line arguments. JBlade makes sure that appropriate command line arguments are provided to blade_wrapper while spawning it. JBlade also uses the JBladeHelper class to spawn a separate thread which constantly reads the output of the blade_wrapper process and prints them to the standard output. This makes messages from the broker appear on the console.

The CLASSPATH must be set properly while compiling jb.java so that the imported classes are found by the compiler. Also JBlade will only work correctly if the blade_wrapper program is on the execution path of the shell. Since the public methods of JBladeParams are exactly like those of BladeParams (with obvious differences like using String instead of string etc.) we will not describe them here. The BLADE tutorial contains all the pertinent information about these methods. Information about writing clients are available in the SHAFT tutorial .

HOME