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.
- Wso2server.sh -DosgiConsoleTo enable the OSGI console in server startup
- install file:<path to file>To install a bundle in the run time
- ss <some_part_of_bundle_name>List the bundle state and bundle id with bundle symbolic name
- 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.
- stop <bunle id>This command will put the bundle from ACTIVE to INSTALLED state.
- uninstall <bundle_id>This will uninstall the bundle from the OSGI framework
- 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
- 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.
- diag <bundle id>This command lists about the status of the bundle and lists if any unresolved packages exists for that particular bundle.
- lslist 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.
- enable <componentID>enabling service components
- comp <componentID>Use this command to find unsatisfied services of the given component, which prevent it from going it to satisfied state.
- serviceslist down all the services in the runtime including services provided by the system bundle. You can use simple filters to narrow down your list.
- disable <componentID>disabling component given by the component ID
Hope the above commands helps you to work with osgi framework. Have fun with osgi! :-)