<Insert Picture Here>




OSGi & Java EE in GlassFish
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungu...
The following/preceding is intended to outline our
general product direction. It is intended for
information purposes only...
#uberconf
  #osgi
 #javaee
            3
4
5
6
7
Generally complex ...
• 13 assembly missions
• 16 pressurized modules
• 35k cubic feet
• 400 metric tons ~ 400K kg ~ 882K ...
9
The OSGi Alliance is a worldwide
consortium of technology innovators
that advances a proven and mature
process to assure i...
OSGi Alliance provides ...

• Specifications
• Reference Implementation
• Test Suites
• Certifications




               ...
What is OSGi Specification ?

• Delivered by OSGi Alliance
  • Originally for embedded devices, set top boxes, network
• A...
“JAR Hell”

• JAR is a build-time and deploy-time
 concept, not run-time
  • Based on the ZIP file format
• No metadata to...
OSGi Layers

                Service



               Life Cycle



                Module



         Execution Environm...
OSGi Bundle – Just a JAR File!
                                 Export-Package
                                 Import-Pac...
Bundle is identified by ...

• Bundle Identifier
  • Unique for the lifetime
  • getBundleId()
• Bundle Location
  • Uniqu...
Java Classes, Static Files, ...    Service

 META-INF/MANIFEST.MF
              ...
        Export-Package
              ....
Interaction between layers
          register / unregister
               get / unget         Service
                    ...
Bundle State Diagram

    update
    refresh                   install


                         INSTALLED
              ...
OSGi Containers




    http://stackoverflow.com/questions/560794/what-osgi-container-do-you-recommend


                 ...
What is GlassFish ?
• GlassFish is an open source community
• Delivers Java EE Reference Implementation
 • GlassFish Serve...
GlassFish Distributions
Distribution                  License      Features

GlassFish Open Source         CDDL &       • ...
GlassFish Roadmap Detail




  23
©2010 Oracle Corporation
OSGi in GlassFish
• GlassFish runs on top of OSGi
• Felix is default, also runs on Equinox &
  Knopflerfish
   • Runs in a...
GlassFish: Modular Platform
   REST                                OpenMQ          WebSpace Server
                   Scri...
GlassFish v3 Runtime with OSGi


 GlassFish V3 modules
                                Random OSGi Bundle
