SlideShare a Scribd company logo
1 of 36
Download to read offline
Modular EJBs in OSGi
Tim Ward
IBM
21 Sep 2011
OSGi Alliance Marketing © 2008-2010 . All Rights Reserved
Page 1
Page 2
Legal
Java and all Java-based trademarks and logos are trademarks or
registered trademarks of Oracle and/or its affiliates.
OSGi and the OSGi logo are trademarks or registered trademarks
of the OSGi Alliance
Other product and service names might be trademarks of IBM or
other companies. A current list of IBM trademarks is available
on the Web at “Copyright and trademark information” at
www.ibm.com/legal/copytrade.shtml
Agenda
A Quick EJB refresher
How EJBs might fit into OSGi
A case study in implementing Modular
EJB
Proof that it really works
Terminology
EJB – Enterprise Java Bean
EJB JAR – A JAR packaging EJBs
Modular EJB – An EJB running in OSGi
EJB Bundle – An OSGi bundle packaging
Modular EJBs
EJBs – the basics
EJBs are managed objects, the container injects their
dependencies
Session EJBs define one or more business “views”
These proxy the real EJB object(s)
The same view object may delegate to the same, or a
different, EJB for successive calls
Different EJB types have different delegation styles
The EJB runtime adds declarative transactions, security
and other services when a business method is called
Page 6
EJB Views and OSGi services
EJB View OSGi Service
Cardinality May proxy one or
many EJB objects
One per registration or
one per client bundle
Location Stored in JNDI Stored in the OSGi
service registry
Interface One business
interface per EJB view
One service may expose
many interfaces
Lifecycle Relatively static once
created, no reinjection,
no notifications from
JNDI
Dynamic, may be
removed or modified and
underlying dependencies
may change
An EJB view shares a number of concepts with an OSGi
service.
Integrating EJBs with OSGi
The service registry is the integration point in OSGi
Expose modular EJBs as OSGi services
Register one service per EJB view
Remote EJB views should be Remoteable Services
service.exported.interfaces = *
EJB services only work with the right lookup lifecycle
Stateless are an interchangable pool
Singleton is like a normal service
Stateful EJBs are “one per lookup”
Identifying EJB Bundles in
OSGi
Requirement
EJB Bundles should be able to be valid EJB JARs
Fit with existing OSGi module types (e.g. WABs)
Proposal
Add a new header “Export-EJB:”
Identifies a bundle as an EJB-Bundle
Defines which EJBs are exposed as OSGi services
Pioneered by Glassfish Application Server
Known to work – good basis for a standard?
Running Modular EJBs in
Aries
Apache Aries provides pieces of an OSGi container
Integrate with existing projects where possible
OpenEJB has been packaged as an OSGi bundle for
a couple of releases
Some tentative OSGi support, little true integration
Mission Statement
Integrate OpenEJB with existing OSGi standards and
Aries features to provide support for Modular EJBs
Issues Running EJBs in OSGi
Locating EJBs in OSGi bundles
OSGi class loading semantics
Building EJB proxy stubs
Transaction Manager integration
JPA integration
Security integration
Miscellaneous
Working with EJB Bundles
– Finding the EJBs
EJBs are defined in one of two ways
via annotations @Stateless
via XML <session>...
Requirement 1 says that EJB Bundles should put
XML in META-INF/ejb-jar.xml (just like Java EE)
Finding the XML is non-trivial for OpenEJB in OSGi
Use the extender pattern to help OpenEJB out
Recognise bundles using Export-EJB header
Working with EJB Bundles
– Finding the EJBs (2)
Finding Annotated EJBs much harder than for XML
Typically a OpenEJB “scans” the classpath by listing files
on the file system (using file: or jar: URLs)
In OSGi there is no guarantee of the bundle being on
the filesystem (or in its original layout)
Typical scanning breaks at this point, so either:
Try to scan the raw bundle bytes (if they exist!)
No fragments, imports or bundle classpath
Implement an OSGi aware scanner
Apache Aries –
Locating META-INF/ejb-jar.xml
OpenEJB allows us to build our own EJBModule
representing the EJB Bundle
An EJBModule allows us to supply a URL to the EJB
XML deployment descriptor
This is parsed and processed by OpenEJB
Aries makes all .xml files in META-INF available
Covers other Java EE specs
Covers OpenEJB config files
Apache Aries –
Writing an OSGi aware scanner
In OSGi 4.3 a new core API method was added
BundleWiring.listResources(String, String, int)
We can use this to build an OSGi specific Xbean
scanner for our EJBModule
for(String resource : bundle.adapt(BundleWiring.class).
listResources("/", "*.class", LISTRESOURCES_RECURSE)) {
URL u = bundle.getResource(resource)
readClassDef(u.openStream());
}
Issues Running EJBs in OSGi
Locating EJBs in OSGi bundles
OSGi class loading semantics
Building EJB proxy stubs
Transaction Manager integration
JPA integration
Security integration
Miscellaneous
Java EE vs OSGi class loading
One of the key differences between OSGi and Java
EE is how they load classes
Java EE has a hierarchy of ClassLoader instances
EJB JAR → Application → EJB Container → Java
OSGi has a ClassLoader network...
EJB Bundle
EJB API
Logger
Business
API
?
? ? ?
Apache Aries –
Classloading for EJB Bundles
Clearly the OpenEJB EJBModule ClassLoader
should be the EJB Bundle ClassLoader
OpenEJB relies on the fact that its internals are
visible from the EJB JAR ClassLoader
No requirement for EJB Bundles to import OpenEJB
Make OpenEJB visible from Application ClassLoader
EJB Bundle
EJB API
Business
API
EJB JAR ClassLoader Open EJB
Application ClassLoader
Page 18
Issues Running EJBs in OSGi
Locating EJBs in OSGi bundles
OSGi class loading semantics
Building EJB proxy stubs
Transaction Manager integration
JPA integration
Security integration
Miscellaneous
Implementing EJBs in OSGi
EJBs are usually implemented using proxy “stubs”
Implement a single business interface
May implement other container specific interfaces
Often implement javax.naming.Referencable
Stubs may be dynamic proxys or generated classes
In either case they must be loaded as classes
In OSGi each bundle has a different ClassLoader
There may not be any one bundle that can see all the
interfaces on the proxy!
Apache Aries –
OSGi safe proxy classes
Aries contains an OSGi aware proxy implementation
Supports dynamic interface implementation generation
for one to N interfaces
The proxy allows a parent bundle to be specified
The proxy understands that not all interfaces may be
visible to the bundle!
Aries replaces the default OpenEJB Proxy factory
EJB stubs can use any mixture of interfaces
Page 21
Issues Running EJBs in OSGi
Locating EJBs in OSGi bundles
OSGi class loading semantics
Building EJB proxy stubs
Transaction Manager integration
JPA integration
Security integration
Miscellaneous
EJBs and Transactions
EJBs have an extremely strong link with transactions
All invocations use a global transaction by default
More complex interactions can be configured
EJBs can control their own transactions too
In OSGi we use the JTA Service to get hold of a
TransactionManager
OpenEJB knows nothing about this...
Tx Client
Apache Aries –
JTA integration
Aries contains a JTA Service implementation that
uses Geronimo's transaction manager
Also provides a TransactionSynchronizationRegistry
Aries overrides the OpenEJB transaction manager
Use the JTA Service
Provide the Tx Manager and Tx Registry
This is a clean and well used plug point
Issues Running EJBs in OSGi
Locating EJBs in OSGi bundles
OSGi class loading semantics
Building EJB proxy stubs
Transaction Manager integration
JPA integration
Security integration
Miscellaneous
EJBs and JPA
JPA replaced Entity Beans as the persistence strategy
for Java EE
EJBs have tight integration with JPA
Injection via Annotations @PersistenceUnit
Injection via XML <persistence-unit-ref> ...
JNDI lookup in java:comp/env
EJBs may use JPA in two ways
Application Managed
Container Managed
EJBs and JPA – Application
Managed
In Application managed JPA the EJB manages lifecycle
Responsible for creating and closing EntityManagers
Responsible for joining any active transactions
Adds a dependency on a named persistence unit
Injects or looks up an EntityManagerFactory
OpenEJB expects to find, create, and manage any
persistence units in persistence.xml
ClassLoader problems make this impossible in OSGi
Apache Aries –
Updates to Aries JPA container
Aries JPA normally uses the Meta-Persistence header
to locate persistence bundles in the framework
Java EE also defines rules for finding persistence.xml
WARs in WEB-INF/classes, or in WEB-INF/lib
EJB JARs in META-INF
Aries JPA already checks for Web-ContextPath
Add support for the Export-EJB header too
Apache Aries –
JPA (Application Managed)
Hide META-INF/persistence.xml from OpenEJB
Don't put the URL in the EJBModule
Override the OpenEJB validation failure, Aries JPA will
provide the missing EntityManagerFactory!
Listen for the registration of OSGi persistence units
If the unit is used by an EJB then bind it into the right
place in java:comp/env
EJB
java:co
mp
Extender
EJBs and JPA – Container
Managed
In Container managed JPA the container manages
everything!
Tx integration
Creating and closing EntityManagers
More importantly, the container propagates context
Different EJBs that use the same persistence unit in a
transaction will get the same EntityManager
Aries JPA already supports this mode of operation for
blueprint beans and OSGi service lookups
Apache Aries –
JPA (Container Managed)
Replace the existing OpenEJB JPA context registry
Check for Aries JPA contexts and OpenEJB contexts
Cross register any created contexts so both agree!
Listen for the registration of OSGi persistence units
If the unit is used as a managed context in an EJB
then create an OpenEJB managed EntityManager
Register this EntityManager in the relevant part of
java:comp/env
EJB
java:co
mp
Extender
Issues Running EJBs in OSGi
Locating EJBs in OSGi bundles
OSGi class loading semantics
Building EJB proxy stubs
Transaction Manager integration
JPA integration
Security integration
Miscellaneous
Java EE Security
Java EE supports role-based authorization
On Servlet methods
On EJB method calls
OpenEJB provides a Security Service plugpoint
Allows third party authentication/authorization engines to be
used
Aries has no security component - any volunteers?
OpenEJB can cope without a Security Service
No integration at this time
Issues Running EJBs in OSGi
Locating EJBs in OSGi bundles
OSGi class loading semantics
Building EJB proxy stubs
Transaction Manager integration
JPA integration
Security integration
Miscellaneous
Issues with OpenEJB in OSGi
OpenEJB makes extensive use of XBean internally to
build things
This has the option of providing a ClassLoader
OpenEJB typically provides none
OpenEjbVersion throws an ExceptionInInitializerError
Attempts to classpath scan for properties
To work around these Aries has to extensively set the
Thread Context ClassLoader when starting OpenEJB
New JAXB code in OpenEJB needs delegating to a 2.1 JAXB
implementation every time we build an app
Summary
There are a few rough edges
Some can easily be remedied in OpenEJB internals
Some support is clearly missing, but could be added
Security, Messaging, EJB lite
Broadly speaking, it works
And I can prove it!
Apache Aries Blog sample with an EJB implemented comment
service!
References
Apache Aries: http://aries.apache.org/
Tim Ward: @TimothyWard timothyjward@apache.org
OSGi and JPA on YouTube:
http://www.youtube.com/user/EnterpriseOSGi
For more information on Enterprise OSGi take a look at
Enterprise OSGi in Action :
http://www.manning.com/cummins

