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
IAC 2024 - IA Fast Track to Search Focused AI Solutions
HowTo Build an OSGI EJB3 Server
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.
3. 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
4. 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
5.
6. 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
8. 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
10. 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
11. 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
12. 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
13. 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
14. 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
15. 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
16. BIRT as Reporting Engine
Perfect Integration into Eclipse world
Reports direct from DB2 RDBMS
Reports directly using Hibernate Pojos
16
17. 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
18. 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
21. 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
22. 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
23. 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
24. Persistence MyBean.java (in a PersistenceContext Bundle)
Context
Configuration
META-INF/persistence.xml
Datei
config/easybeans.xml
Datei
24
25. 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
26. Business Interface Bundles
Bundles @Local,
Business - Interface Bundles
@Remote
Local or Remote
unlimited Bundles
structured per Subdomain, Product, ...
used on Client and Server
26
29. 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
30. 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
31.
32.
33.
34. 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
37. 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
47. 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
48. 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
51. 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
52. 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
53. 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
54. 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
55. Bundle Start
Order (6)
Using Declarative
Services
TODO:
replace
Easybeans Agent
by own
Implementation
using DS
48
56. Bundle Start
Order (6)
Using Declarative
Services
TODO:
replace
Easybeans Agent
by own
Implementation
using DS
48
60. Riena Remote Services (3)
Injecting Service
the Riena Way (fluent interfaces)
I prefer DeclarativeServices
52
61. 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
62. 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
63. 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
64. 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
65. 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
66. 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
67. Service Tracker (3)
DataSources ManagedServiceFactory registered
registered ?
easybeans.xml JDBCPool
Component ?
Yes
register JNDI for
DataSource
all DataSources
registered ?
57
68. 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
70. 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
71. 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
72. 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
73. Service Tracker (7)
ServiceTracker now tracks ManagedServices
tests for some Properties from EasyBeans
registers Services as RienaRemoteService
61
74. 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
75. 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
76. 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
77. 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
81. ion
lut
Declarative Services (3) so
al
fin
Example „EasyBeans Components started ?“
65
82. 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
84. 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
85. 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
86. 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
87. Logging with OSGI and 3rdParty
OSGI Logging
'classic' Logging
Compare LoggingFrameworks
HowTo integrate them all
71
94. 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
95. HowTo solve Dependency Cycles
Eclipse 3.5M6 PDE Tooling Support
dont forget to set Compiler Warnings:
79
96. Classloader from 3rd party
EasyBeans contains Hibernate
Hibernate uses ContextClassLoader
Try to avoid
Dynamic Import *
BuddyPolicy only if really needed
80
97.
98. 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
102. 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
108. 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
109.
110.
111.
112.
113. Next Steps
Other ways to persist ?
More M2M Transformations
Give Value back to Open Source Community
94
114. 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
115. 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
121. 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