HowTo Build an OSGI EJB3 Server
-
Upload
ekkehard-gentz -
Category
Technology
-
view
7.794 -
download
0
description
Transcript of HowTo Build an OSGI EJB3 Server
1
Ekkehard Gentz, Independent Software Architect
HowTo Build an OSGI EJB3 Server
OSGI Experts Day 2009-05-24
(c) 2009 ekkehard gentz, eclipse public license EPL
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, ...
Who am I
3
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
Why this session
4
Project built from scratch
Business Processes and Rules change 'daily'
Short time-frame
Small Project Ressources
Possible to make it run ?
Business Project Overview
6
7
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)
Business Project Requirements
8
Frameworks
Tools
Technology
Project Decisions
9
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
Design and Modeling Tools
10
Eclipse RCP Platform
plus Riena UI Ridgets
Markers
Validators
plus Riena Navigation
plus redView dynamic Views for Business Apps
CDO distributed view models
Eclipse RCP (SWT) as Rich Client
11
OSGI modular, dynamic updates
flexible server architecture
Why Equinox as OSGI Framework ? its Eclipse ;-)
Riena uses Buddy Policy
so I‘m bound to Equinox
OSGI (Equinox) as Server
12
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
Services and Persistence: EJB3, JPA
13
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
Drools Business Rules and Process Flow
14
Relational data and xml data can be mixed
low costs for small companies
scales well if company grows
I know it
RDBMS: IBM DB2 Express
15
Perfect Integration into Eclipse world
Reports direct from DB2 RDBMS
Reports directly using Hibernate Pojos
BIRT as Reporting Engine
16
EJB3 Standard
Out of the box directly from EJB3 Container services
persistence
transactions
OSGI goes Enterprise
Easybeans OSGI JPA Container
Why OSGI and EJB3
17
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
Why not CDO to persist Business Models
18
Bundles entity
ejb, interfaces
enumerations
Fragments icons, fonts, OS-dependent-styles
Logging Utils, Logging Configuration
OSGI Server
19
Bundles entity
ejb
interfaces
enumerations
OSGI Server (Bundles)
20
@Stateless@PersistenceContext
@Local, @Remote
@Stateless, @Stateful
@EJB
Entity Bundles
EJB Bundles
PersistenceContext Bundles
Business - Interface Bundles
implementsimplements
uses
uses
injects
Enum
Enumeration Bundles
@Entity, @Embeddable
Bundles unlimited
per Subapplication
per Subdomain
Productfamilies
Tip:
used at Client and Server
Server-only Dependencies should be optional
Entity Bundles
21
Entity Bundles
@Entity, @Embeddable
Bundles per Subapplication
per Subdomain
per Customer / Product
Why separate Bundles ?Enumeration Literals different per Customers
Easy to change / enhance
Also used by Business Processes, Rules
Enumeration Bundles
22
Enum
Enumeration Bundles
BundlesStateless Beans
implements BusinessInterfaces
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
PersistenceContext Bundles
23
@Stateless
@PersistenceContext
PersistenceContext Bundles
Persistence Context Configuration
24
MyBean.java (in a PersistenceContext Bundle)
Datei
META-INF/persistence.xml
Datei
config/easybeans.xml
BundlesStateless 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
EJB Bundles
25
@Stateless,
@Stateful@EJB
EJB Bundles
Bundles Local or Remote
unlimited Bundles
structured per Subdomain, Product, ...
used on Client and Server
Business Interface Bundles
26
@Local,
@RemoteBusiness - Interface Bundles
Fragments Icons
Fonttemplates
OS-dependent-styles
Logging - Utilities
OSGI Server (Fragments)
27
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
MDSD
29
Quicktime Demo
UML Entity Diagram (MagicDraw) … oAW
(openArchitectureWare) Templates …
redView (Riena - EMF - Dynamic Views)
Overview
Different Eclipse Installations for different Roles Architect and Modeler
Client-Server-Platform Developer
UI Designer (Development)
UI Design and Prototyping (Business User)
Eclipse Workspaces and Installations
32
Eclipse Workspaces and Installations
33
Eclipse Modeling
EMFUML2openArchitectureWare- XPand- XTend- Workflow
Eclipse Installations Eclipse Workspaces
my oAW Cartridges
javaentityejbservicesprocesses
Mo
delin
gR
un
tim
e
Eclipse Runtime
Target Platform
EquinoxRCPRienaEasyBeans
abcfoosample
uses
generates
Project Workflows
Project codeProject "foo"
entityejb - beansejb - apiservicesprocessesrulesui
Project Bundles
34
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
Problems to solve
35
36
Are they all brave OSGI citizens ? 1 jar == 1 bundle
import package instead of required bundles ?
always Versioning Bundles and Dependencies ?
HowTo integrate 3rdParty Bundles (1)
37
Quicktime Demo
look inside an OSGI Monster Bundle
… or… „can you count the jars ?“ ;-)
Are there any Monsters ? look inside EasyBeans core bundle
Are there dependency - cycles ? SLF4J + Logback, Easybeans
HowTo integrate 3rdParty Bundles (2)
41
42
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
Bundle Start Order (1)
43
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
Bundle Start Order (2)
44
Bundle Start Order (3)
45
Bundle Start Order (3)
45
early it
erations
Bundle Start Order (4)
46
ServerAgent tracks Services from EasyBeans using a
ServiceTracker
registers @Remote Interfaces for Riena
registers a Service if all is done
Bundle Start Order (4)
46
ServerAgent tracks Services from EasyBeans using a
ServiceTracker
registers @Remote Interfaces for Riena
registers a Service if all is done
early it
erations
Bundle Start Order (5)
47
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
Bundle Start Order (5)
47
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
early it
erations
Bundle Start Order (6)
48
Using Declarative Services
TODO:
replace Easybeans Agent by own Implementation using DS
Bundle Start Order (6)
48
Using Declarative Services
TODO:
replace Easybeans Agent by own Implementation using DS
Riena Remote Services
EasyBeans Services
ServiceTracker
Declarative Services (DS)
ServiceTracker vs DS
Services, Services, Services...
49
Riena Remote Services (1)
50
Publishing Service
Riena Remote Services (2)
51
Injecting Service the Riena Way (fluent interfaces)
Riena Remote Services (3)
52
I prefer DeclarativeServices
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)
EasyBeans Services (1)
53
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
EasyBeans Services (2)
54
start EJB Bundles ?
Service Tracker (1)
55
ManagedServiceFactory registered
all EZB
Components
registered ?
JDBCPool
Component ?
register JNDI for
DataSource
Yes
all DataSources
registered ?
Start EJB Bundles
Yes
Yes
start EJB Bundles ?
Service Tracker (1)
55
ManagedServiceFactory registered
all EZB
Components
registered ?
JDBCPool
Component ?
register JNDI for
DataSource
Yes
all DataSources
registered ?
Start EJB Bundles
Yes
Yes
early it
erations
EasyBeans Components ? carol, hsqldb,
jotm, quartz, event, jmx, jdbcpool, joram
Services named like
carol-component-factory
Service Tracker (2)
56
ManagedServiceFactory registered
all EZB
Components
registered ?
EasyBeans Components ? carol, hsqldb,
jotm, quartz, event, jmx, jdbcpool, joram
Services named like
carol-component-factory
Service Tracker (2)
56
ManagedServiceFactory registered
all EZB
Components
registered ?
early it
erations
DataSources registered ? easybeans.xml
Service Tracker (3)
57
ManagedServiceFactory registered
JDBCPool
Component ?
register JNDI for
DataSource
Yes
all DataSources
registered ?
DataSources registered ? easybeans.xml
Service Tracker (3)
57
ManagedServiceFactory registered
JDBCPool
Component ?
register JNDI for
DataSource
Yes
all DataSources
registered ?
early it
erations
Service Tracker (4)
58
start EJB Bundles:
EasyBeans creates EJB3-Container for each PersistenceContext Bundle
Service Tracker (5)
59
ManagedServiceFactory registered
all EZB
Components
registered ?
JDBCPool
Component ?
register JNDI for
DataSource
Yes
all DataSources
registered ?
Start EJB Bundles
Yes
Yes
start EJB Bundles:
EasyBeans creates EJB3-Container for each PersistenceContext Bundle
Service Tracker (5)
59
ManagedServiceFactory registered
all EZB
Components
registered ?
JDBCPool
Component ?
register JNDI for
DataSource
Yes
all DataSources
registered ?
Start EJB Bundles
Yes
Yes
early it
erations
Service Tracker (6)
60
EZB Container Service registered
Container for all
EJB Bundles ?
register
RienaEasyBeansServerService
Yes
ManagedService registered
Remote Business
- Interface ?
register as Riena Remote Endpoint
Yes
ManagedServicesregistered by EasyBeansfor Business - Interfacesimplemented by @Stateless or @Statefull Beansfrom EJB - Bundles
EZBContainerServicesregistered by EasyBeansfor each EJB - Bundle
EasyBeans registers:
ManagedService for @Local, @Remote
EZBContainer Service for each EJB3-Container
Service Tracker (7)
61
ServiceTracker now tracks ManagedServices
tests for some Properties from EasyBeans
registers Services as RienaRemoteService
Service Tracker (7)
61
ServiceTracker now tracks ManagedServices
tests for some Properties from EasyBeans
registers Services as RienaRemoteService
early it
erations
Service Tracker (8)
62
All logic around EasyBeans EJB3-Container at a central point
Sounds good ?
Difficult to maintain or to test
What to do ?
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
Declarative Services (1)
63
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
Declarative Services (1)
63
final so
lution
Example „EasyBeans Components started ?“
Declarative Services (2)
64
Example „EasyBeans Components started ?“
Declarative Services (2)
64
final so
lution
Example „EasyBeans Components started ?“
Declarative Services (3)
65
Example „EasyBeans Components started ?“
Declarative Services (3)
65
final so
lution
OSGI Runtime with DeclarativeServices Wondering why a DS not started ?
Tip:
set debug-trace-log vm-parameters:
-Dequinox.ds.debug=true
Declarative Services (3)
66
Console Output:
Declarative Services (4)
67
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
Declarative Services (5)
68
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
Service Tracker vs Declarative Services
69
Over all my recommendation:
Use Declarative Services where possible
Equinox DS will do all the difficult work for you
Service Tracker vs Declarative Services
70
OSGI Logging
'classic' Logging
Compare LoggingFrameworks
HowTo integrate them all
Logging with OSGI and 3rdParty
71
LogService
Equinox Extended LogService graduated soon
OSGI Logging
72
Log4J
CommonsLogging
SLF4J
JDK Logging (java.util)
Classic Logging
73
...Easybeans Commons-Logging
JDK Logging
Riena Extended LogService
Start Parameters, ExtensionPoint
Hibernate switched from CommonsLogging to SLF4J
Logging used by ...
74
Compare LogFrameworks
75
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
HowTo integrate them all
76
HowTo integrate them all
77
Eclipse 3.4 PDE Export has Problems with Cycles
Equinox Runtime works well
Trick:
put a „Fake“ Bundle without Dependencies into Workspace
HowTo solve Dependency Cycles
78
Eclipse 3.5M6 PDE Tooling Support
dont forget to set Compiler Warnings:
HowTo solve Dependency Cycles
79
EasyBeans contains Hibernate Hibernate uses ContextClassLoader
Try to avoid Dynamic Import *
BuddyPolicy only if really needed
Classloader from 3rd party
80
Overview
TargetPlatformDefinition Files to be portable: variable - string substitution
PDE Tooling 3.5 easier
Duplicates, Deltas Bugzilla Reports discuss better PDE Tooling support
HowTo configure the TargetPlatform (1)
82
Locations
HowTo configure the TargetPlatform (2)
83
HowTo configure the TargetPlatform (3)
84
HowTo configure the TargetPlatform (3)
84
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
oAW - your little Helper
85
generate classnames into persistence.xml
oAW - solves Bug detecting Entity
86
generate @EJB.mappedName
oAW - solves Bug injecting @EJB (1)
87
generate @EJB.mappedName
oAW - solves Bug injecting @EJB (2)
88
generate @EJB.mappedName
now its easy to use:@EJB (mappedName = MyInterface.EZB_MAPPED_NAME)
MyInterface mi = null;
oAW - solves Bug injecting @EJB (3)
89
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)
Summary
90
Quicktime Demo
start the server: equinox, riena,
easybeans EJB3 … write some data to db
… watch (SLF4J/logback) logfiles with
lilith …
Other ways to persist ?
More M2M Transformations
Give Value back to Open Source Community
Next Steps
94
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 ????
Alternate Ways to Persist Data
95
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
Extra M2M transformation
96
97
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
open-erp-ware.org (1)
98
slf4joverOSGI LoggingBridge
could be used additional to SLF4J / LogBack Bridges
open-erp-ware.org (2)
99
Open Source Dynamic Views for Business ApplicationsEMF
CDO
Ridgets
Prototyping
WYSIWYG Editor for dynamic SWT Views
100
redView - Riena EMF Dynamic Views
Question & Answer
[email protected] 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
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