Implementing a Gogo Shell Service command

Creating shell service commands is fairly simple; it consists of the following:

  • Creating a proxy class that defines the commands— one method per command syntax flavor
  • Registering the proxy as a service with the OSGi framework, along with properties in the registration dictionary

Those properties declare the commands to be exposed and the scope in which they belong.

Additionally, a set of annotations can be attached to the proxy methods and their parameters to provide further descriptive information. This information would be used when listing the commands or when constructing their help output.

There are two service properties used when registering commands:

  • osgi.command.scope: A string that declares the scope of the registered commands
  • osgi.command.function: A string array listing the commands to be exposed from the registered proxy

Here's a diagram that describes the previous setup to our case:

Implementing a Gogo Shell Service command

When a service is registered with those dictionary properties, the Gogo Shell Runtime picks them up and constructs command entries for them. Those entries map to the method, or methods, with the same name.

It is possible to have more than one method that matches the function name (with different signatures). The Gogo components will find the best match, based on the command input by the user.

The BookshelfServiceProxy is the service that we will register; it will hold the methods that provide the commands. We will first take an end-to-end path with the search commands and then take it again when implementing the add command.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset