OSGi and Java EE 6 Yes you can with GlassFish V3

Jerome Dochez Oracle Corposration The following 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. Agenda

Introduction OSGi in GlassFish > Demo OSGi + Java EE in GlassFish > Hybrid Applications > Enterprise OSGi API > Demo Q &A

Some History and Context

Tomcat Jasper GlassFish v1 GlassFish v3 Catalina (Java EE 6, OSGi) JSTL (Java EE 5) Struts GlassFish v2 Crimson Launch v2.1 v2.1.1 XSLTC Xalan Xerces

JAXB June May Jan JAX-RPC Sept. Nov. Dec. JSF 2005 2006 2007 2008 2009 2009

(you are here) GlassFish

A Community

> Users, Partners, Testers, Developers > Started in 2005 on java.net

Application Server

> Enterprise Quality and Open Source a > Java EE 5 / 6 Reference Implementation > Full Commercial Support from Sun/Oracle > Tools Bundle for NetBeans &

OSGi in GlassFish

GlassFish runs on top of OSGi - default is Felix

Runs unmodified on Equinox as well

Can be embedded in existing OSGi runtime

Highly modular runtime > Implemented as 200+ bundles > Customizable distribution

Supports deployment of OSGi bundles

OSGi Bundle Deployment

● Pure OSGi bundles can be deployed

● Drop it in domain1/autodeploy/bundles/

● asadmin --type osgi

● OSGi administration console

● (telnet console, web console, etc...)

● Supports OBR :

● Discover and deploy dependencies together

OSGi + Java EE in GlassFish ``

OSGi + Java EE = Hybrid Application

“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.” Role of GlassFish...

Provides a runtime for Hybrid Applications

Implements Java EE related OSGi Services and Standards

You don't have to assemble the bits.

OSGi no longer under the cover > Raises visibility from GlassFish developers to GlassFish users

Differentiators

Runtime + OSGi glue layer

Migration path for Java EE to hybrid apps

Java EE 6 support

Supports Java EE component model (e.g. EJB as OSGi service)

And extensible (blueprint component model, declarative services, iPOJO)

Hybrid Application Life Cycle

http://weblogs.java.net/blog/2009/06/14/developing-hybrid-osgi-java-ee-applications- Enterprise OSGi API in GlassFish

OSGi/HTTP Service

OSGi/Web Application (rfc #66)

OSGi/EJB

OSGi/JDBC (rfc #122)

OSGi/JPA

OSGi/JTA (rfc #98) * Work In Progress - in trunk. Some of it already in v3 release.

OSGi/HTTP Service

Thin API – contains only two interfaces

> HttpService – registerResource, registerServlet, unregister

> HttpContext – Provides a context to a collection of servlets. GlassFish OSGi Administration Console

> Based on Web Console http://www.osgi.org/javadoc/r4v42/org/osgi/service/http/package-summary.html

OSGi/JPA

JPA supported in hybrid applications

Enhancement at runtime

> Works in all OSGi runtime

Same packaging rules as JPA

You can also deploy entities.jar as a bundle

Shared persistence unit – so shared 2nd level cache

OSGi/JDBC

JDBC Driver as DataSourceFactory

Dynamic discovery of driver details

Multiple versions of same driver

Wrap non-OSGi driver jars -> Bundles

JDBC resource exported as OSGi Service

OSGi/Web Application (rfc #66)

Web Application Bundle (WAB) > WAR + OSGi Metadata + Web-ContextPath header > Can use all enterprise Including 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

OSGi/EJB (GlassFish feature)

EJB Jar as OSGi bundle EJB artifacts + OSGi Metadata + Export-EJB header Export-EJB: List of EJBs to be exported as OSGi services. > Special values: NONE, ALL > Support for Stateless & Singleton EJBs with Local Views Same life cycle as WAB Local EJB can cross application boundary!!!

Invoke OSGi from pure Java EE

OSGi service exported by some bundle Invoke the service from a EE component using standard @Resource injection Never use a GlassFish API !

Step by step: http://blogs.sun.com/dochez/entry/glassfish_v3_extensions_part_4 Jerome Dochez [email protected]