Adding New Shell Commands
The JXTA Shell is an open framework where new Shell commands can be added dynamically. Every Shell commands is a separate application that is loaded by the Shell framework when the command is first invoked via the command interpreter.
The Shell framework does not need to be recompiled when adding new commands. New commands can be easily written by users to add new functionalities to the Shell.
The JXTA Shell Project provide base Shell Command classes that can be extended to implement new commands. As long as these commands follow the guidelines of the JXTA Shell framework invocation, they will be able to be loaded by the Shell framework and communicate through pipes with other existing commands.
New commands can be implemented for a search engine, graphical input/output interface, webproxies (to allow to interface with a Web server). New commands may also be implemented for administrative or accounting purpose.
How to Write a new Command
All Shell commands needs to extend the net.jxta.impl.shell.ShellApp Class. This class provides the framework to interact with the Shell console, print and read from the console and setup environment variables for the command (stdgroup, stdin and stdout pipes). The new command class needs to implement the two methods "startApp" and "stopApp". The startApp method is called after the command is loaded. The StopApp is called when the Shell exit.
Here is an example of a simple "Hello World" command:
Package net.jxta.impl.shell.bin.myHelloWorld
public class myHelloWorld extends ShellApp {
private ShellEnv myEnv;
public int startApp (String[] args) { //args contain the argument of the command
// The ShellApp class provides global variables to access
// group: PeerGroup service handle
// pipes: Pipe service handle)
// env: Shell environment variables
// extract the current stdin from the environment
ShellObject obj = env.get ("stdin");
if (args == null) { //println print to the console
println("Hello my peergroup is" + group.toString());
} else { // no argument are authorized
println ("Sorry no argument supported!");
}
return ShellApp.appNoError; // Everything went OK!
}
public void stopApp () {
// no much to be done here
}
}
All Shell commands are located in the package net.jxta.impl.shell.bin. For a new command to be accessible from the Shell, the new command class file needs to be copied into the Shell bin class directory.There is no need to recompile the Shell. By copying the new class file into the Shell bin class directory, the command will be dynamically loaded when invoked. The Shell does not have to be restarted,