HowTo Build an OSGI EJB3 Server

4,564 views

Published on

This is an overview how to build an OSGI EJB3 Server I gave at OSGIExpertsDay at JAX09.
The Server is build using:
Eclipse Equinox as OSGI Framework
Eclipse Riena for Remote OSGI Services
EasyBeans as OSGI EJB3 Container
Hibernate as JPA Provider
Clients are Rich Clients (Eclipse RCP)
The project is model-driven using UML (MagicDraw), EMF (Eclipse Modeling) and oAW (openArchitectureWare).

more info:
http://ekkes-corner.org (blog english)
http://ekkes-ecke.org (blog german)
http://ekkes-corner-tv.org (Video PodCasts)

You want to watch the slides with included screencasts ? here's the movie:
http://www.vimeo.com/ekkescorner/videos

Published in: Technology
1 Comment
8 Likes
Statistics
Notes
No Downloads
Views
Total views
4,564
On SlideShare
0
From Embeds
0
Number of Embeds
69
Actions
Shares
0
Downloads
245
Comments
1
Likes
8
Embeds 0
No embeds

No notes for slide

HowTo Build an OSGI EJB3 Server

  1. 1. Ekkehard Gentz, Independent Software Architect HowTo Build an OSGI EJB3 Server OSGI Experts Day 2009-05-24 1  (c) 2009 ekkehard gentz, eclipse public license EPL
  2. 2. Who am I  ekke  Ekkehard Gentz, Rosenheim  Freelancer, Software Architect, ERP Consultant  Business Developer (ERP Solutions)  Assembler, Cobol, Pascal,4GL, Java  Domains: Apple Dealer, Paper Manufacturer, Waste & Recycling, ... 3
  3. 3. Why this session  So many articles and guidelines about OSGI:  how to do it the right way  Is this reality for OSGI Enterprise Apps ? you have to...  ... live with existing code  ... use 3rd party bundles  ... integrate different OSGI products, frameworks etc 4
  4. 4. Business Project Overview  Project built from scratch  Business Processes and Rules change 'daily'  Short time-frame  Small Project Ressources  Possible to make it run ? 6
  5. 5. 7
  6. 6. Business Project Requirements  Easy to use for business users  Server 24*7 online  Rich Clients with great UI comfort  Processes and Rules change heavy and often  Has to run on different OS (XP, Vista, OSX) 8
  7. 7. Project Decisions  Frameworks  Tools  Technology 9
  8. 8. Design and Modeling Tools  UML (MagicDraw)  MD DSL Customization Engine  MD Customized Domain-Specific Editors  MD Reader available  Eclipse - Integration  Why not EMF - only ?  Combine UML and EMF  oAW as Generatorframework 10
  9. 9. Eclipse RCP (SWT) as Rich Client  Eclipse RCP Platform  plus Riena UI  Ridgets  Markers  Validators  plus Riena Navigation  plus redView dynamic Views for Business Apps  CDO distributed view models 11
  10. 10. OSGI (Equinox) as Server  OSGI  modular, dynamic updates  flexible server architecture  Why Equinox as OSGI Framework ?  its Eclipse ;-)  Riena uses Buddy Policy  so I‘m bound to Equinox 12
  11. 11. Services and Persistence: EJB3, JPA  Easybeans choosen  pure OSGI bundle implementation  vs WSAD, Glassfish or other OSGI-based JEE Server:  integrate Easybeans into your OSGI Enterprise app  all is under your control, no deploy to Appserver  Hibernate as JPA provider  my knowledge of Hibernate  already bundled with EasyBeans OSGI 13
  12. 12. Drools Business Rules and Process Flow  First decision: jBPM + Drools  jBPM as BusinessProcess Engine  Drools as Rules Engine + Decision Nodes in jBPM  Drools 5 supports both:  Business Process Flow  Business Rules 14
  13. 13. RDBMS: IBM DB2 Express  Relational data and xml data can be mixed  low costs for small companies  scales well if company grows  I know it 15
  14. 14. BIRT as Reporting Engine  Perfect Integration into Eclipse world  Reports direct from DB2 RDBMS  Reports directly using Hibernate Pojos 16
  15. 15. Why OSGI and EJB3  EJB3 Standard  Out of the box directly from EJB3 Container  services  persistence  transactions  OSGI goes Enterprise  Easybeans OSGI JPA Container 17
  16. 16. Why not CDO to persist Business Models  Pros:  all stored in EMF Models, EMF Databinding  no lazy exceptions from hibernate at client side  scales very well, persistence (Teneo, Hibernate)  Cons:  model evolution not supported, no data-migration  no reporting tools like BIRT to use CDO repositories  future: could be an alternate way 18
  17. 17. OSGI Server  Bundles  entity  ejb, interfaces  enumerations  Fragments  icons, fonts, OS-dependent-styles  Logging Utils, Logging Configuration 19
  18. 18. OSGI Server (Bundles)  Bundles @Local, Business - Interface Bundles  entity @Remote @Stateless, EJB Bundles  ejb @Stateful @EJB implements implements  interfaces @Stateless @PersistenceContext injects uses @Entity,  enumerations @Embeddable uses PersistenceContext Bundles Entity Bundles Enum Enumeration Bundles 20
  19. 19. Entity Bundles  Bundles @Entity,  unlimited @Embeddable  per Subapplication  per Subdomain Entity Bundles  Productfamilies  Tip:  used at Client and Server  Server-only Dependencies should be optional 21
  20. 20. Enumeration Bundles  Bundles  per Subapplication Enum  per Subdomain Enumeration Bundles  per Customer / Product  Why separate Bundles ?  Enumeration Literals different per Customers  Easy to change / enhance  Also used by Business Processes, Rules 22
  21. 21. PersistenceContext Bundles @Stateless  Bundles @PersistenceContext  Stateless Beans  implements BusinessInterfaces PersistenceContext Bundles  contains PersistenceContext (EntityManager)  only used at Server  Tip:  JIRA EZB-294 all EJB‘s of PersistenceContext = 1 Bundle  All @Entity and @Embeddable must be listed inside persistence.xml because of a Bug 23
  22. 22. Persistence MyBean.java (in a PersistenceContext Bundle) Context Configuration META-INF/persistence.xml Datei config/easybeans.xml Datei 24
  23. 23. EJB Bundles @Stateless,  Bundles EJB Bundles @Stateful @EJB  Stateless or Stateful  only used at Server  can inject other EJB‘s from PersistenceContext Bundles  Productfamilies  Tip:  @EJB(mappedName) BusinessInterface  JIRA EZB-322 can‘t found Interfaces from other Bundles 25
  24. 24. Business Interface Bundles  Bundles @Local, Business - Interface Bundles @Remote  Local or Remote  unlimited Bundles  structured per Subdomain, Product, ...  used on Client and Server 26
  25. 25. OSGI Server (Fragments)  Fragments  Icons  Fonttemplates  OS-dependent-styles  Logging - Utilities 27
  26. 26. MDSD  openArchitectureWare (oAW)  perfect integrated into eclipse  working with UML and EMF models side-by-side  generating:  Entity, EJB, Business Interfaces  BusinessProcess /-rules Integration  EMF View models from Entity  configuration files and more 29
  27. 27. oAW mo )… e raw es … D ime icD lat ckt ag Qui (M mp Views) ram re) Te iag Wa mic D tity cture yna En -D hite ML MF U Arc iena - E pen (o (R iew edV r
  28. 28. Eclipse Workspaces and Installations  Overview  Different Eclipse Installations for different Roles  Architect and Modeler  Client-Server-Platform Developer  UI Designer (Development)  UI Design and Prototyping (Business User) 32
  29. 29. Eclipse Workspaces and Installations Eclipse Installations Eclipse Workspaces java entity Eclipse Modeling my oAW ejb Cartridges services processes Modeling EMF UML2 openArchitectureWare uses - XPand - XTend - Workflow abc Project foo Workflows sample generates Project code Project quot;fooquot; Eclipse Runtime Runtime Target Platform entity ejb - beans Equinox ejb - api Project RCP services Bundles Riena processes EasyBeans rules ui 33
  30. 30. 34
  31. 31. Problems to solve  Integrate 3rd Party  Bundle Start Order  Services, ServiceTracker or DS ?  Logging Frameworks and OSGI  Dependency Cycles  Classloader used by 3rdParty  How to configure Target Platform  Problems solved using oAW 35
  32. 32. 36
  33. 33. HowTo integrate 3rdParty Bundles (1)  Are they all brave OSGI citizens ?  1 jar == 1 bundle  import package instead of required bundles ?  always Versioning Bundles and Dependencies ? 37
  34. 34. dle mo Bun -) De ime ter “; kt ns uic rs ? Mo GI Q ja S n O unt the ea sid co n you ki loo can …„ or …
  35. 35. HowTo integrate 3rdParty Bundles (2)  Are there any Monsters ?  look inside EasyBeans core bundle  Are there dependency - cycles ?  SLF4J + Logback, Easybeans 41
  36. 36. 42
  37. 37. Bundle Start Order (1)  Goal: Try to avoid Start-Levels needed  but 3rdParty:  Agents like EasyBeans Agent  Logging first if using Log Bridges from OSGI  start first to avoid black holes 43
  38. 38. Bundle Start Order (2)  To make a System run:  try using Start-Levels  then Iterations:  Add OSGI Services  Add ServiceTracker to start Bundles  Add DeclarativeServices to reduce ServiceTracker Complexity 44
  39. 39. Bundle Start Order (3) 45
  40. 40. Bundle Start Order (3) ns io at er it ly ar e 45
  41. 41. Bundle Start Order (4)  ServerAgent  tracks Services from EasyBeans using a ServiceTracker  registers @Remote Interfaces for Riena  registers a Service if all is done 46
  42. 42. Bundle Start Order (4) ns io at er it ly ar e  ServerAgent  tracks Services from EasyBeans using a ServiceTracker  registers @Remote Interfaces for Riena  registers a Service if all is done 46
  43. 43. Bundle Start Order (5)  MyServer  waits for the ServerAgent - Service  registers a Service if all is ready  registers this also as RienaRemote Service  now the Clients know that the Domain Server runs 47
  44. 44. Bundle Start Order (5) ns io at er it rly ea  MyServer  waits for the ServerAgent - Service  registers a Service if all is ready  registers this also as RienaRemote Service  now the Clients know that the Domain Server runs 47
  45. 45. Bundle Start Order (6)  Using Declarative Services  TODO:  replace Easybeans Agent by own Implementation using DS 48
  46. 46. Bundle Start Order (6)  Using Declarative Services  TODO:  replace Easybeans Agent by own Implementation using DS 48
  47. 47. Services, Services, Services...  Riena Remote Services  EasyBeans Services  ServiceTracker  Declarative Services (DS)  ServiceTracker vs DS 49
  48. 48. Riena Remote Services (1) 50
  49. 49. Riena Remote Services (2)  Publishing Service 51
  50. 50. Riena Remote Services (3)  Injecting Service  the Riena Way (fluent interfaces)  I prefer DeclarativeServices 52
  51. 51. EasyBeans Services (1)  EasyBeans registers Services for each Business Interface (@Local, @Remote)  thanks to the EZB Team:  changed to ManagedServices, so Properties can easy used  in Filters of ServiceTrackers  or DeclarativeServices (DS) 53
  52. 52. EasyBeans Services (2)  EasyBeans registers:  ManagedServiceFactory Services for each EasyBeans components:Transactions, Mail, JDBCPool, JMS, etc  EZBContainer Services EJB3Container ready PersistenceContext: Hibernate Mapping, Binding  JDBCPoolComponent  the DataSource is available 54
  53. 53. Service Tracker (1)  start EJB Bundles ? ManagedServiceFactory registered all EZB JDBCPool Components Component ? registered ? Yes register JNDI for DataSource all DataSources registered ? Yes Yes Start EJB Bundles 55
  54. 54. Service Tracker (1)  start EJB Bundles ? ManagedServiceFactory registered all EZB JDBCPool Components ns Component ? registered ? io at Yes er it register JNDI for ly DataSource ar e all DataSources registered ? Yes Yes Start EJB Bundles 55
  55. 55. Service Tracker (2)  EasyBeans ManagedServiceFactory registered Components ?  carol, hsqldb, all EZB Components registered ? jotm, quartz, event, jmx, jdbcpool, joram  Services named like carol-component-factory  56
  56. 56. Service Tracker (2)  EasyBeans ManagedServiceFactory registered Components ?  carol, hsqldb, all EZB Components ns registered ? io jotm, quartz, at er event, jmx, it ly jdbcpool, joram ar e  Services named like carol-component-factory  56
  57. 57. Service Tracker (3)  DataSources ManagedServiceFactory registered registered ?  easybeans.xml JDBCPool Component ? Yes register JNDI for DataSource all DataSources registered ? 57
  58. 58. Service Tracker (3)  DataSources ManagedServiceFactory registered registered ?  easybeans.xml JDBCPool ns Component ? io at Yes er it register JNDI for ly DataSource ar e all DataSources registered ? 57
  59. 59. Service Tracker (4) 58
  60. 60. Service Tracker (5)  start EJB Bundles: ManagedServiceFactory registered  EasyBeans creates all EZB EJB3-Container JDBCPool Components Component ? registered ? for each Yes PersistenceContext register JNDI for DataSource Bundle all DataSources registered ? Yes Yes Start EJB Bundles 59
  61. 61. Service Tracker (5)  start EJB Bundles: ManagedServiceFactory registered  EasyBeans creates all EZB EJB3-Container JDBCPool Components ns Component ? registered ? io for each at Yes er PersistenceContext it register JNDI for ly DataSource ar Bundle e all DataSources registered ? Yes Yes Start EJB Bundles 59
  62. 62. Service Tracker (6)  EasyBeans registers: ManagedServices registered by EasyBeans ManagedService registered for Business - Interfaces implemented by @Stateless or @Statefull Beans from EJB - Bundles  ManagedService for Remote Business - Interface ? @Local, @Remote Yes register as Riena Remote Endpoint  EZBContainer EZB Container Service registered Service for each EZBContainerServices Container for all EJB Bundles ? registered by EasyBeans EJB3-Container for each EJB - Bundle Yes register RienaEasyBeansServerService 60
  63. 63. Service Tracker (7)  ServiceTracker now tracks ManagedServices  tests for some Properties from EasyBeans  registers Services as RienaRemoteService 61
  64. 64. ns io at Service Tracker (7) er it ly ar e  ServiceTracker now tracks ManagedServices  tests for some Properties from EasyBeans  registers Services as RienaRemoteService 61
  65. 65. Service Tracker (8)  All logic around EasyBeans EJB3-Container at a central point  Sounds good ?  Difficult to maintain or to test  What to do ? 62
  66. 66. Declarative Services (1)  We can describe the same complex logic solved with ServiceTracker using  DeclarativeServices (DS)  let the OSGI Framework do the work  easy to maintain  lazy loading of Bundles  Eclipse 3.4 Ganymede: edit XML files  Eclipse 3.5 Galileo: PDE Tooling-Support 63
  67. 67. ion lut Declarative Services (1) so al fin  We can describe the same complex logic solved with ServiceTracker using  DeclarativeServices (DS)  let the OSGI Framework do the work  easy to maintain  lazy loading of Bundles  Eclipse 3.4 Ganymede: edit XML files  Eclipse 3.5 Galileo: PDE Tooling-Support 63
  68. 68. Declarative Services (2)  Example „EasyBeans Components started ?“ 64
  69. 69. ion lut Declarative Services (2) so al fin  Example „EasyBeans Components started ?“ 64
  70. 70. Declarative Services (3)  Example „EasyBeans Components started ?“ 65
  71. 71. ion lut Declarative Services (3) so al fin  Example „EasyBeans Components started ?“ 65
  72. 72. Declarative Services (3)  OSGI Runtime with DeclarativeServices  Wondering why a DS not started ?  Tip:  set debug-trace-log vm-parameters: -Dequinox.ds.debug=true 66
  73. 73. Declarative Services (4)  Console Output: 67
  74. 74. Declarative Services (5)  some more Properties:  equinox.ds.print=true prints tracelogs to console  equinox.ds.perf=true logs execution times in ms  equinox.scr.waitTimeOnBlock=10000 how many ms should DS ait until a service component is ready 68
  75. 75. Service Tracker vs Declarative Services  Are DS replacement for ServiceTracker (ST) ?  ST has access to all methods of a Service  DS only access to properties  Missing graph visualization for some Dependencies 69
  76. 76. Service Tracker vs Declarative Services  Over all my recommendation:  Use Declarative Services where possible  Equinox DS will do all the difficult work for you 70
  77. 77. Logging with OSGI and 3rdParty  OSGI Logging  'classic' Logging  Compare LoggingFrameworks  HowTo integrate them all 71
  78. 78. OSGI Logging  LogService  Equinox Extended LogService  graduated soon 72
  79. 79. Classic Logging  Log4J  CommonsLogging  SLF4J  JDK Logging (java.util) 73
  80. 80. Logging used by ...  ...Easybeans  Commons-Logging  JDK Logging  Riena  Extended LogService  Start Parameters, ExtensionPoint  Hibernate  switched from CommonsLogging to SLF4J 74
  81. 81. Compare LogFrameworks 75
  82. 82. HowTo integrate them all  SLF4JoverOSGI Bridge  SLF4J with logback implementation  catches JCL, JDK, SLF4J, OSGI Log, ext. Log  Marker and Bundles  Fragments  alternate Solution: PAX Logging  Log4J  catches JCL, JDK, SLF4J, Avalon 76
  83. 83. HowTo integrate them all 77
  84. 84. HowTo solve Dependency Cycles  Eclipse 3.4  PDE Export has Problems with Cycles  Equinox Runtime works well  Trick:  put a „Fake“ Bundle without Dependencies into Workspace 78
  85. 85. HowTo solve Dependency Cycles  Eclipse 3.5M6 PDE Tooling Support  dont forget to set Compiler Warnings: 79
  86. 86. Classloader from 3rd party  EasyBeans contains Hibernate  Hibernate uses ContextClassLoader  Try to avoid  Dynamic Import *  BuddyPolicy only if really needed 80
  87. 87. HowTo configure the TargetPlatform (1)  Overview  TargetPlatformDefinition Files  to be portable: variable - string substitution  PDE Tooling 3.5 easier  Duplicates, Deltas  Bugzilla Reports discuss better PDE Tooling support 82
  88. 88. HowTo configure the TargetPlatform (2)  Locations 83
  89. 89. HowTo configure the TargetPlatform (3) 84
  90. 90. HowTo configure the TargetPlatform (3) 84
  91. 91. oAW - your little Helper  EZB, Hibernate Bug Annotations  generate classnames into persistence.xml  Check JPA Persistence data  length of indizes, tables, inheritance strategies  EZB problems JNDI naming  generate mapped Names into Interfaces  Bridge between UML and EMF  from UML to EMF - UI and back 85
  92. 92. oAW - solves Bug detecting Entity  generate classnames into persistence.xml 86
  93. 93. oAW - solves Bug injecting @EJB (1)  generate @EJB.mappedName 87
  94. 94. oAW - solves Bug injecting @EJB (2)  generate @EJB.mappedName 88
  95. 95. oAW - solves Bug injecting @EJB (3)  generate @EJB.mappedName  now its easy to use: @EJB (mappedName = MyInterface.EZB_MAPPED_NAME) MyInterface mi = null; 89
  96. 96. Summary  Server  Equinox (OSGI Framework), Riena (OSGI RemoteServices)  EasyBeans (OSGI EJB3 Container, JPA, Hibernate)  Rich Client  Eclipse RCP, Riena (UI Ridgets and Navigation)  Riena (OSGI Remote Services, ObjectTransactions)  ModelDriven Project  Eclipse Modeling (EMF, UML, CDO)  openArchitectureWare (oAW): Workflow, XPand, Xtend  MagicDraw (UML, DSL, oAW Integration) 90
  97. 97. mo na, db De rie ata to me ox, e d kti uic uin som ith Q q r: e rite es w rve … w fil log se the EJB3 ck) ba art ans log st 4J/ e syb h (SLF ea tc wa … h… lilit
  98. 98. Next Steps  Other ways to persist ?  More M2M Transformations  Give Value back to Open Source Community 94
  99. 99. Alternate Ways to Persist Data  EasyBeans and EclipseLink  EasyBerans provides both: Hibernate + EclipseLink  CDO with Teneo Hibernate  re-use of JPA Annotations for Teneo  EMF Databinding  CDO remoting instead of RienaRemoteOSGI  possible ???? 95
  100. 100. Extra M2M transformation  whole Business Model as EMF  extra M2M transformation from UML  pro:  redView Drag‘n‘Drop for Databinding  needed if CDO in the future becomes an alternative 96
  101. 101. 97
  102. 102. open-erp-ware.org (1)  Open Source OSGI - EJB3 - Riena Server  core equinox-EasyBeans OSGI-EJB3 server  UML Profiles (Java, JPA, EJB3, Drools)  oAW Templates and Cartridges  MagicDraw DSL Customization + Editors  Riena for Remote OSGI Services  plus core ERP functionality (business modules)  first beta published in june 2009 98
  103. 103. open-erp-ware.org (2)  slf4joverOSGI  LoggingBridge  could be used additional to SLF4J / LogBack Bridges 99
  104. 104. redView - Riena EMF Dynamic Views  Open Source Dynamic Views for Business Applications  EMF  CDO  Ridgets  Prototyping  WYSIWYG Editor for dynamic SWT Views 100
  105. 105. Question & Answer  ekke@ekkes-corner.org  Blog: http://ekkes-corner.org (en)  Blog: http://ekkes-ecke.org (de)  Video Podcasts: http://ekkes-corner-tv.org  Twitter: @ekkescorner  http://open-erp-ware.org  http://redview.org 101
  106. 106. Video Podcast  you like to watch and hear this screencast as a Video Podcast ?  visit: http://ekkes-corner-tv.org  or search iTunes for „ekkes-corner“  (c) 2009 ekkehard gentz, eclipse public license EPL 102

×