Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Leveraging OSGi to Create Extensible Plugins fo...

Leveraging OSGi to Create Extensible Plugins for Liferay 6.2

Avatar for Milen Dyankov

Milen Dyankov

June 26, 2015
Tweet

More Decks by Milen Dyankov

Other Decks in Programming

Transcript

  1. Leveraging OSGi to Create Extensible Plugins for Liferay 6.2 Eduardo

    García edupgv @ Julio Camarero juliocamarero @ Core Engineers at Liferay, Inc Milen Dyankov milendyankov @ Senior Consultant at Liferay, Inc
  2. ...

  3. we could… Develop a very complex and laborious application that

    covers all possible cases Release a new version every time any shipping cost algorithm changes or we add new countries Develop a simple core application that covers only the common features Make the application extensible with country modules “ ” If a shipping algorithm changes, our core application remains the same and only that specific extension must be changed
  4. ... because it’s all advantages! improves maintainability maximizes reusability simplification

    of releases (independent) new market opportunities (extensions)
  5. App ver. 1 App ver. 2 time size ... ext

    1 ver. 1 ext 1 ver. 2 ext 1 ver. 3 ext 2 ver. 3 ext 2 ver. 1 ext 2 ver. 2 ext 3 ver. 1 ext 1 ver. 4 ext 3 ver. 2
  6. In fact, Audience Targeting, the first Liferay 6.2 application following

    this approach, is already available on Marketplace!
  7. OSGi basic concepts in 3 minutes! (or what you need

    to understand before we continue)
  8. OSGi bundles (this is what our plug-ins are) manifest manifest

    manifest manifest manifest Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Shipping Impl Bundle-SymbolicName: com.liferay.shipping.impl Bundle-Vendor: Liferay, Inc. Bundle-Version: 1.0.0 Private-Package: com.liferay.shipping.impl.model,com.liferay.shipping.impl.util Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))" . . . #1
  9. #1 OSGi bundles (this is what our plug-ins are) manifest

    manifest manifest manifest manifest Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Shipping Impl Bundle-SymbolicName: com.liferay.shipping.impl Bundle-Vendor: Liferay, Inc. Bundle-Version: 1.0.0 Private-Package: com.liferay.shipping.impl.model,com.liferay.shipping.impl.util Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))" . . . All modern build tools (Ant, Maven, Gradle, ...) can build OSGi bundles! So can Liferay SDK !
  10. Package dependencies (this is how we describe what we provide

    and expect) Import-Package: com.liferay.shipping.api.model, com.liferay.shipping.api.util, com.liferay.portal.kernel.io.unsync;resolution:=optional, com.liferay.portal.kernel.util;resolution:=optional, freemarker.cache;resolution:=optional, freemarker.template;resolution:=optional Export-Package: com.liferay.shipping.api.model;version="1.0.0", com.liferay.shipping.api.util;version="1.0.0" manifest manifest manifest manifest manifest EXPORT EXPORT #2
  11. manifest manifest manifest manifest manifest EXPORT EXPORT Package dependencies (this

    is how we describe what we provide and expect) Import-Package: com.liferay.shipping.api.model, com.liferay.shipping.api.util, com.liferay.portal.kernel.io.unsync;resolution:=optional, com.liferay.portal.kernel.util;resolution:=optional, freemarker.cache;resolution:=optional, freemarker.template;resolution:=optional Export-Package: com.liferay.shipping.api.model;version="1.0.0", com.liferay.shipping.api.util;version="1.0.0" #2
  12. #2 manifest manifest manifest manifest manifest EXPORT EXPORT Package dependencies

    (this is how we describe what we provide and expect) Import-Package: com.liferay.shipping.api.model, com.liferay.shipping.api.util, com.liferay.portal.kernel.io.unsync;resolution:=optional, com.liferay.portal.kernel.util;resolution:=optional, freemarker.cache;resolution:=optional, freemarker.template;resolution:=optional Export-Package: com.liferay.shipping.api.model;version="1.0.0", com.liferay.shipping.api.util;version="1.0.0" The BND tool (bnd.bndtools.org) can discover dependencies and automatically generate export/import manifest headers! Liferay SDK also allows you to use BND tool!
  13. OSGi services (this is how we provide and consume functionality)

    manifest manifest manifest manifest OSGi service registry Interface Service 1 ... Service N #3
  14. OSGi services (this is how we provide and consume functionality)

    manifest manifest manifest OSGi service registry Interface Service 1 ... Service N REGISTER REGISTER USE manifest #3
  15. #3 OSGi services (this is how we provide and consume

    functionality) manifest manifest manifest OSGi service registry Interface Service 1 ... Service N REGISTER REGISTER USE manifest There are number of component frameworks on top of OSGi (Declarative Services and Blueprint being part of the specs) which greatly simplify the usage of services!
  16. Application server / Servlet container Liferay 6.2 Portlet application Portlet

    application Portlet application Portlet application Liferay CORE Portlet Portlet ...
  17. Application server / Servlet container Liferay 6.2 Portlet application Portlet

    application Portlet application Portlet application Liferay CORE Portlet Portlet OSGi container ...
  18. Application server / Servlet container Liferay 6.2 Portlet application Portlet

    application Portlet application Portlet application Liferay CORE Portlet Portlet OSGi container OSGi core services HTTP Service Configuration Admin Service ... ... Liferay core OSGi services
  19. Application server / Servlet container Liferay 6.2 Portlet application Portlet

    application Portlet application Portlet application Liferay CORE Portlet Portlet OSGi container API Bundle API Bundle Service Bundle Extension bundle Service Bundle Portlet Bundle Extension Bundle Portlet Bundle OSGi core services HTTP Service Configuration Admin Service ... ... Liferay core OSGi services
  20. Application server / Servlet container Liferay 6.2 Portlet application Portlet

    application Portlet application Portlet application Liferay CORE Portlet Portlet OSGi container API Bundle API Bundle Service Bundle Extension bundle Service Bundle Portlet Bundle Extension Bundle Portlet Bundle OSGi core services HTTP Service Configuration Admin Service ... ... Liferay core OSGi services In Liferay 6.2 portlets inside OSGi container have certain limitations!
  21. There is an extra step in Liferay 6.2 as not

    all dependencies are provided! You will NOT need to do this in Liferay 7! #0 Shipping application modules (bundles)
  22. This approach is for Liferay 6.2 only ! It will

    change in Liferay 7 ! This approach is for Liferay 6.2 only ! It will change in Liferay 7 ! #3 Shipping application modules (bundles)
  23. Send feedback! Build your own OSGi modules Learn more about

    OSGi Try the samples yourself https://github.com/epgarcia/liferay-plugins/commits/LRNAS2014.OSGI