Develop an OSGi bundle with simple activation
The most straightforward way to control the lifecycle of our OSGi bundle code is to implement the org.osgi.framework.BundleActivator interface in one of the classes within the bundle. When the server starts and stops the bundle, the start and stop methods of the BundleActivator interface are called.
If we are using the WebSphere Application Server Developer Tools, create an OSGi bundle project, and create an OSGi BundleActivator class in that project. Then identify the bundle activator class to the OSGi framework by adding the Bundle-Activator header to the bundle MANIFEST.MF file. For example: Bundle-Activator: com.example.bundle.Activator.
Subtopics
- Receiving configuration data using the ManagedService interface
Liberty profile configuration is managed by the OSGi Configuration Admin service and can be accessed according to the OSGi Configuration Admin service specification. Sets of configuration properties are identified by a persisted identity (PID) used to associate an element in server.xml, where the PID is used as the element name, with a component that registers to receive the properties.
- Work with the OSGi service registry
We can create an object and register it as an OSGi service for use by third-party features deployed to the Liberty profile.
Example
package com.example.bundle; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println("Sample bundle starting"); // Insert bundle activation logic here } public void stop(BundleContext context) throws Exception { System.out.println("Sample bundle stopping"); // Insert bundle deactivation logic here } }
Parent topic: Develop a Liberty feature