• OSGI In Liferay 7 DXP

    OSGI In Liferay 7 DXP


    OSGi In Liferay 7 DXP is a new concept introduced In Liferay 7, The main intention behind OSGi is to split the Liferay 7 Portal  Modules independent of each other. I am gonna introduce you to some of the basic concepts of OSGI such OSGi Modules, OSGi Components and OSGi Services.

    What is Modularity?

    A Software application is Consists of different parts, they are typically called as software components. These components interact with each other using the API's. API's are nothing but the Classes, Interfaces and Methods defined in a Module.

    What is a Module?

    A module can be defined a part of Software application composed of different Components and Services, Service can be used to perform any action. In OSGI a Module is collection of classes and interfaces as a Bundle, Finally Its a JAR file with some meta data. In older versions of Liferay we were using the concept of plugins, now in Liferay 7 DXP any new project we create is called as module.

    What is OSGi?

    OSGI Is  service oriented platform on top of unique class loading mechanism, its enables features such as versioning of modules, encapsulation of API's (Classes) and run-time dynamics(starting stopping updating modules at run-time)

    Problems with Non Modular Applications

    Blurring the responsibility
    Increases complexity
    maintenance becomes harder over time

    Benefits of OSGi

    Instead of gigantic big application, using OSGI we can separate them as independent modules.
    Easy maintenance
    Each Module with its own clear responsibility
    Restrict and Expose the visibility of classes properly

    OSGi Component

    If you want the lifecycle of your object to be managed by the OSGi container,  you can declare it as a component. Using Declarative Service annotations,  you can make a POJO Class a OSGi component by annotating it with @Component With this,  you'll get the ability to start, stop and configure the components.

    OSGi Service

    OSGi components classes can be made as OSGi services just by annotating it with @Service annotation. Services should implement atleast an interface. When you mark a component as service, you can use (call) this service from other osgi components.
    Any class defined as a component can be used only inside the module, where as when you declare class as service, it can be accessible outside the module, you can export them, the other modules just have to import them in bnd.bnd files in order to use the service. 

    What is Dependency In OSGI?

    When a module uses the services of another module we can say the Module 1 is Dependent on Module 2.

    What is OSGI Container?

    OSGI Container manages the Lifecycle of  Components, Services and Bundle or Modules

    What is Bundle?

    OSGI Modules (Projects) are called as bundles. 


    Bundle Lifecycle

    The life cycle of a bundle is shown in the below picture, once the module is published(deployed), it will go through the Life cycle as shown below.


    Publish Find Bind Model

    OSGi Works on the model called publish-find-bind If a module wants to consume the service of the other module, the other module have to be published, the consumer module have to find the published module and bind it to consume its services


    OSGI Framework Architecture


    Bundles – Bundles are the OSGi components that we create in module project.

    Services – Services connects bundles dynamically using a publish-find-bind model for POJO Objects (Services and components).

    Life Cycle – An Interfce to install, start, stop, update, and uninstall bundles.

    Modules – It's a layer that defines how a bundle can import and export packges,classes codes.

    Security – A layer to the handles the security features.

    Execution Environment – Tells Which methods and Classes are available in the specific platorm.


    I know most of us will not understand OSGi when we read it for the first time, i will give more information on OSGi with examples in detail soon.


  • 1 comment:

    1. Excellent boss simple and quite informative. Keep up good work thanks

      ReplyDelete