Intro to OSGi Ivan Chadikovski AEM Team Lead at Tricode February 2016
AgendaModule (What is it?)
OSGi (the mission)
Bundles (ARE modules!)
Component Models
Declarative Services
SRC Annotations
Implementations
Who is using OSGi
Questions?
Module (What is it?)A module must have one, well defined purpose.
A module should know nothing about implementations of the modules it depends on, It should rely on their public interface.
Benefits: Separation of concerns, parallel development, ease of maintenance.
JARs (Are NOT modules!)JARs are not modules, they can be considered more as
deployment units.
What JARs are missing to achieve modularity:
meaningful names, versions, vendors, exports, explicit class restriction, explicit dependency information, etc..
Build tools such as Maven, Ant and Gradle tackle some deficiencies, but do not offer true modularity.
True modular approach currently is offered only by OSGi.
OSGi (the mission)OSGi - The dynamic module system for Java.
Was originally conceived as a standard embedded systems.
Driven by OSGi AllianceConsortium of vendors (big players in tech industry).
Mission
Build ecosystem to support component and service based development in Java.
Bundles (ARE modules)JARs with metadata that OSGi can interpret (via MANIFEST.MF)
Can also be used outside OSGi.
Dynamic and have a life-cycle Installed, Resolved, Active, Uninstalled, Start, Stop.
Can be updated without down time.
MANIFEST.MFExample:
Bundle-Name: Hello WorldBundle-SymbolicName: nl.tricode.helloworldBundle-Description: Hello World BundleBundle-Version: 1.0.0Bundle-Activator: nl.tricode.ActivatorExport-Package: nl.tricode.helloworld;version="1.1.0"Import-Package: org.osgi.framework;version=[1.3.0, 2)"
BundleActivatorExample:
Oldest way to activate code in your bundle.
It couples you to OSGi API, using Component Models is far more convenient.
Component ModelsComponent, the LEGO vs BEES analogy
Component Models: Defining components that interact with each other via Services.
Multiple Choices:Blueprint
Declarative Services (DS)
Declarative ServicesIt helps developer to concentrate on application logic and takes
responsibility for almost all OSGi aspects of tracking and registering services.
Service (API) implementations can be swapped on the fly.
SCR Annotations (Automated creation of Descriptor Files).