DS, BP, EJB, CDI, WTF!? - Graham Charters


Published on

OSGi Community Event 2013 (http://www.osgi.org/CommunityEvent2013/Schedule)

There are a number component models available to OSGi developers; Declarative Services (DS), Blueprint (BP), Enterprise JavaBeans (EJB), Contexts and Dependency Injection (CDI). Some have their roots in Java EE, some in open source projects such as the Spring Framework, others are standards at the OSGi Alliance, and some have DNA from all three. As is often the case where there are options available, there's rarely a one-size-fits-all. The 'right' choice may depend on the type of project you're working on, the existing assets, tools and skills at your disposal, and the runtime you're looking to deploy to. This talk will provide a brief overview of the four component models listed, describe their capabilities, standards coverage, tools support, and available implementations, and will show working examples of each, all in an effort to help OSGi users find a path to a component model best suited to their particular task.

Graham Charters is a Senior Technical Staff Member in the IBM WebSphere Application Server development organization. He is responsible for the OSGi Applications feature of the Application Server and a committer and PMC member of the Apache Aries OSGi programming model project. He is also the IBM technical lead in the OSGi Alliance Enterprise Expert Group.

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

DS, BP, EJB, CDI, WTF!? - Graham Charters

  1. 1. OSGi DevCon US 2013 DS, BP, EJB, CDI, WTF!? Graham Charters, IBM 1 © 2013 IBM Corporation
  2. 2. Agenda  Background  Criteria  Component models  How to choose 2 © 2013 IBM Corporation
  3. 3. Why? 4 © 2013 IBM Corporation
  4. 4. Approach  Provide some criteria to consider when making a component model choice  Explain a little bit about the technologies My beans are dynamic and use annotations.  Describe how each rates against the criteria Your beans smell!!  Reasons aren’t always technical  We probably won’t always agree 5 © 2013 IBM Corporation
  5. 5. Technical Criteria  Extra-bean definition (e.g. XML-based declarative model)  Intra-bean definition (e.g. bean annotationbased declarative model)  Extensibility  Enterprise Qualities of Service  Quality of Integration with OSGi 6 © 2013 IBM Corporation
  6. 6. Non-technical criteria  Open Standards  Open Source implementations  Choice of implementations  Availability of tools  Existing assets  Existing skills 7 © 2013 IBM Corporation
  7. 7. The technologies: DS, BP, EJB, CDI, WTF  Declaratives Services (DS)  Blueprint (not commonly known as BP)  Enterprise JavaBeans (EJB)  Contexts and Dependency Injection (CDI)  World Taekwondo Federation (WTF) Now with added demos! There are a number of other component models, but I’ve focused on the ones I heard discussed most often. They’re also all based on open standards 8 © 2013 IBM Corporation
  8. 8. The demo Http Service Whiteboard Http Service alias=/xyz 9 Component Servlet Service Time Service © 2013 IBM Corporation
  9. 9. Declarative Services Criterion DS Inspiration Popularity if DI frameworks, but designed for OSGi Approach Extra-bean definition (XML-based declarative model) Build-time intra-bean definition (annotations compiled to XML) @Component public class DiscountCalculatorImpl implements DiscountCalculator { private Logger logger; @Reference(policy=DYNAMIC, policyOption=GREEDY, cardinality=MANDATORY) void setLog( LogService log) { ... } void unsetLog( LogService log) { ... } void updatedLog( Map<String,?> ref ) { ... } } Extensibility Schema extensibility Enterprise QoS No OSGi Integration Designed by OSGi for OSGi. Includes Configuration <component name=“DiscountCalculator“ …> Admin Open Standards OSGi Alliance Implementations Eclipse Equinox & Apache Felix Tools BND & BNDTools 10 <implementation class="com.acme.utils.impl.DiscountCalculatorImpl"/> <service> <provide interface="com.acme.utils.DiscountCalculator"/> </service> <reference name=“log" interface="org.osgi.service.log.LogService" bind="setLog" unbind="unsetLog" updated=“updateLog" /> </component> © 2013 IBM Corporation
  10. 10. Blueprint Criterion Blueprint Inspiration Spring & Spring DM (standardized by SpringSource) Approach Extra-bean definition (XML-based declarative model, includes bean-tobean wiring) Intra-bean definition (Annotations – Apache Aries Open Source only) Extensibility Through XML namespaces – no runtime standard Enterprise QoS Transactions and Persistence (Apache Aries), Security (WebSphere Application Server), Bus (CXF), Camel, etc… OSGi Integration Some life-cycle compromises Config Admin (open source) Open Standards OSGi Alliance Updates in pipeline Implementations Eclipse Gemini & Apache Aries Tools WebSphere Developer Tools (no charge), Rational Application Developer 11 <?xml version="1.0" encoding="UTF-8"?> <blueprint …> <service id="DiscountCalculatorBeanService" ref="DiscountCalculatorBean" interface="com.acme.utils.DiscountCalculator" /> <bean id="DiscountCalculatorBean" class="com.acme.utils.impl.DiscountCalculatorImpl"> <property name="logger" ref="loggerService" /> </bean> <reference id="loggerService" interface="com.acme.utils.Logger" /> </blueprint> © 2013 IBM Corporation
  11. 11. Enterprise JavaBeans Criterion EJB Inspiration Version 1.0 - 15 years old Approach Inheritance & XML bindings (pre-3.0). Intra-bean definition (bean annotationbased declarative model) (3.0 or later) Extensibility Nothing formal (defer to CDI) Enterprise QoS Transaction, Security, Remoting, Persistence, Messaging OSGi Integration Core capabilities (proprietary) Open Standards JCP, OSGi specification in progress Implementations All JavaEE App Servers support EJB. OSGi integration in WebSphere Application Server, GlassFish, Apache Aries, Apache OpenEJB Tools 12 @Stateless @Local(DiscountCalculator.class) public class DiscountCalculatorImpl implements DiscountCalculator { @Resource(lookup="osgi:service/Logger") private Logger logger; public double discount() { … } … } WebSphere Developer Tools (no charge), Rational Application Developer, Eclipse WTP © 2013 IBM Corporation
  12. 12. Contexts and Dependency Injection Criterion CDI Inspiration JBoss Seam, Google Guice & Spring Approach Intra-bean definition (annotation-based life-cycle and DI model), Extra-bean opt-in beans.xml with additional config (e.g. extensibility) Extensibility Interceptors, Decorators & Portable Extensions Enterprise QoS @Inject @Service StaticLogger logger; None. Leverage CDI in other component models (e.g. EJB) OSGi Integration @Named @RequestScoped @Component public class DiscountCalculatorImpl implements DiscountCalculator { Core capabilities (Open Source) public double dicount() {...} ... Open Standards JCP, OSGi Alliance in progress Implementations Weld-OSGi, Pax-CDI, Fighterfish Tools EE Vendors tools 13 } © 2013 IBM Corporation
  13. 13. Some questions to ask when choosing No one component model to rule them all  What existing skills does my team have? – Choose the closest match (e.g. Spring? Consider Blueprint)  What existing assets do I have available? – Choose the closest match  Do I need Enterprise capabilities? – If “yes”, consider Blueprint or EJB, if “no”, consider DS  Do I want something based on a standard? – If “yes”, familarize yourself with the scope and direction of existing standards  Do I need something based on open source? – Apache Felix, Eclipse Equinox, Apache Karaf, Eclipse Gemini, Apache Aries, Eclipse Virgo, ….the list goes on…..  What are the capabilities of my target runtime? – If a component model isn’t supported, there’s little point choosing it  What are the capabilities of my tool chain? – If a component model isn’t supported, you’re asking for pain  What if I use more than one component model? – Leverage OSGi services as the common integration point 14 © 2013 IBM Corporation