Chapter 8. Console

Table of Contents

Enabling the Console
Console Commands
Adding Commands

All Eclipse RCP programs, and this includes the CSS end-user GUI as well as command-line tools like the archive engine, alarm server etc. include the OSGi console.

The console allows you to view which plugins have been loaded, to introspect extension points and more. In principle it can be used to load additional plugins or to replace existing plugins at runtime, but at this point no CSS tool is using that feature.

Enabling the Console

To start any RCP program with console access, add the command-line option

-console

You can allow network access to the console by adding a TCP port number, for example

-console 4884

You will then be able to access the console of the program remotely via

telnet host_where_program_is_running 4884

Multiple network connections to the same program are possible. Note that there is no security, i.e. anybody on the network could telnet to your application and stop it!

Console Commands

Useful console commands:

  • help - List all available commands.
  • ss - List all plugins and their short status.
  • ns - List all plugins that define extension points.
  • ns name.of.some.plugin - List all extension points of that plugin.
  • pt name.of.some.extension.point - List all implementations of that extension point.
  • disconnect - Disconnect from a telnet session to the console. The application will continue to run.
  • close - Close, i.e. stop the program. Note that this does not just end the console session, it stops the application. The IApplication.stop() method will be invoked, which allows for a graceful shutdown of the application.

There are also commands to list all applications, stop an application, update or add plugins, then restart the application. Refer to the help command for more.

Adding Commands

Applications can add custom commands to the console. To accomplish this, you need to implement an

org.eclipse.osgi.framework.console.CommandProvider

and register it with the CommandProvider service. This can be done from the start() method of the plugin activator:

class MyActivator
...
  public void start(final BundleContext context)
      throws Exception
  {
     // Register console commands for this engine
     commands = new MyConsoleCommands();
     context.registerService(CommandProvider.class.getName(),
                             commands, null);
     ...

When implementing your CommandProvider, note that there is no interface in the usual Java sense to declare your console commands. Instead, all public methods starting with an underscore in their name and a CommandInterpreter parameter will be available as console commands:

public class MyConsoleCommands implements CommandProvider
{
    @Override
    public String getHelp()
    {
        final StringBuilder buf = new StringBuilder();
        buf.append("---My commands---\n");
        buf.append("\thello - Say hello\n");
        return buf.toString();
    }

    /** 'hello' command */
    public Object _hello(final CommandInterpreter intp)
    {
        intp.print("Hello");
        return null;
    }
}