More Related Content

Similar to modular-ejbs-for-enterprise-osgi developers

The Complete Spring Tutorial
The Complete Spring TutorialThe Complete Spring Tutorial
The Complete Spring Tutorialcribes
 
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...IndicThreads
 
Eclipse_Building_Blocks
Eclipse_Building_BlocksEclipse_Building_Blocks
Eclipse_Building_BlocksRahul Shukla
 
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...mfrancis
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1kshanth2101
 
OSGi-enabled Java EE Applications using GlassFish
OSGi-enabled Java EE Applications using GlassFishOSGi-enabled Java EE Applications using GlassFish
OSGi-enabled Java EE Applications using GlassFishArun Gupta
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi WebinarWSO2
 
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishArun Gupta
 
Enabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDMEnabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDMmukulobject
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006achraf_ing
 
OSGi Overview TomTom DevDay May 2009
OSGi Overview TomTom DevDay May 2009OSGi Overview TomTom DevDay May 2009
OSGi Overview TomTom DevDay May 2009Toralf Richter
 
Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Jeffrey Groneberg
 
OSGi in Java EE Servers - Sneak Peek Under the Hood - Krasimir Semerdzhiev
OSGi in Java EE Servers - Sneak Peek Under the Hood - Krasimir SemerdzhievOSGi in Java EE Servers - Sneak Peek Under the Hood - Krasimir Semerdzhiev
OSGi in Java EE Servers - Sneak Peek Under the Hood - Krasimir Semerdzhievmfrancis
 

