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 .