What is Twiddle?
Twiddle is a command line shell, similar in concept to /bin/sh, but where commands are Java classes.
The basic concept is to make it simple, to write command line thingys which can provide added value for administration. Command line tools should have a consistent interface and be easily organized (instead of littering up bin/* with scripts).
I know many people like HTML consoles, but I also know many UNIX system administrators who hate them too. Twiddle is an effort to provide rich support for those UNIX guys.
Goals
- Simple framework for building commands
- Interactive console with pluggable line reading layer
- Installable as a Geronimo component to allow telnet/ssh-like access for administration
- A Twiddle command will be the main entry-point for Geronimo
Vision
Here is a little background on Twiddle (the concept and the future)...
The short-term vision is to provide a simple container for commands (which is mostly done).
The medium-term vision is to use Twiddle as the bootstrap for Geronimo, letting Twiddle handle the details of the initial footprint, as well as to provide a set of admin commands to work on Geronimo (start/stop/deploy/status/...) using either interactive or non-interactive console modes.
The long-term vision is to turn Twiddle into a Geronimo component, so that one could telnet/ssh into the server to run commands on the live instance, especially to run a script interpreter command (using BSF or something) so that one could evaluate a Jython or BeanShell script on the live server.
On The Side
Had a little chat with BobTheDespot about a possible future integration of Twiddle and [ http://jerk.codehaus.org "The Jerk" ] which would add and IRC interface to Geronimo. After making some modifcations to The Jerk to allow public logging of #geronimo I think it will be failr easy to do too
How To Run Twiddle
(This is just what I've got so far, and if it's wrong would the people writing twiddle please correct it -Matt)
First, build Geronimo (will building just twiddle work?) To run Twiddle, go to the source directory of Geronimo. Then change into the <code>target/geronimo-DEV/bin</code> directory. From there either run <code>twiddle</code> or <code>twiddle.bat</code>, depending on whether or not you use a Windows or UN*X based OS.
To run a command (you can't do this with the Twiddle console yet...): <code>
package org.apache.geronimo.command;
import org.apache.geronimo.twiddle.command.Command;
import org.apache.geronimo.twiddle.command.CommandInfo;
import org.apache.geronimo.twiddle.config.CommandConfig;
import com.werken.classworlds.ClassWorld;
public class CommandRunner() {
{{{ private ClassWorld world;
private Command command;
public CommandRunner()
throws Exception {
world = new ClassWorld();
world.newRealm(Command.DEFAULT_CLASS_REALM);
createCommand();
runCommand();
}
private void createCommand()
throws Exception {
// This describes the attributes of a command
CommandConfig config = new CommandConfig();
// This is the description for the command (accessed ?)
config.setDescription("My First Command");
// This is the how the command is looked up. This is not useful in our
// simple instance here, but when Twiddle runs the commands, it will check
// against a database of commands for this key when it parses a line of input, that is
// if a user types in PROMPT> firstcommand arg1 arg2 at the command prompt, Twiddle
// will look for a command with name firstcommand in its database, and run that command.
config.setName("firstcommand");
// This is the class name that will be loaded in as a command to be executed. This is
// a java class that is a properly formatted command (see
// "How To Write Commands for Twiddle")
config.setCode("org.apache.geronimo.command.MyFirstCommand");
// Loads the class into a form that can be read by the ClassWorld
CommandInfo cInfo = new CommandInfo(config, world);
// Creates a command out of the prototype generated in cInfo
command = cInfo.getPrototype();
}
private void runCommand()
throws Exception {
// Simple enough. The argument here is an array of command line arguments to your command.
command.execute(new String[0]);
}
public static void main(String[] args) {
try {
new CommandRunner();
} catch (Exception E) {
System.err.println("Cought Exception while creating and running command: \n" +
E.getMessage()
);
}
} }
- }}}
</code>
How To Write Commands for Twiddle
(This is just what I've got so far, and if it's wrong would the people writing twiddle please correct it -Matt)
Commands either:
extend the abstract class <code>org.apache.geronimo.twiddle.command.AbstractCommand</code>
or
implement the interface <code>org.apache.geronimo.command.Command</code> and extend <code>org.apache.geronimo.common.CloneableObject</code>
Here is a simple command that outputs Hello, World! to the console:
<code>
package org.apache.geronimo.command;
import org.apache.geronimo.twiddle.command.AbstractCommand;
public class MyFirstCommand extends AbstractCommand {
{{{ // This method is all that's needed to finish the implementation of AbstractCommand.
// It is what is run when your command is run. (It is the entry point for your command) - public int execute(String[] args) throws Exception {
{{{ // The oh, so familiar greeting.
- System.out.println("Hello, World!"); return 0; }}}
- }
}
- }}}
</code>