Bundle Activator Osgi

2020. 2. 26. 13:20카테고리 없음

Bundle Activator OsgiOsgi @component example

Osgi Bundle Activator

The OSGi platforms represent a viable solution to support this kind of requirements.The Open Service Gateway Initiative is a specification defining a Java-based component system. It's currently managed by the, and its first version dates back to 1999.Since then, it has proved to be a great standard for component systems, and it's widely used nowadays.

The Eclipse IDE, for instance, is an OSGi-based application.In this article, we'll explore some basic features of OSGi leveraging the implementation provided by Apache. In OSGi, a single component is called a bundle.Logically, a bundle is a piece of functionality that has an independent lifecycle – which means it can be started, stopped and removed independently.Technically, a bundle is just a jar file with a MANIFEST.MF file containing some OSGi-specific headers.The OSGi platform provides a way to receive notifications about bundles becoming available or when they're removed from the platform. This will allow a properly designed client to keep working, maybe with degraded functionality, even when a service it depends on, is momentarily unavailable.Because of that, a bundle has to explicitly declare what packages it needs to have access to and the OSGi platform will start it only if the dependencies are available in the bundle itself or in other bundles already installed in the platform.

Getting the Tools. Let's start Karaf by executing the command: /bin/karaf startwhere is the folder where Karaf is installed. When the prompt of the Karaf console appears we can execute the following command to install the bundle: bundle:install mvn:com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOTBundle ID: 63This instructs Karaf to load the bundle from the local Maven repository.In return Karaf prints out the numeric ID assigned to the bundle that depends on the number of bundles already installed and may vary. The bundle is now just installed, we can now start it with the following command: bundle:start 63Hello World“Hello World” immediately appears as soon the bundle is started. We can now stop and uninstall the bundle with: bundle:stop 63 bundle:uninstall 63“Goodbye World” appears on the console, accordingly to the code in the stop method.