Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Hybrid Applications

1 780 vues

Publié le

A presentation about how to create and combine Java EE and OSGi (aka hybrid application). Presentation held at Devcon12 2012 (Sweden, Karlskrona)

Publié dans : Technologie
  • Soyez le premier à commenter

Hybrid Applications

  1. 1. HYBRID APPLICATIONS - Combining the Power of Java EE and OSGiANDREAS ENBOHM (@enbohm)2012-09-13
  2. 2. About Me
  3. 3. Agenda Introduction Java EE OSGi + Java EE Demo - Java EE + OSGi - Glassfish V3 Future<?>
  4. 4. Why This Presenation?Homer Simpson Programming Model: ”Let some else do it!”
  5. 5. Java EE
  6. 6. Java EE”The industri standard for enterprise computing. JEE isused for mission-critical, large-scale, multi-tiered,scalable, reliable, and secure applications”
  7. 7. Java EE A set of API - JTA, JPA, JSF, EJB, JMS, JCA, Servlet, CDI, JAX-WS, JAX-RS… Application Servers - Oracle AS, IBM Websphere, Apache Geronimo, JBoss, Glassfish, JOnAS, TomEE, Resin… Used within - Finance - Telecom - Manufacturing -…
  8. 8. Ewok* EJB Appreciation*Ewoks from motion picture ”Star Wars Return of the Jedi”
  10. 10. ”EJB/J2EE IS HEAVYWEIGHT” EJB != heavyweight - acctually its considered ultra-lean - please tell if anyone know any other tech! One jar file (java-ee-6.jar, 967 kB) One single annotation - @Stateless Glassfish (55/200MB) - restart in ~3 seconds - hot deployment - full OSGi support
  11. 11. Why Java EE Hyper productive - time-to-market Maximize focus on Business functionality - Inversion of control (DI) - Decorators - Aspects - Schedulers - Events - Asyncronous calls -… Helps you with a lot of non-functional requirements
  12. 12. Why Java EE Thread-safe - every thread gets it own bean instance Transaction management - transaction are automatically started, commited or rollbacked Pooling of Session beans - prevent DDOS attacks - scale up/down Distributed components - runs in a multi-tier architecture - failover, scalability
  13. 13. Why Java EE Deployment - very few (if any) xzy.xml deployment desc. - runs on several app servers and/or clouds Elastic
  14. 14. Why Java EE Ultra-lean - what more can be removed?
  15. 15. EJB Component Plain interface (not required)public interface PaymentService { public ProductReceipt pay(int productId);} EJB-annotation (convention over configuration)@Statelesspublic class PaymentEJB implements PaymentService { public ProductReceipt pay(int productId){ //implementation goes here }}
  16. 16. TDD and Java EE Unit test - POJO Integration test - embedded container - arquillian - pax exam
  17. 17. TDD and Java EEEJBContainer container = EJBContainer.createEJBContainer();Context ctx = container.getContext();PaymentService service = (PaymentService) ctx.lookup("java:global/classes/PaymentEJB");Assert.assertNotNull(service);
  18. 18. Areas Not Covered by Java EE Java lacks (real) modularity - known problem since day 1 - many app servers builds on OSGi - may change when Project Jigsaw is release (2013) Service tracking Criteria-based service selection ”Jar-hell” - NoSuchMethodException - Classpath / Dependencies
  19. 19. Areas Not Covered by Java EE Well defined life-cycle of components Multiple instances of a service/component Hot-swapping* of components * debug mode doesn’t count
  20. 20. Hello OSGi!“OSGi technology provides a service-oriented,component-based environment for developers andoffers standardized ways to manage the softwarelifecycle.” - Wikipedia
  21. 21. Hello OSGi!Simply put, a modularity layer for the Java platform
  22. 22. Why OSGi Separation of concerns (i.e modularization) Key concepts - Cohesion - Coupling Containers - Apache Felix - Knopflerfish - Equinox
  23. 23. Why OSGi But how about OO in Java? - OO is all about high cohesion and low coupling, right? Java has a limited modularization - no transitive dependencies - public (keyword) is ’too public’ - error prone class path - low-level modularization (packages)
  24. 24. OSGi Layers OSGi Layered Architecture Module - packaging and sharing of code Life Cycle - module management Service - interaction between modules
  25. 25. OSGi Module Layer Bundle –a unit of modularity in OSGi Package as a JAR (classes + MANIFEST.MF with OSGi metadata) Versionable Clear dependency declaration Clear dependency resolution rules
  26. 26. OSGi Metadata Manifest.MF Manifest-Version: 1.0 Built-By: aenbohm Bundle-ManifestVersion: 2 Bundle-Name: hybridCommon Bundle-SymbolicName: hybridCommon Bundle-Version: 1.0.0 Export-Package: com.acme.hybrid.devcon.entity;version="1.0.0" Import-Package: javax.persistence,javax.xml.bind.annotation
  27. 27. OSGi Life Cycle Layer Life Cycle
  28. 28. OSGi Service Layer Services registry - register - unregister Service is a POJI - focus on the contract/interface - reduce coupling Service discovery - LDAP filter based queries
  29. 29. Best of Both Worlds How about combining JEE & OSGi? - productivity - reusable bundles with visible dependencies - version control of components - automatic transaction handling - ..
  30. 30. Hello Hybrid Application! © 2012 Capgemini. All rights reserved. 31
  31. 31. Hybrid Applications“a hybrid application bundle is an OSGi bundle as wellas a Java EE module. Atruntime, it has both an OSGi bundle context and a JavaEE context.”
  32. 32. Hybrid Applications Allows you to develop managed, transactional OSGi services with little knowledge of OSGi Makes your EJB:s available as OSGi services with little effort - bundles can use Java EE services like JTA, JPA, etc Supports Stateless and Singleton EJBs
  33. 33. Hybrid ApplicationsHow to turn your JavaEE artifacts to OSGiServices?
  34. 34. Hybrid Applications Manifest.MF…Implementation-Title: hybridImplementation-Version: 1.3Bundle-ClassPath: WEB-INF/classes/Bundle-Name: hybridBundle-SymbolicName: com.acme.hybrid.service.implBundle-Version: 1.3.0Export-EJB: ALLWeb-ContextPath: /hybrid… WAB (web application bundle); OSGi Spec. 4.2
  35. 35. Hybrid Applications EJB artifacts + Manifest.MF = ’Declarative’ Service - Enterprise Application Bundle (EAB) - Web Application Bundle (WAB) Export-EJB: List of EJBs to be exported as OSGi services. - Values: NONE, ALL or fully qualified name
  36. 36. Hybrid Applications In VM SOA - service-oriented design - domain-driven design Different support for hybrid apps - JBoss - Glassfish - IBM Websphere - Geronimo This makes hybrid apps less portable! - RFP 152 ”EJB Integration” - RFP 146 ”OSGi/CDI Integration”
  37. 37. Glassfish + OSGi OSGi R4, version 4.2 compliant - Uses Apache Felix as OSGi runtime Jave EE / OSGi services in Glassfish - JTA - JPA - JMS - HTTP Service - Event Admin - Config Admin -…
  38. 38. Glassfish + OSGi Type safe injection with CDI Extension ServiceTracker tracker = new ServiceTracker(context, Hello.class.getName(), null); tracker.open(); Hello hello = (Hello) tracker.getService(); System.out.println(hello.sayHello("Duke")); With CDI annotation: @Inject @OSGiService(dynamic=true) Hello hello; System.out.println(hello.sayHello("Duke"));
  39. 39. PROVE IT ! (Demo time) Asyncronous invocations Events Decorators Service update (hot deployment) REST service
  40. 40. Demo Overview HybridCommon (standard OSGi bundle containing domain objects) <uses> <uses> HybridClient OSGi Service HybridBackend(WAB exposes a service via Jax-RS) Registry (EJB as OSGi service, EAB) <discover> <publish>
  41. 41. CONS JEE + OSGi ”With great power comes great complexity” - combining OSGi + JEE - two different component models - developers need to know both models - not all app server have (full) hybrid support - different containers with different characteristics Technology overlap of Java EE and OSGi - events, security, monitoring… Declarative Services, iPojo, Blueprint, ServiceTracker…
  42. 42. FUTURE<JavaEE&OSGi>Project Jigsaw
  43. 43. FUTURE<JavaEE&OSGi> Project Jigsaw - monolitic JVM - will address both compile & runtime (Maven + OSGi) - no service register nor life cycle handling - (probably) not until Java 9
  44. 44. FUTURE<JavaEE&OSGi>OSGi + Maven?
  45. 45. FUTURE<JavaEE&OSGi> OSGi - CDI integration - EJB incorporation - more app servers will support hybrid apps Jigsaw and OSGi will definitely co-exist - Project Penrose
  46. 46. SUMMARY Features in Java EE and OSGi - productivity and modularity How to combine them - WAB/EAB Demonstrated a hybrid application - using Glassfish + Apache Felix
  47. 47. USEFUL LINKSwww.osgi.orgwww.glassfish.orghttp://www.oracle.com/technetwork/java/javaee/overview/index.htmlhttp://www.jboss.org/arquillian.htmlhttp://mreinhold.org/blog/late-for-the-train-qa | Sector, Alliance, Offering
  48. 48. Q&Ahttp://www.slideshare.net/enbohm Twitter: @enbohm © 2012 Capgemini. All rights reserved. 49
  49. 49. www.se.capgemini.comThe information contained in this presentation is proprietary. ©2012 Capgemini. All rights reserved