(OSGi + extra me...
Benefits of OSGi for GlassFish
• Demands and enforces stronger modularity
• Enables custom tailored App server
• Lazy load...
Create an OSGi Bundle – Maven

• Create a Maven project
• Implement “BundleActivator”
• Update “pom.xml”
   • Change packa...
Create an OSGi bundle – NetBeans




http://blogs.sun.com/arungupta/entry/totd_125_creating_an_osgi

                     ...
Create an OSGi bundle – NetBeans




http://blogs.sun.com/arungupta/entry/totd_125_creating_an_osgi

                     ...
Create an OSGi bundle – Eclipse




http://blogs.sun.com/arungupta/entry/totd_126_creating_an_osgi

                      ...
OSGi Bundles in GlassFish
• asadmin deploy –type osgi
• “cp”/“rm”
    glassfish/domains/domain1/autodeploy/bundles
•   tel...
33
Dynamic Discovery of OSGi service

                                                                          OSGi
  Export...
Why OSGi in Enterprise Apps ?

• Improved modularity
  •   Reusable bundles
  •   Dependencies are more visible
  •   Bett...
Why Java EE in Enterprise Apps ?

• Better API (JPA, JTA, JAXB, JNDI)
• Better component model (Servlet, EJB, JAX-RS)
• Be...
37
OSGi Enterprise Expert Group

 The OSGi Enterprise Expert Group
   (EEG) is chartered to define the
      technical requir...
OSGi EEG Focus
• Scaling, including multi-container and multi-process
  environments
• Distributed and/or federated servic...
Hybrid Applications

 “A hybrid application is an OSGi
   bundle as well as a Java EE
  archive and hence has both an
OSGi...
Why Hybrid Apps ?




       Best of both worlds!!!
Why do you want to learn new APIs ?




                              ...
Role of GlassFish

• Provides a runtime for Hybrid Applications
• Implements Java EE related OSGi services
  and standards...
OSGi Compendium Specs in GlassFish

• OSGi/HTTP Service
• OSGi/Web Application (rfc #66)
• OSGi/JTA (rfc #98)
• OSGi/JDBC ...
OSGi/Web Application (rfc #66)

• Web Application Bundle (WAB)
  • WAR + OSGi + Web-ContextPath Header
  • Can use all ent...
OSGi Declarative Services

• Complications of Publish/Find/Bind
  • Long startup time
  • Memory footprint
  • Complex ser...
OSGi Declarative Service
                                     <scr:component enabled="true" name="hello-service">
        ...
OSGi Declarative Services


 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.S...
JAX-WS & OSGi




          Artifacts   WSDL
                             JAX-WS
JAX-WS                       Endpoint
 Cl...
JAX-WS & OSGi

                    Artifacts                                   WSDL
                                      ...
OSGi & EJB

• Export EJB as OSGi services
• Pure OSGi component can discover/invoke
  the service
• Advantages
  • Declara...
OSGi & EJB

                 Client                                            OSGi Service Registry


                   ...
OSGi & JMS


Export-EJB: None   Consumer


                                               Destination
                    ...
Extending GlassFish v3
    Using Spring dm Container


                                                            • Simpl...
Upcoming
  OSGi & Java EE Integration in 3.1

• With EJB
  • OSGi bundles containing EJB
  • Selectively export EJB to OSG...
Upcoming
     OSGi & Java EE Integration in 3.1

  • GlassFish can be embedded in OSGi and non-OSGi
    runtime
  • OSGi A...
References


• glassfish.org
• blogs.sun.com/theaquarium
• oracle.com/goto/glassfish
• glassfish.org/roadmap
• Follow @gla...
<Insert Picture Here>




OSGi & Java EE in GlassFish
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungu...
Upcoming SlideShare
Loading in...5
×

OSGi & Java EE in GlassFish - Best of both worlds

8,499

Published on

OSGi & Java EE in GlassFish - Best of both worlds at Uber Conf 2010

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
8,499
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
274
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "OSGi & Java EE in GlassFish - Best of both worlds"

  1. 1. <Insert Picture Here> OSGi & Java EE in GlassFish Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta
  2. 2. The following/preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 2
  3. 3. #uberconf #osgi #javaee 3
  4. 4. 4
  5. 5. 5
  6. 6. 6
  7. 7. 7
  8. 8. Generally complex ... • 13 assembly missions • 16 pressurized modules • 35k cubic feet • 400 metric tons ~ 400K kg ~ 882K lbs • 173 – 286 miles above Earth • Average speed: 17,227 mph • 15.7 orbits/day • Estimated cost: $157 billion 8
  9. 9. 9
  10. 10. The OSGi Alliance is a worldwide consortium of technology innovators that advances a proven and mature process to assure interoperability of applications and services based on its component integration platform. 10
  11. 11. OSGi Alliance provides ... • Specifications • Reference Implementation • Test Suites • Certifications 11
  12. 12. What is OSGi Specification ? • Delivered by OSGi Alliance • Originally for embedded devices, set top boxes, network • Architecture for modular application development in Java • Breaks applications into “modules” or “bundles” • Can install, uninstall, start, and stop each bundle dynamically without restarting container • Multiple versions are supported • Dependencies explicitly defined with clear boundaries 12
  13. 13. “JAR Hell” • JAR is a build-time and deploy-time concept, not run-time • Based on the ZIP file format • No metadata to indicate dependencies • Multiple versions of JARs cannot be loaded • All “public” classes are public • Access modifiers are for packages, not JAR 13
  14. 14. OSGi Layers Service Life Cycle Module Execution Environment 14
  15. 15. OSGi Bundle – Just a JAR File! Export-Package Import-Package Java Classes, Static Files, … Bundle-ClassPath (bundle private) ... META-INF/MANIFEST.MF Persistent OSGI-OPT (docs, source code, ...) Atomic 15
  16. 16. Bundle is identified by ... • Bundle Identifier • Unique for the lifetime • getBundleId() • Bundle Location • Unique location of the bundle • getLocation() • Bundle Symbolic Name and Version • Globally unique identifier • getSymbolicName(), getVersion() 16
  17. 17. Java Classes, Static Files, ... Service META-INF/MANIFEST.MF ... Export-Package ... Client Java Classes, Static Files, ... META-INF/MANIFEST.MF ... Import-Package ... 17
  18. 18. Interaction between layers register / unregister get / unget Service manage start / stop Life Cycle Bundle Bundle install uninstall classload Module execute EE 18
  19. 19. Bundle State Diagram update refresh install INSTALLED STARTING update rt resolve sta refresh RESOLVED ACTIVE uninstall stop STOPPING Each bundle installation is new 19
  20. 20. OSGi Containers http://stackoverflow.com/questions/560794/what-osgi-container-do-you-recommend 20
  21. 21. What is GlassFish ? • GlassFish is an open source community • Delivers Java EE Reference Implementation • GlassFish Server Open Source Edition - glassfish.org • Oracle GlassFish Server - oracle.com/goto/glassfish • Tooling: NetBeans, Eclipse, IntelliJ • GlassFish 3.1 – currently developed • Modular, Embeddable, Extensible • High Availability, Clustering, Centralized Administration 21
  22. 22. GlassFish Distributions Distribution License Features GlassFish Open Source CDDL & • Java EE 6 Compatibility Edition 3.0 GPLv2 • No Clustering • Clustering planned in 3.1 • mod_jk for load balancing GlassFish Open Source CDDL & • Java EE 5 Compatibility Edition 2.1.1 GPLv2 • In memory replication • mod_loadbalancer Oracle GlassFish Server 3.0 Commercial • GlassFish Open Source Edition 3.0 • GlassFish Server Control Clustering • Clustering planned in 3.1 Coming Soon! Oracle GlassFish Server Commercial • GlassFish Open Source Edition 2.1.1 2.1.1 • Enterprise Manager • HADB 22
  23. 23. GlassFish Roadmap Detail 23 ©2010 Oracle Corporation
  24. 24. OSGi in GlassFish • GlassFish runs on top of OSGi • Felix is default, also runs on Equinox & Knopflerfish • Runs in an existing shell • 200+ bundles in v3 • All GlassFish modules are OSGi bundles • No OSGi APIs are used in GlassFish • HK2 provides abstraction layer http://blogs.sun.com/arungupta/entry/totd_103_glassfish_v3_with http://blogs.sun.com/arungupta/entry/totd_127_embedding_glassfish_in 24
  25. 25. GlassFish: Modular Platform REST OpenMQ WebSpace Server Scripting OpenESB OpenSSO Web Services JMS Portal Web Connection Java Web Services JSF EJB Container Application Container Container Pooling (JCA) Persistence Interop Management Console Update Center Management CLI Naming Grizzly Framework Monitoring/ Injection Service Config Deploy Manager Security Monitor Configuration Cluster Serviceability/ Logging GlassFish V3 Core Transaction Security (Module Subsystem) Service Service Deployment Clustering OSGi Java SE 25
  26. 26. GlassFish v3 Runtime with OSGi GlassFish V3 modules Random OSGi Bundle (OSGi + extra metadata) Service OSGi HK2 Service layer Mapper Service Layer OSGi Bundle Management 26
  27. 27. Benefits of OSGi for GlassFish • Demands and enforces stronger modularity • Enables custom tailored App server • Lazy loading based on usage patterns • Open for all JVM based technologies • Native deployment of JRuby-on-Rails application • Successfully maintained quick startup • Available to GlassFish developers and users 27
  28. 28. Create an OSGi Bundle – Maven • Create a Maven project • Implement “BundleActivator” • Update “pom.xml” • Change packaging to “bundle” • Add dependencies on OSGI APIs • Use “maven-bundle-plugin” to package • Build the bundle http://blogs.sun.com/arungupta/entry/totd_36_deploy_osgi_bundles 28
  29. 29. Create an OSGi bundle – NetBeans http://blogs.sun.com/arungupta/entry/totd_125_creating_an_osgi 29
  30. 30. Create an OSGi bundle – NetBeans http://blogs.sun.com/arungupta/entry/totd_125_creating_an_osgi 30
  31. 31. Create an OSGi bundle – Eclipse http://blogs.sun.com/arungupta/entry/totd_126_creating_an_osgi 31
  32. 32. OSGi Bundles in GlassFish • asadmin deploy –type osgi • “cp”/“rm” glassfish/domains/domain1/autodeploy/bundles • telnet localhost 6666 • Apache Felix Web Console • REST Console bundle • Perl-based shell (Osgish) • VisualVM OSGi Plugin • Supports OBR • Discover and deploy dependencies together http://blogs.sun.com/arungupta/entry/totd_118_managing_osgi_bundles 32
  33. 33. 33
  34. 34. Dynamic Discovery of OSGi service OSGi Export-Package API Service Registry Import-Package Impl Bundle-Activator Import-Package cker Client Service Tra Bundle-Activator Filters http://blogs.sun.com/arungupta/entry/totd_131_dynamic_osgi_services 34
  35. 35. Why OSGi in Enterprise Apps ? • Improved modularity • Reusable bundles • Dependencies are more visible • Better isolation / Cleaner class loading model • Better version control • Faster deployment cycle • Better tools for deployment • Observable bundle life cycle • Service Tracking • Criteria-based service selection 35
  36. 36. Why Java EE in Enterprise Apps ? • Better API (JPA, JTA, JAXB, JNDI) • Better component model (Servlet, EJB, JAX-RS) • Better frameworks (JSF, CDI) • Ease-of-use (Annotations, Convention-over- configuration) • Platform provided integrated infrastructure services • Transaction, Security, Persistence, Remoting, ... • Many more reasons ... 36
  37. 37. 37
  38. 38. OSGi Enterprise Expert Group The OSGi Enterprise Expert Group (EEG) is chartered to define the technical requirements and specifications to tailor and extend the OSGi Service Platform to address information technology software infrastructure use cases found in enterprise business scenarios. http://www.osgi.org/EEG/HomePage 38
  39. 39. OSGi EEG Focus • Scaling, including multi-container and multi-process environments • Distributed and/or federated service model for • Multiple Service Platforms • External, heterogeneous systems • Requirements for extensions to the OSGi publish/f nd/bind service model i • Enterprise-class life cycle and conf guration i management • Integration of established Java EE technology into OSGi 39
  40. 40. Hybrid Applications “A hybrid application is an OSGi bundle as well as a Java EE archive and hence has both an OSGi bundle context and Java EE context at runtime and can leverage capabilities of both the platforms.” 40
  41. 41. Why Hybrid Apps ? Best of both worlds!!! Why do you want to learn new APIs ? 41
  42. 42. Role of GlassFish • Provides a runtime for Hybrid Applications • Implements Java EE related OSGi services and standards • Don't have to assemble the bits • OSGi is no longer under the cover • Raises visibility from GlassFish developers to users 42
  43. 43. OSGi Compendium Specs in GlassFish • OSGi/HTTP Service • OSGi/Web Application (rfc #66) • OSGi/JTA (rfc #98) • OSGi/JDBC (rfc #122) • OSGi/JNDI (rfc #142) • OSGi/JPA (rfc #143) 43
  44. 44. OSGi/Web Application (rfc #66) • Web Application Bundle (WAB) • WAR + OSGi + Web-ContextPath Header • Can use all enterprise APIs include JPA with lazy loading • Sample manifest: Manifest-Version: 1.0 Import-Package: javax.servlet.http; javax.persistence Bundle-ClassPath: WEB-INF/classes/,WEB-INF/lib/entities.jar Bundle-Version: 1.0 Bundle-ManifestVersion: 2 Web-ContextPath: /hello Bundle-SymbolicName: test.hellowab • Wrapped WAR Support • webbundle: URL scheme 44
  45. 45. OSGi Declarative Services • Complications of Publish/Find/Bind • Long startup time • Memory footprint • Complex service programming model • OSGi services in Java EE @Resource(mappedName=”osgiName”) SomeOSGiService osgiService; • JNDI Lookup • Portable, no OSGi dependencies in application • Exported APIs visible to Java EE apps 45
  46. 46. OSGi Declarative Service <scr:component enabled="true" name="hello-service"> <implementation class="org.glassfish.samples.osgi.helloservice.impl.HelloImpl"/> <service servicefactory="false"> OSGI-INF/ <provide interface="org.glassfish.samples.osgi.helloservice.api.HelloService"/> </service> serviceComponents.xml <property name="service.pid" value="hello-service"/> </scr:component> Export-Package API Servlet Client ... import org.glassfish.samples.osgi.helloservice.api.HelloService; HelloImpl @WebServlet(urlPatterns={"/HelloClient"}) public class HelloClient extends HttpServlet { @Resource(mappedName="hello-service") HelloService helloService; @Resource(mappedName="howdy-service") HowdyImpl HelloService howdyService; ... http://blogs.sun.com/arungupta/entry/totd_124_osgi_declarative_services 46
  47. 47. OSGi Declarative Services import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Service; import org.glassfish.samples.osgi.helloservice.api.HelloService; maven- bundle- @Component(name="hello-service") plugin @Service public class HelloImpl implements HelloService { maven- public String sayHello(String name) { scr- return "Hello " + name; plugin } } http://blogs.sun.com/arungupta/entry/totd_124_osgi_declarative_services 47
  48. 48. JAX-WS & OSGi Artifacts WSDL JAX-WS JAX-WS Endpoint Client Business Method 48
  49. 49. JAX-WS & OSGi Artifacts WSDL JAX-WS JAX-WS Endpoint Client Business Delegate Method Query Registry OSGi OSGi Register Service Service Bundle Registry Business Method http://blogs.sun.com/arungupta/entry/totd_130_invoking_a_osgi 49
  50. 50. OSGi & EJB • Export EJB as OSGi services • Pure OSGi component can discover/invoke the service • Advantages • Declarative security, Transaction, Context dependency, Injection, … are available to non-EE components • TX context from pure OSGi bundle propagates to invoked EJB • Ditto for security and persistence context 50
  51. 51. OSGi & EJB Client OSGi Service Registry login Export-Package API register Export-EJB Impl Container-managed JPA LoadData http://weblogs.java.net/blog/ss141213/archive/2010/03/30/ejb-osgi-service-demo-eclipsecon 51
  52. 52. OSGi & JMS Export-EJB: None Consumer Destination ConnectionFactory Messages# BundleActivator Producer OSGi Config Admin http://www.java.net/blog/ss141213/archive/2010/04/21/osgijmsmdb-example 52
  53. 53. Extending GlassFish v3 Using Spring dm Container • Simple Spring bean implementing the service • Invoke the service from a servlet using standard @Resource injection • Single runtime for both Spring and full Java EE http://blogs.sun.com/dochez/entry/glassfish_v3_extensions_part_4 53
  54. 54. Upcoming OSGi & Java EE Integration in 3.1 • With EJB • OSGi bundles containing EJB • Selectively export EJB to OSGi Service Registry Export-EJB: <names of EJBs> • Only local stateful and stateless EJBs • With JPA • Entities + persistence.xml bundled as OSGi bundle • EE resources like JDBC, JavaMail, or JMS resource available in OSGi service registry • With CDI& JAX-RS 54
  55. 55. Upcoming OSGi & Java EE Integration in 3.1 • GlassFish can be embedded in OSGi and non-OSGi runtime • OSGi Administration • Apache Gogo Shell – Scripting environment (RFC #147) • Scripting, Piping, Variables, ... • Closures, Dynamic method invocations, ... • OSGi Web Console – Web-front end • OBR Integration – Deployment can resolve dependencies via OBR http://wiki.glassfish.java.net/attach/V3FunctionalSpecs/GFv3.1-OSGi-onepager-v0.2.txt 55
  56. 56. References • glassfish.org • blogs.sun.com/theaquarium • oracle.com/goto/glassfish • glassfish.org/roadmap • Follow @glassfish 56
  57. 57. <Insert Picture Here> OSGi & Java EE in GlassFish Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×