Similar to modular-ejbs-for-enterprise-osgi developers (20)

Polyglot OSGi
Polyglot OSGiPolyglot OSGi
Polyglot OSGi
 
OSGi summary
OSGi summaryOSGi summary
OSGi summary
 
Osgi Sun 20080820
Osgi Sun 20080820Osgi Sun 20080820
Osgi Sun 20080820
 
The Complete Spring Tutorial
The Complete Spring TutorialThe Complete Spring Tutorial
The Complete Spring Tutorial
 
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
 
Eclipse_Building_Blocks
Eclipse_Building_BlocksEclipse_Building_Blocks
Eclipse_Building_Blocks
 
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
 
Jsf+ejb 50
Jsf+ejb 50Jsf+ejb 50
Jsf+ejb 50
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
OSGi-enabled Java EE Applications using GlassFish
OSGi-enabled Java EE Applications using GlassFishOSGi-enabled Java EE Applications using GlassFish
OSGi-enabled Java EE Applications using GlassFish
 
OSGI in Java EE servers:Sneak peak
OSGI in Java EE servers:Sneak peakOSGI in Java EE servers:Sneak peak
OSGI in Java EE servers:Sneak peak
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi Webinar
 
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFish
 
GlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and FutureGlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and Future
 
Enabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDMEnabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDM
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006
 
