OSGI is another way to achieve similar modularity within the same JVM. In OSGI world a service is a bundle they provide similar benefits of microservices without the networking downside.
Some of the benefits of OSGI bundles include:
- OSGI Bundles can dynamically be added and removed from a container at runtime without shutting down the OSGI container.
- Bundle dependencies can be made private to the bundle meaning 2 bundles with different versions of the same dependency can run without issues in the same JVM
- Interfaces are in java so no translation needed
To demonstrate building projects with OSGI I have created a toy OSGI project at https://github.com/rizvn/OSGi-Greeter.
The project consists of 3 Bundles.
- Greeter - Defines Dict interface it consumes any bundles with dictionaries from the container
- English Dict - Provides implementation of Dict interface to the container
- French Dict- Provides implementation of Dict interface to the container
The UML diagram below shows how the Greeter and the dictionaries are related.
When greeter starts up, it looks for implementations of Dict. Once a Dict is available the greeter will greet using the words in that Dict. Once Dict is removed the greeter will stop greeting in the language.
The following commands can be used to manage bundles in the felix gogo shell:
start <bundleid> - can be used to start a bundle
stop <bundleId> - can be used to stop a bundle
The following commands can be used to manage bundles in the felix gogo shell:
start <bundleid> - can be used to start a bundle
stop <bundleId> - can be used to stop a bundle
No comments:
Post a Comment