Leveraging OSGi to Create
Extensible Plugins for Liferay 6.2
!
Eduardo García @epgarcia
Julio Camarero @juliocamarero
!
Core Engineers at Liferay, Inc
#LRNAS2014
#LRNAS2014
OSGi is about 

modularity
#LRNAS2014
… and Liferay already
allowed for modularity
#LRNAS2014Portlets, hooks, themes, templates…
Hot Deployable modules (plugins)
#LRNAS2014Portlets, hooks, themes, templates…
Hot Deployable modules
#LRNAS2014
… but modules were not
modular!!
#LRNAS2014
OSGi brings into 

Liferay 6.2 

modularity of modules :)
#LRNAS2014
#LRNAS2014
#LRNAS2014
Microservices
Supported in the
marketplace from
this week
#LRNAS2014
Let’s see an example…
A Shipping Cost Calculator
https://github.com/epgarcia/liferay-plugins/commits/LRNAS2014.OSGI
#LRNAS2014
final price
common features
for all countries
specific features for
each country
#LRNAS2014
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
#LRNAS2014
OSGi makes this 

possible in

Liferay 6.2
#LRNAS2014
Actually, this will be the
future of all Liferay 7
applications, so…

Welcome to the future!
#LRNAS2014
Audience Targeting is the first
Liferay app following this approach
#LRNAS2014
It’s all advantages!
Improves
maintainability
Maximizes
reusability
Simplification
of releases

(independent)
New Market
opportunities
(extensions)
#LRNAS2014
#LRNAS2014
#LRNAS2014
Sounds great, but I have
no idea about OSGi…
!
:_(
Leveraging OSGI #LRNAS2014
No worries, today we'll tell you all you need to know!
Through a practical use-case sample, you will
learn how to:
!
• Create OSGi plugins with the Liferay SDK
• Make your plugin hot-extensible
• Add OSGi extensions to your core plugin
Leveraging OSGI #LRNAS2014
Leveraging OSGI #LRNAS2014
Required Services for our app
• Extensions Registry
• Extensions (e.g. USA Shipping Cost,
Europe Shipping Cost…)
Leveraging OSGI #LRNAS2014
A service is composed by:
• An API (contract)
!
• Implementations (1 or more)
#LRNAS2014
ShippingExtension
interface
#LRNAS2014
ShippingExtensionUSA

@Component
#LRNAS2014
ShippingExtensionRegistry
@Reference
#LRNAS2014
ServiceTrackerUtil 

is the tool to consume
OSGi services from non-
OSGi contexts
#LRNAS2014
bnd.bnd file defines
interdependencies
between modules

(most of them are auto-calculated)
#LRNAS2014
And the whole app can be modular too
Leveraging OSGI #LRNAS2014
For more information
• Visit the new Liferay Dev Site
!
• Don't miss:
• “Microservices: The OSGi Way”

by Miguel Pastor – Tue. 2.40pm Back Bay C
• “Extending Audience Targeting” 

by Julio Camarero – Mon. 15.10 Gardner
#LRNAS2014
Thank you! :)
!
Questions?
@edupgv @juliocamarero

Leverage OSGI to create Extensible plugins for Liferay 6.2