Friday, May 18, 2012

Useful commands in OSGI


OSGI framework enables to build true modular system in java. It defines a way to create true bundles and a way those communicate at run time. Here generally the modules are called as bundles and another advantage is we can install and unistall a bundle in the runtime without restarting the JVM.
Here the unit of information hiding is package in a bundle, ie there can be certain packages made visible to other bundles in the runtime and certain can he hidden.

This post is mainly targeted to work an debug wso2 server. Therefore in the run time there is requirement interact with OSGI framework. I'm listing some useful commands here.

  1. Wso2server.sh -DosgiConsole
    To enable the OSGI console in server startup
  1. install file:<path to file>
    To install a bundle in the run time

  2. ss <some_part_of_bundle_name>
    List the bundle state and bundle id with bundle symbolic name

  3. start <bundle id>
    when you just run the install command, it won't start the bundle. For that you should execute start command also. You can notice this in the ss command.

  4. stop <bunle id>
    This command will put the bundle from ACTIVE to INSTALLED state.

  5. uninstall <bundle_id>
    This will uninstall the bundle from the OSGI framework

  6. packages <package_name>
    You can see the packages visible to the OSGI framework with its versions and exporting bundles.
    Eg: packages org.wso2.foo.bar
  1. b <bundle id>
    lists the bundle information, such as exported and imported packages. If you have same package exported by multiple bundles with different versions, then you can view what version of package being used in the run time in the specified bundle id.

  2. diag <bundle id>
    This command lists about the status of the bundle and lists if any unresolved packages exists for that particular bundle.
  1. ls
    list down all the service components found in this runtime along with their component ID and life-cycle status. Here you can see whether a bundle in satisfied state or unsatisfied state. For example if a bundle expects a osgi service, and if it's not available in the osgi at run time the bundle will be unsatisfied sate.
  2. enable <componentID>
    enabling service components

  3. comp <componentID>
    Use this command to find unsatisfied services of the given component, which prevent it from going it to satisfied state. 

  4. services
    list down all the services in the runtime including services provided by the system bundle. You can use simple filters to narrow down your list.
  1. disable <componentID> 
    disabling component  given by the component ID

Hope the above commands helps you to work with osgi framework. Have fun with osgi! :-)

No comments:

Post a Comment