OSGi Overview TomTom DevDay May 2009
OSGi Overview TomTom DevDay May 2009OSGi Overview TomTom DevDay May 2009
OSGi Overview TomTom DevDay May 2009
 
Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -
 
OSGi in Java EE Servers - Sneak Peek Under the Hood - Krasimir Semerdzhiev
OSGi in Java EE Servers - Sneak Peek Under the Hood - Krasimir SemerdzhievOSGi in Java EE Servers - Sneak Peek Under the Hood - Krasimir Semerdzhiev
OSGi in Java EE Servers - Sneak Peek Under the Hood - Krasimir Semerdzhiev
 
OSGi for mere mortals
OSGi for mere mortalsOSGi for mere mortals
OSGi for mere mortals
 

Recently uploaded

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

modular-ejbs-for-enterprise-osgi developers

  • 1. Modular EJBs in OSGi Tim Ward IBM 21 Sep 2011 OSGi Alliance Marketing © 2008-2010 . All Rights Reserved Page 1
  • 2. Page 2 Legal Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates. OSGi and the OSGi logo are trademarks or registered trademarks of the OSGi Alliance Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at “Copyright and trademark information” at www.ibm.com/legal/copytrade.shtml
  • 3. Agenda A Quick EJB refresher How EJBs might fit into OSGi A case study in implementing Modular EJB Proof that it really works
  • 4. Terminology EJB – Enterprise Java Bean EJB JAR – A JAR packaging EJBs Modular EJB – An EJB running in OSGi EJB Bundle – An OSGi bundle packaging Modular EJBs
  • 5. EJBs – the basics EJBs are managed objects, the container injects their dependencies Session EJBs define one or more business “views” These proxy the real EJB object(s) The same view object may delegate to the same, or a different, EJB for successive calls Different EJB types have different delegation styles The EJB runtime adds declarative transactions, security and other services when a business method is called
  • 6. Page 6 EJB Views and OSGi services EJB View OSGi Service Cardinality May proxy one or many EJB objects One per registration or one per client bundle Location Stored in JNDI Stored in the OSGi service registry Interface One business interface per EJB view One service may expose many interfaces Lifecycle Relatively static once created, no reinjection, no notifications from JNDI Dynamic, may be removed or modified and underlying dependencies may change An EJB view shares a number of concepts with an OSGi service.
  • 7. Integrating EJBs with OSGi The service registry is the integration point in OSGi Expose modular EJBs as OSGi services Register one service per EJB view Remote EJB views should be Remoteable Services service.exported.interfaces = * EJB services only work with the right lookup lifecycle Stateless are an interchangable pool Singleton is like a normal service Stateful EJBs are “one per lookup”
  • 8. Identifying EJB Bundles in OSGi Requirement EJB Bundles should be able to be valid EJB JARs Fit with existing OSGi module types (e.g. WABs) Proposal Add a new header “Export-EJB:” Identifies a bundle as an EJB-Bundle Defines which EJBs are exposed as OSGi services Pioneered by Glassfish Application Server Known to work – good basis for a standard?
  • 9. Running Modular EJBs in Aries Apache Aries provides pieces of an OSGi container Integrate with existing projects where possible OpenEJB has been packaged as an OSGi bundle for a couple of releases Some tentative OSGi support, little true integration Mission Statement Integrate OpenEJB with existing OSGi standards and Aries features to provide support for Modular EJBs
  • 10. Issues Running EJBs in OSGi Locating EJBs in OSGi bundles OSGi class loading semantics Building EJB proxy stubs Transaction Manager integration JPA integration Security integration Miscellaneous
  • 11. Working with EJB Bundles – Finding the EJBs EJBs are defined in one of two ways via annotations @Stateless via XML <session>... Requirement 1 says that EJB Bundles should put XML in META-INF/ejb-jar.xml (just like Java EE) Finding the XML is non-trivial for OpenEJB in OSGi Use the extender pattern to help OpenEJB out Recognise bundles using Export-EJB header
  • 12. Working with EJB Bundles – Finding the EJBs (2) Finding Annotated EJBs much harder than for XML Typically a OpenEJB “scans” the classpath by listing files on the file system (using file: or jar: URLs) In OSGi there is no guarantee of the bundle being on the filesystem (or in its original layout) Typical scanning breaks at this point, so either: Try to scan the raw bundle bytes (if they exist!) No fragments, imports or bundle classpath Implement an OSGi aware scanner
  • 13. Apache Aries – Locating META-INF/ejb-jar.xml OpenEJB allows us to build our own EJBModule representing the EJB Bundle An EJBModule allows us to supply a URL to the EJB XML deployment descriptor This is parsed and processed by OpenEJB Aries makes all .xml files in META-INF available Covers other Java EE specs Covers OpenEJB config files
  • 14. Apache Aries – Writing an OSGi aware scanner In OSGi 4.3 a new core API method was added BundleWiring.listResources(String, String, int) We can use this to build an OSGi specific Xbean scanner for our EJBModule for(String resource : bundle.adapt(BundleWiring.class). listResources("/", "*.class", LISTRESOURCES_RECURSE)) { URL u = bundle.getResource(resource) readClassDef(u.openStream()); }
  • 15. Issues Running EJBs in OSGi Locating EJBs in OSGi bundles OSGi class loading semantics Building EJB proxy stubs Transaction Manager integration JPA integration Security integration Miscellaneous
  • 16. Java EE vs OSGi class loading One of the key differences between OSGi and Java EE is how they load classes Java EE has a hierarchy of ClassLoader instances EJB JAR → Application → EJB Container → Java OSGi has a ClassLoader network... EJB Bundle EJB API Logger Business API ? ? ? ?
  • 17. Apache Aries – Classloading for EJB Bundles Clearly the OpenEJB EJBModule ClassLoader should be the EJB Bundle ClassLoader OpenEJB relies on the fact that its internals are visible from the EJB JAR ClassLoader No requirement for EJB Bundles to import OpenEJB Make OpenEJB visible from Application ClassLoader EJB Bundle EJB API Business API EJB JAR ClassLoader Open EJB Application ClassLoader
  • 18. Page 18 Issues Running EJBs in OSGi Locating EJBs in OSGi bundles OSGi class loading semantics Building EJB proxy stubs Transaction Manager integration JPA integration Security integration Miscellaneous
  • 19. Implementing EJBs in OSGi EJBs are usually implemented using proxy “stubs” Implement a single business interface May implement other container specific interfaces Often implement javax.naming.Referencable Stubs may be dynamic proxys or generated classes In either case they must be loaded as classes In OSGi each bundle has a different ClassLoader There may not be any one bundle that can see all the interfaces on the proxy!
  • 20. Apache Aries – OSGi safe proxy classes Aries contains an OSGi aware proxy implementation Supports dynamic interface implementation generation for one to N interfaces The proxy allows a parent bundle to be specified The proxy understands that not all interfaces may be visible to the bundle! Aries replaces the default OpenEJB Proxy factory EJB stubs can use any mixture of interfaces
  • 21. Page 21 Issues Running EJBs in OSGi Locating EJBs in OSGi bundles OSGi class loading semantics Building EJB proxy stubs Transaction Manager integration JPA integration Security integration Miscellaneous
  • 22. EJBs and Transactions EJBs have an extremely strong link with transactions All invocations use a global transaction by default More complex interactions can be configured EJBs can control their own transactions too In OSGi we use the JTA Service to get hold of a TransactionManager OpenEJB knows nothing about this... Tx Client
  • 23. Apache Aries – JTA integration Aries contains a JTA Service implementation that uses Geronimo's transaction manager Also provides a TransactionSynchronizationRegistry Aries overrides the OpenEJB transaction manager Use the JTA Service Provide the Tx Manager and Tx Registry This is a clean and well used plug point
  • 24. Issues Running EJBs in OSGi Locating EJBs in OSGi bundles OSGi class loading semantics Building EJB proxy stubs Transaction Manager integration JPA integration Security integration Miscellaneous
  • 25. EJBs and JPA JPA replaced Entity Beans as the persistence strategy for Java EE EJBs have tight integration with JPA Injection via Annotations @PersistenceUnit Injection via XML <persistence-unit-ref> ... JNDI lookup in java:comp/env EJBs may use JPA in two ways Application Managed Container Managed
  • 26. EJBs and JPA – Application Managed In Application managed JPA the EJB manages lifecycle Responsible for creating and closing EntityManagers Responsible for joining any active transactions Adds a dependency on a named persistence unit Injects or looks up an EntityManagerFactory OpenEJB expects to find, create, and manage any persistence units in persistence.xml ClassLoader problems make this impossible in OSGi
  • 27. Apache Aries – Updates to Aries JPA container Aries JPA normally uses the Meta-Persistence header to locate persistence bundles in the framework Java EE also defines rules for finding persistence.xml WARs in WEB-INF/classes, or in WEB-INF/lib EJB JARs in META-INF Aries JPA already checks for Web-ContextPath Add support for the Export-EJB header too
  • 28. Apache Aries – JPA (Application Managed) Hide META-INF/persistence.xml from OpenEJB Don't put the URL in the EJBModule Override the OpenEJB validation failure, Aries JPA will provide the missing EntityManagerFactory! Listen for the registration of OSGi persistence units If the unit is used by an EJB then bind it into the right place in java:comp/env EJB java:co mp Extender
  • 29. EJBs and JPA – Container Managed In Container managed JPA the container manages everything! Tx integration Creating and closing EntityManagers More importantly, the container propagates context Different EJBs that use the same persistence unit in a transaction will get the same EntityManager Aries JPA already supports this mode of operation for blueprint beans and OSGi service lookups
  • 30. Apache Aries – JPA (Container Managed) Replace the existing OpenEJB JPA context registry Check for Aries JPA contexts and OpenEJB contexts Cross register any created contexts so both agree! Listen for the registration of OSGi persistence units If the unit is used as a managed context in an EJB then create an OpenEJB managed EntityManager Register this EntityManager in the relevant part of java:comp/env EJB java:co mp Extender
  • 31. Issues Running EJBs in OSGi Locating EJBs in OSGi bundles OSGi class loading semantics Building EJB proxy stubs Transaction Manager integration JPA integration Security integration Miscellaneous
  • 32. Java EE Security Java EE supports role-based authorization On Servlet methods On EJB method calls OpenEJB provides a Security Service plugpoint Allows third party authentication/authorization engines to be used Aries has no security component - any volunteers? OpenEJB can cope without a Security Service No integration at this time
  • 33. Issues Running EJBs in OSGi Locating EJBs in OSGi bundles OSGi class loading semantics Building EJB proxy stubs Transaction Manager integration JPA integration Security integration Miscellaneous
  • 34. Issues with OpenEJB in OSGi OpenEJB makes extensive use of XBean internally to build things This has the option of providing a ClassLoader OpenEJB typically provides none OpenEjbVersion throws an ExceptionInInitializerError Attempts to classpath scan for properties To work around these Aries has to extensively set the Thread Context ClassLoader when starting OpenEJB New JAXB code in OpenEJB needs delegating to a 2.1 JAXB implementation every time we build an app
  • 35. Summary There are a few rough edges Some can easily be remedied in OpenEJB internals Some support is clearly missing, but could be added Security, Messaging, EJB lite Broadly speaking, it works And I can prove it! Apache Aries Blog sample with an EJB implemented comment service!
  • 36. References Apache Aries: http://aries.apache.org/ Tim Ward: @TimothyWard timothyjward@apache.org OSGi and JPA on YouTube: http://www.youtube.com/user/EnterpriseOSGi For more information on Enterprise OSGi take a look at Enterprise OSGi in Action : http://www.manning.com/cummins