OSGi and Java EE in GlassFish - Tech Days 2010 India

27
<Insert Picture Here> OSGi & Java EE in GlassFish Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta

description

OSGi and Java EE in GlassFish - Tech Days 2010 India

Transcript of OSGi and Java EE in GlassFish - Tech Days 2010 India

Page 1: OSGi and Java EE in GlassFish - Tech Days 2010 India

<Insert Picture Here>

OSGi & Java EE in GlassFish

Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta

Page 2: OSGi and Java EE in GlassFish - Tech Days 2010 India

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.

Page 3: OSGi and Java EE in GlassFish - Tech Days 2010 India

3

#glassfish#techdays

Are you tweeting ?

Page 4: OSGi and Java EE in GlassFish - Tech Days 2010 India

4

The OSGi Alliance is a worldwideconsortium of technology innovators that advances a proven and mature process to assure interoperability of applications and services based on its component integration platform.

Page 5: OSGi and Java EE in GlassFish - Tech Days 2010 India

5

OSGi Alliance provides ...

• Specifications• Reference Implementation• Test Suites• Certifications

Page 6: OSGi and Java EE in GlassFish - Tech Days 2010 India

6

What is OSGi ?

• Specification delivered by OSGi Alliance• Originally for embedded devices and networks

• Architecture for modular application development in Java

• Reduces the cost of building, maintaining, and deploying applications

Page 7: OSGi and Java EE in GlassFish - Tech Days 2010 India

7

What is OSGi ?

• OSGi “container” breaks application into “modules” or “bundles”• Felix, Equinox, Knopflerfish

• Dependencies between each bundle are managed• Can install, uninstall, start, and stop each bundle

dynamically without restarting container• Multiple versions of a bundle are supported

Page 8: OSGi and Java EE in GlassFish - Tech Days 2010 India

8

GlassFish v3 & OSGi

• No OSGi APIs are used in GlassFish• HK2 provides abstraction layer

• All GlassFish modules are OSGi bundles• Felix is default, also runs on Knopflerfish &

Equinox• Can run in an existing shell• 216 modules in v3

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

Page 9: OSGi and Java EE in GlassFish - Tech Days 2010 India

9

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

Page 10: OSGi and Java EE in GlassFish - Tech Days 2010 India

10

GlassFish: The next generation platform

NamingService

TransactionService

InjectionManager

SecurityService

Configuration

Deployment

Monitoring/Serviceability/

Logging

Clustering

Java SE

GlassFish V3 Core(Module Subsystem)

Grizzly Framework

Application Container

Config Deploy Security Monitor Cluster

Management Console Management CLIUpdate Center

OSGi

RESTWeb Services

ScriptingWebSpace Server

PortalOpenMQ

JMSOpenESB OpenSSO

WebContainer

JSFConnection

Pooling (JCA)Java

Persistence EJB ContainerWeb Services

Interop

Page 11: OSGi and Java EE in GlassFish - Tech Days 2010 India

11

GlassFish v3 Runtime with OSGi

GlassFish V3 modules(OSGi + extra metadata)

GlassFish V3 modules(OSGi + extra metadata)

HK2 Service layerHK2 Service layer OSGiService Layer

OSGiService Layer

OSGi Bundle managementOSGi Bundle management

Random OSGi BundleRandom OSGi Bundle

ServiceMapper

Page 12: OSGi and Java EE in GlassFish - Tech Days 2010 India

12

Create an OSGi Bundle – Using 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

Page 13: OSGi and Java EE in GlassFish - Tech Days 2010 India

13

OSGi Bundle Management in GlassFish

• asadmin deploy –type osgi• “cp” / “rm” glassfish/modules/autostart directory• telnet localhost 6666• Apache Felix Web Console• REST Console bundle• Perl-based shell (Osgish)

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

Page 14: OSGi and Java EE in GlassFish - Tech Days 2010 India

14

Page 15: OSGi and Java EE in GlassFish - Tech Days 2010 India

15

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

Page 16: OSGi and Java EE in GlassFish - Tech Days 2010 India

16

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 ...

Page 17: OSGi and Java EE in GlassFish - Tech Days 2010 India

17

Hybrid Applications

“A hybrid application is an OSGibundle as well as a Java EE archive and hence has both anOSGi bundle context and Java EE context at runtime and  can leveragecapabilities of both the platforms.”

Page 18: OSGi and Java EE in GlassFish - Tech Days 2010 India

18

Why Hybrid Apps ?

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

Page 19: OSGi and Java EE in GlassFish - Tech Days 2010 India

19

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

Page 20: OSGi and Java EE in GlassFish - Tech Days 2010 India

20

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.

Page 21: OSGi and Java EE in GlassFish - Tech Days 2010 India

21

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

Page 22: OSGi and Java EE in GlassFish - Tech Days 2010 India

22

Hybrid Applications - Demo

• 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

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

Page 23: OSGi and Java EE in GlassFish - Tech Days 2010 India

23

Extending GlassFish v3Using 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

Page 24: OSGi and Java EE in GlassFish - Tech Days 2010 India

24

Create an OSGi bundle - NetBeans

Page 25: OSGi and Java EE in GlassFish - Tech Days 2010 India

25

Looking Forward

• GlassFish v3• Support OSGi-Enabled Java EE applications• Implement Java EE-related OSGi services• Expose Java EE services as OSGi services• Improve underlying OSGi framework administration

Page 26: OSGi and Java EE in GlassFish - Tech Days 2010 India

26

References

• glassfish.org• blogs.sun.com/theaquarium• twitter.com/glassfish• [email protected]

Page 27: OSGi and Java EE in GlassFish - Tech Days 2010 India

<Insert Picture Here>

OSGi & Java EE in GlassFish

Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta