SlideShare une entreprise Scribd logo
1  sur  50
ANDREAS ENBOHM (@enbohm)
2012-09-13
HYBRID APPLICATIONS
- Combining the Power of Java EE and OSGi
About Me
Agenda
 Introduction
 Java EE
 OSGi + Java EE
 Demo
- Java EE + OSGi
- Glassfish V3
 Future<?>
Why This Presenation?
Homer Simpson Programming Model:
”Let some else do it!”
Java EE
Java EE
”The industri standard for enterprise computing. JEE is
used for mission-critical, large-scale, multi-tiered,
scalable, reliable, and secure applications”
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
- …
Ewok* EJB Appreciation
*Ewoks from motion picture ”Star Wars Return of the Jedi”
”EJB/J2EE IS HEAVYWEIGHT”
”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
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
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
Why Java EE
 Deployment
- very few (if any) xzy.xml deployment desc.
- runs on several app servers and/or clouds
 Elastic
Why Java EE
 Ultra-lean
- what more can be removed?
EJB Component
public interface PaymentService {
public ProductReceipt pay(int productId);
}
@Stateless
public class PaymentEJB implements PaymentService {
public ProductReceipt pay(int productId){
//implementation goes here
}
}
EJB-annotation (convention over configuration)
Plain interface (not
required)
TDD and Java EE
 Unit test
- POJO
 Integration test
- embedded container
- arquillian
- pax exam
TDD and Java EE
EJBContainer container = EJBContainer.createEJBContainer();
Context ctx = container.getContext();
PaymentService service = (PaymentService) ctx
.lookup("java:global/classes/PaymentEJB");
Assert.assertNotNull(service);
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
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
Hello OSGi!
“OSGi technology provides a service-oriented,
component-based environment for developers and
offers standardized ways to manage the software
lifecycle.” - Wikipedia
Hello OSGi!
Simply put, a modularity layer for the Java platform
Why OSGi
 Separation of concerns (i.e modularization)
 Key concepts
- Cohesion
- Coupling
 Containers
- Apache Felix
- Knopflerfish
- Equinox
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)
OSGi Layers
 OSGi Layered Architecture
 Module
- packaging and sharing
of code
 Life Cycle
- module management
 Service
- interaction between
modules
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
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
OSGi Life Cycle Layer
 Life Cycle
OSGi Service Layer
 Services registry
- register
- unregister
 Service is a POJI
- focus on the contract/interface
- reduce coupling
 Service discovery
- LDAP filter based queries
Best of Both Worlds
 How about combining JEE & OSGi?
- productivity
- reusable bundles with visible dependencies
- version control of components
- automatic transaction handling
- ..
Hello Hybrid Application!
31
© 2012 Capgemini. All rights reserved.
Hybrid Applications
“a hybrid application bundle is an OSGi bundle as well
as a Java EE module. At
runtime, it has both an OSGi bundle context and a Java
EE context.”
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
Hybrid Applications
How to turn your Java
EE artifacts to OSGi
Services?
Hybrid Applications
…
Implementation-Title: hybrid
Implementation-Version: 1.3
Bundle-ClassPath: WEB-INF/classes/
Bundle-Name: hybrid
Bundle-SymbolicName: com.acme.hybrid.service.impl
Bundle-Version: 1.3.0
Export-EJB: ALL
Web-ContextPath: /hybrid
…
Manifest.MF
WAB (web application bundle); OSGi Spec. 4.2
Hybrid Applications
 EJB artifacts + Manifest.MF = ’Declarative’ Service
- Enterprise Application Bundle (EAB)
- Web Application Bundle (WAB)
 ExportEJB: List of EJBs to be exported as OSGi services.
- Values: NONE, ALL or fully qualified name
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”
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
- …
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"));
@Inject @OSGiService(dynamic=true)
Hello hello;
System.out.println(hello.sayHello("Duke"));
With CDI annotation:
PROVE IT ! (Demo time)
 Asyncronous invocations
 Events
 Decorators
 Service update (hot deployment)
 REST service
Demo Overview
HybridCommon
(standard OSGi bundle containing
domain objects)
HybridClient
(WAB exposes a service via Jax-RS)
HybridBackend
(EJB as OSGi service, EAB)
<uses>
<uses>
OSGi Service
Registry
<publish>
<discover>
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…
FUTURE<JavaEE&OSGi>
Project Jigsaw
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
FUTURE<JavaEE&OSGi>
OSGi + Maven?
FUTURE<JavaEE&OSGi>
 OSGi
- CDI integration
- EJB incorporation
- more app servers will support hybrid
apps
 Jigsaw and OSGi will definitely co-exist
- Project Penrose
SUMMARY
 Features in Java EE and OSGi
- productivity and modularity
 How to combine them
- WAB/EAB
 Demonstrated a hybrid application
- using Glassfish + Apache Felix
| Sector, Alliance, Offering
USEFUL LINKS
www.osgi.org
www.glassfish.org
http://www.oracle.com/technetwork/java/javaee/overvie
w/index.html
http://www.jboss.org/arquillian.html
http://mreinhold.org/blog/late-for-the-train-qa
Q & A
49
© 2012 Capgemini. All rights reserved.
http://www.slideshare.net/enbohm
Twitter: @enbohm
www.se.capgemini.com
The informationcontained in this presentation is proprietary. ©2012 Capgemini. All rights reserved

Contenu connexe

Tendances

Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
Tom Lee
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
Anton Arhipov
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
Bruno Oliveira
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Nayden Gochev
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
Nayden Gochev
 

Tendances (19)

Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBoss
 
Seeking Clojure
Seeking ClojureSeeking Clojure
Seeking Clojure
 
Faster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzFaster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzz
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
 
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
Cracking JWT tokens: a tale of magic, Node.JS and parallel computingCracking JWT tokens: a tale of magic, Node.JS and parallel computing
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
 
SoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringSoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with Spring
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Rapid Network Application Development with Apache MINA
Rapid Network Application Development with Apache MINARapid Network Application Development with Apache MINA
Rapid Network Application Development with Apache MINA
 
Invoke dynamics
Invoke dynamicsInvoke dynamics
Invoke dynamics
 

Similaire à Hybrid Applications

Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 
Playframework + Twitter Bootstrap
Playframework + Twitter BootstrapPlayframework + Twitter Bootstrap
Playframework + Twitter Bootstrap
Kevingo Tsai
 

Similaire à Hybrid Applications (20)

OSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 IndiaOSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 India
 
OSGi Community Event 2010 - Enterprise OSGi in WebSphere and Apache Aries
OSGi Community Event 2010 - Enterprise OSGi in WebSphere and Apache AriesOSGi Community Event 2010 - Enterprise OSGi in WebSphere and Apache Aries
OSGi Community Event 2010 - Enterprise OSGi in WebSphere and Apache Aries
 
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
 
OSGi DevCon 2009 Review
OSGi DevCon 2009 ReviewOSGi DevCon 2009 Review
OSGi DevCon 2009 Review
 
GlassFish OSGi Server
GlassFish OSGi ServerGlassFish OSGi Server
GlassFish OSGi Server
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
 
GlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and FutureGlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and Future
 
Glass Fishv3 March2010
Glass Fishv3 March2010Glass Fishv3 March2010
Glass Fishv3 March2010
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Easing offline web application development with GWT
Easing offline web application development with GWTEasing offline web application development with GWT
Easing offline web application development with GWT
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
 
Java ee7 1hour
Java ee7 1hourJava ee7 1hour
Java ee7 1hour
 
Java EE7
Java EE7Java EE7
Java EE7
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
 
Polyglot OSGi
Polyglot OSGiPolyglot OSGi
Polyglot OSGi
 
GlassFish v3 : En Route Java EE 6
GlassFish v3 : En Route Java EE 6GlassFish v3 : En Route Java EE 6
GlassFish v3 : En Route Java EE 6
 
Playframework + Twitter Bootstrap
Playframework + Twitter BootstrapPlayframework + Twitter Bootstrap
Playframework + Twitter Bootstrap
 
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
Java EE | Modular EJBs for Enterprise OSGi | Tim WardJava EE | Modular EJBs for Enterprise OSGi | Tim Ward
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
 
JBoss AS7 OSDC 2011
JBoss AS7 OSDC 2011JBoss AS7 OSDC 2011
JBoss AS7 OSDC 2011
 

Plus de Andreas Enbohm (7)

BDD Short Introduction
BDD Short IntroductionBDD Short Introduction
BDD Short Introduction
 
Behavior-driven Development and Lambdaj
Behavior-driven Development and LambdajBehavior-driven Development and Lambdaj
Behavior-driven Development and Lambdaj
 
Software Craftsmanship
Software CraftsmanshipSoftware Craftsmanship
Software Craftsmanship
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Java Extension Methods
Java Extension MethodsJava Extension Methods
Java Extension Methods
 
Project Lambda - Closures after all?
Project Lambda - Closures after all?Project Lambda - Closures after all?
Project Lambda - Closures after all?
 
Fest
FestFest
Fest
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Hybrid Applications

  • 1. ANDREAS ENBOHM (@enbohm) 2012-09-13 HYBRID APPLICATIONS - Combining the Power of Java EE and OSGi
  • 3. Agenda  Introduction  Java EE  OSGi + Java EE  Demo - Java EE + OSGi - Glassfish V3  Future<?>
  • 4. Why This Presenation? Homer Simpson Programming Model: ”Let some else do it!”
  • 6.
  • 7. Java EE ”The industri standard for enterprise computing. JEE is used for mission-critical, large-scale, multi-tiered, scalable, reliable, and secure applications”
  • 8. 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 - …
  • 9. Ewok* EJB Appreciation *Ewoks from motion picture ”Star Wars Return of the Jedi”
  • 11. ”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
  • 12. 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
  • 13. 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
  • 14. Why Java EE  Deployment - very few (if any) xzy.xml deployment desc. - runs on several app servers and/or clouds  Elastic
  • 15. Why Java EE  Ultra-lean - what more can be removed?
  • 16. EJB Component public interface PaymentService { public ProductReceipt pay(int productId); } @Stateless public class PaymentEJB implements PaymentService { public ProductReceipt pay(int productId){ //implementation goes here } } EJB-annotation (convention over configuration) Plain interface (not required)
  • 17. TDD and Java EE  Unit test - POJO  Integration test - embedded container - arquillian - pax exam
  • 18. TDD and Java EE EJBContainer container = EJBContainer.createEJBContainer(); Context ctx = container.getContext(); PaymentService service = (PaymentService) ctx .lookup("java:global/classes/PaymentEJB"); Assert.assertNotNull(service);
  • 19. 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
  • 20. 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
  • 21. Hello OSGi! “OSGi technology provides a service-oriented, component-based environment for developers and offers standardized ways to manage the software lifecycle.” - Wikipedia
  • 22. Hello OSGi! Simply put, a modularity layer for the Java platform
  • 23. Why OSGi  Separation of concerns (i.e modularization)  Key concepts - Cohesion - Coupling  Containers - Apache Felix - Knopflerfish - Equinox
  • 24. 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)
  • 25. OSGi Layers  OSGi Layered Architecture  Module - packaging and sharing of code  Life Cycle - module management  Service - interaction between modules
  • 26. 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
  • 27. 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
  • 28. OSGi Life Cycle Layer  Life Cycle
  • 29. OSGi Service Layer  Services registry - register - unregister  Service is a POJI - focus on the contract/interface - reduce coupling  Service discovery - LDAP filter based queries
  • 30. Best of Both Worlds  How about combining JEE & OSGi? - productivity - reusable bundles with visible dependencies - version control of components - automatic transaction handling - ..
  • 31. Hello Hybrid Application! 31 © 2012 Capgemini. All rights reserved.
  • 32. Hybrid Applications “a hybrid application bundle is an OSGi bundle as well as a Java EE module. At runtime, it has both an OSGi bundle context and a Java EE context.”
  • 33. 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
  • 34. Hybrid Applications How to turn your Java EE artifacts to OSGi Services?
  • 35. Hybrid Applications … Implementation-Title: hybrid Implementation-Version: 1.3 Bundle-ClassPath: WEB-INF/classes/ Bundle-Name: hybrid Bundle-SymbolicName: com.acme.hybrid.service.impl Bundle-Version: 1.3.0 Export-EJB: ALL Web-ContextPath: /hybrid … Manifest.MF WAB (web application bundle); OSGi Spec. 4.2
  • 36. Hybrid Applications  EJB artifacts + Manifest.MF = ’Declarative’ Service - Enterprise Application Bundle (EAB) - Web Application Bundle (WAB)  ExportEJB: List of EJBs to be exported as OSGi services. - Values: NONE, ALL or fully qualified name
  • 37. 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”
  • 38. 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 - …
  • 39. 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")); @Inject @OSGiService(dynamic=true) Hello hello; System.out.println(hello.sayHello("Duke")); With CDI annotation:
  • 40. PROVE IT ! (Demo time)  Asyncronous invocations  Events  Decorators  Service update (hot deployment)  REST service
  • 41. Demo Overview HybridCommon (standard OSGi bundle containing domain objects) HybridClient (WAB exposes a service via Jax-RS) HybridBackend (EJB as OSGi service, EAB) <uses> <uses> OSGi Service Registry <publish> <discover>
  • 42. 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…
  • 44. 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
  • 46. FUTURE<JavaEE&OSGi>  OSGi - CDI integration - EJB incorporation - more app servers will support hybrid apps  Jigsaw and OSGi will definitely co-exist - Project Penrose
  • 47. SUMMARY  Features in Java EE and OSGi - productivity and modularity  How to combine them - WAB/EAB  Demonstrated a hybrid application - using Glassfish + Apache Felix
  • 48. | Sector, Alliance, Offering USEFUL LINKS www.osgi.org www.glassfish.org http://www.oracle.com/technetwork/java/javaee/overvie w/index.html http://www.jboss.org/arquillian.html http://mreinhold.org/blog/late-for-the-train-qa
  • 49. Q & A 49 © 2012 Capgemini. All rights reserved. http://www.slideshare.net/enbohm Twitter: @enbohm
  • 50. www.se.capgemini.com The informationcontained in this presentation is proprietary. ©2012 Capgemini. All rights reserved