Ian Robinson
IBM Distinguished Engineer
Is OSGi Ready for the Enterprise? Ian Robinson IBM Distinguished - - PowerPoint PPT Presentation
Is OSGi Ready for the Enterprise? Ian Robinson IBM Distinguished Engineer The Questions Why should we care? Does Enterprise Java need OSGi? Does OSGi need Enterprise Java? March12, 2010 QCon London 2010 Ian Robinson
Ian Robinson
IBM Distinguished Engineer
March12, 2010 QCon London 2010 Ian Robinson 2
March12, 2010 QCon London 2010 Ian Robinson 3
IDL JDBC JNDI JAXP JAAS JMX RMI-IIOP
Enterprise APIs in Java SE (Required for Java EE)
Servlet JSP
Web Container
JavaMail JAF JAX-RPC JAX-WS Web Services WS Metadata JMS JTA JACC JAXR Management JPA EJB SAAJ HTTP/SSL Direct dependency Optional dependencies JSTL JSF JAXB JCA Debug Common Annotations
Java EE Web technologies
StAX Indirect (soft) dependency JAX-RS JASPIC CDI & DI
March12, 2010 QCon London 2010 Ian Robinson 4
IDL JDBC JNDI JAXP JAAS JMX RMI-IIOP
Enterprise APIs in Java SE (Required for Java EE)
Servlet JSP
Web Container
JavaM ail JAF JAX- RPC JAX- WS Web Service s WS Metada ta JMS JTA JACC JAXR Manag ement JPA EJB SAA J HTTP/ SSL Direct dependency Optional dependencies JSTL JSF JAX B JCA Deb ug Com mon Anno tation s
Java EE Web technologies
StAX Indirect (soft) dependency JAX- RS JASPI C CDI & DI
HTTP Session Replication Connection Management Persistence Providers User Registries Event Mgmt Logging and Tracing MBean Server Admin Console and scripting DataSources Messaging Engines Security Transport Channels Workload Management HTTP Serving and routing High Availability Management Transaction Logging and Recovery Thread management Classloading Provisioning Monitoring Policy and SLA mgmt Configuration …
March12, 2010 QCon London 2010 Ian Robinson 5
IDL JDBC JNDI JAXP JAAS JMX RMI-IIOPEnterprise APIs in Java SE (Required for Java EE)
Servlet JSPWeb Container
JavaMail JAF JAX-RPC JAX-WS Web Services WS Metadata JMS JTA JACC JAXR Management JPA EJB SAAJ HTTP/SSL Direct dependency Optional dependencies JSTL JSF JAXB JCA Debug Common AnnotationsJava EE Web technologies
StAX Indirect (soft) dependency JAX-RS JASPIC CDI & DIHTTP Session Replication Connection Management Persistence Providers User Registries Event Mgmt Logging and Tracing MBean Server Admin Console and scripting DataSources Messaging Engines Security Transport Channels Workload Management HTTP Serving and routing High Availability Management Transaction Logging and Recovery Thread management Classloading Provisioning Monitoring Policy and SLA mgmt Configuration …
Batch Telephony BPM Dynamic Scripting SCA Business Rules Complex Event Processing
…
March12, 2010 QCon London 2010 Ian Robinson 6
The major AppServer and Integration vendors and Open Source communities have all embraced OSGi for their own internal architecture
GlassFish, SpringSource dm Server, Paremus Service Fabric, Eclipse Platform, Apache Geronimo, (non-exhaustive list)
These complex engineering projects required a modular approach to development as they evolved and grew
enables development teams to focus on their area of concern.
Does the Enterprise runtime need OSGi? The vendors answered with a resounding Yes.
March12, 2010 QCon London 2010 Ian Robinson 7
It hasn’t had much to say on application concerns such as
What's the component model? Whets the persistence architecture? How are qualities of service configured? Remoting
March12, 2010 QCon London 2010 Ian Robinson 8
http://www.gutenberg.org
March12, 2010 QCon London 2010 Ian Robinson 9
Java Platform Modularity
Class visibility:
public
No means for a jar to declare its dependencies. No versioning. Jars have no modularization characteristics
classes on a global classpath
Jar Jar Package Package Class Class Class Class Class Class Package Package Class Class Class Class Class Class Package Package Class Class Class Class Class Class
March12, 2010 QCon London 2010 Ian Robinson 10
Java VM log4j barcode4j axis batik commons derby fop ezmorph freemarker httpunit jakarta jcl json jdbm jdom jenks jpos18 jython looks lucene mail mx4j naming jetty poi resolver rome serializer servlets tomcat velocity ws-commons xalan wsdl4j xerces xmlgraphics xmlrpc xmlapis .. geronimo bsh bsf guiapp hhfacility manufact. marketing minerva accounting assetmaint base bi catalina common
ebay content datafile ecommerce entity googlebase
widget minilang party pos. product workeffort workflow … sunjce_prov. plugin jsse jce rt dnsns .. … Class Not Found Exception
Begin Begin Here Here
March12, 2010 QCon London 2010 Ian Robinson 11
webA.war WEB-INF/classes/servletA.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webA.war WEB-INF/classes/servletA.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webB.war WEB-INF/classes/servletB.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webB.war WEB-INF/classes/servletB.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webC.war WEB-INF/classes/servletC.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webC.war WEB-INF/classes/servletC.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar…
plankton.v1 plankton.v2
March12, 2010 QCon London 2010 Ian Robinson 12
March12, 2010 QCon London 2010 Ian Robinson 13
The higher-level module is the “bundle” which is a normal jar containing:
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: MyService bundle Bundle-SymbolicName: com.sample.myservice Bundle-Version: 1.0.0 Bundle-Activator: com.sample.myservice.Activator Import-Package:
Export-Package: com.sample.myservice.api;version="1.0.0"
META-INF/MANIFEST.MF
OSGi headers in the manifest include:
Can explicitly define the required version or version range for each package.
packages are encapsulated by the bundle.
Eclipse tooling provides convenient editors for the manifest
March12, 2010 QCon London 2010 Ian Robinson 14
Class sharing and visibility is based
class loader trees built up at runtime.
Multiple versions of bundles supported concurrently. No global, flat classpath to search. Each bundle has its own classloader / classpath. More efficient for large systems.
March12, 2010 QCon London 2010 Ian Robinson 15
Optional BundleActivator class has Optional BundleActivator class has
bundle bundle
Header in Manifest refers to this class class BundleActivator has 2 methods BundleActivator has 2 methods
Start: Initialize bundle
Stop: Cleanup
INSTALLED INSTALLED RESOLVED RESOLVED UNINSTALLED UNINSTALLED ACTIVE ACTIVE STOPPING STOPPING STARTING STARTING start start stop stop
Resolution of dependencies at deployment time. If resolution fai Resolution of dependencies at deployment time. If resolution fails, ls, bundle is not available for use. bundle is not available for use.
No ClassNotFoundExceptions at runtime Bundle lifecycle is dynamic and independent of the rest of the f Bundle lifecycle is dynamic and independent of the rest of the f/w. /w.
BundleListener can be registered for bundle state change events. events.
March12, 2010 QCon London 2010 Ian Robinson 16
OSGi intrinsically supports SOA through its service layer. The core platform includes a non-durable “Service Registry” component. Services are published to and discovered from this Service Registry.
bundles. An OSGi service is a POJO published to the SR under one or more Java interface names with optional key/value pair metadata
Services are fully dynamic and typically have the same lifecycle as the bundle that provides them.
S
March12, 2010 QCon London 2010 Ian Robinson 17
March12, 2010 QCon London 2010 Ian Robinson 18
Apache “Aries” created as a new Apache incubator project in Sep 2009:
http://incubator.apache.org/aries/
new technologies to inform further EEG standardization.
In particular the programming model aspects of OSGi applications
in an enterprise environment such as multi-bundle composites.
implementation and adoption of EEG specs Eclipse Enterprise Modules (“Gemini”)
http://www.eclipse.org/proposals/gemini/
March12, 2010 QCon London 2010 Ian Robinson 19
Specifies a Dependency Injection container, standardizing established Spring conventions Configuration and dependencies declared in XML “module blueprint”, which is a standardization of Spring “application context” XML.
services Simplifies unit test outside either Java EE or OSGi r/t. The Blueprint DI container is a part of the server runtime (compared to Spring which is part of the application.)
dependencies injected publishes service consumes service
Module Blueprint scoped by a bundle (one per bundle). Multiple <components /> per Module-Context A static assembly and configuration of components (POJOs) Blueprint managed bundle
public class ShopImpl { private BillingService billingService; void setBillingService(BillingService srv) { billingService = srv; } void process(Order o) { billingService.bill(o); } } e-Commerce <blueprint> <bean id=”shop” class=”org.example.ecomm.ShopImpl”> <property name=”billingService” ref=”billingService” /> </bean> <reference id=”billingService” interface=”org.example.bill.BillingService” /> </blueprint>
e-Commerce bundle
without the bundle caring
public interface BillingService { void bill(Order o); } Billing <blueprint> <service ref=”service” interface = ”org.example.bill.BillingService” /> <bean id=”service” scope=”prototype” class=”org.example.bill.impl.BillingServiceImpl” /> </blueprint>
Billing service bundle
new instance is created by the container for each use.
March12, 2010 QCon London 2010 Ian Robinson 22
March12, 2010 QCon London 2010 Ian Robinson 23
Each persistence bundle has its standard JPA metadata located through the Meta- Persistence bundle header. JPA Container locates a JPA Provider which can service the PU and registers a Provider- created EntityManagerFactory service for each PU in each persistence bundle
follows the persistence bundle lifecycle JPA Provider gets persistence bundle classloader from PUInfo.
Persistence bundle
Bundle Manifest … Meta-Persistence: OSGI-INF/persistence.xml OSGI-INF/ persistence.xml
Used to build the EntityManagerFactory Managed EntityManagerFactory Registered on behalf of the persistence bundle
JPA Provider
javax.persistence.spi. PersistenceProvider service
createContainerEMF (PersistenceUnitInfo) Uses Registers EntityManagerFactory service per PU
Entities
Uses
March12, 2010 QCon London 2010 Ian Robinson 24
The Aries JPA container context bundle provides a blueprint namespace for dependency injection
Managed persistence units (EntityManagerFactory objects) can be injected with or without a JTA Transaction Services implementation. Managed persistence contexts (EntityManager objects) are only available with a JTA Transaction Services implementation. Both managed persistence units and managed persistence contexts behave as per the JPA specification. Example blueprint with JPA resource injection and container-managed transactions:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:jta="http://aries.apache.org/xmlns/transactions/v1.0.0" xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"> <bean id=“appMgd“ class=“com.acme.AppManaged”> <jpa:unit property="emf" unitname="myUnit" /> </bean> <bean id="containerMgd“ class=“com.acme.Container”> <jpa:context property="em" unitname=“myUnit“/> <jta:transaction method=“*" value=“Required" /> </bean> </blueprint>
March12, 2010 QCon London 2010 Ian Robinson 25
JMX OSGi Manager <<MBean>> Framework MBean <<MBean>> Bundle State MBean <<MBean>> Service St ate MBean <<MBean>> Package St ate MBean <<MBean>> Configuration Admin MBean <<MBean>> Permission Admin MBean <<MBean>> Provisi oning ServiceMBean <<MBean>> User Admin MBean PermissionAdmin Configuration Admin Provisioning Service User Admin MBean Server <<MBean>> Blue print MBean
Framework MBeans Compendium MBeans Additional Aries MBeans
March12, 2010 QCon London 2010 Ian Robinson 26
<blueprint xmlns=...> <bean id="bloggingServiceComponent" class="org.apache.aries.BloggingServiceImpl"> </bean> <service ref="bloggingServiceComponent" interface="org.apache.aries.samples.blog.api.BloggingService"/> ... </blueprint>
registerService InitialContext ic = new InitialContext(); BloggingService blog= ic.lookup("osgi:services/" + BloggingService.class.getName()); getService
OSGi Service Registry JNDI Context
March12, 2010 QCon London 2010 Ian Robinson 27
March12, 2010 QCon London 2010 Ian Robinson 28
webA.war WEB-INF/classes/servletA.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webA.war WEB-INF/classes/servletA.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webB.war WEB-INF/classes/servletB.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webB.war WEB-INF/classes/servletB.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webC.war WEB-INF/classes/servletC.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar… webC.war WEB-INF/classes/servletC.class WEB-INF/lib/spring.jar WEB-INF/lib/commons-logging.jar WEB-INF/lib/junit.jar…
No Java code changes; war modules -> bundles Common, bundles may be easily factored out of the WARs and used at specific versions
webA.wab WEB-INF/classes/servletA.class META-INF/MANIFEST.MF webA.wab WEB-INF/classes/servletA.class META-INF/MANIFEST.MF
Bundle Repository WEB-INF/lib/spring.jar;version=“a.b.c” WEB-INF/lib/commons-logging.jar;version=… WEB-INF/lib/json4j.jar;version=… WEB-INF/lib/junit.jar… Bundle Repository WEB-INF/lib/spring.jar;version=“a.b.c” WEB-INF/lib/commons-logging.jar;version=… WEB-INF/lib/json4j.jar;version=… WEB-INF/lib/junit.jar…
webB.wab WEB-INF/classes/servletB.class META-INF/MANIFEST.MF webB.wab WEB-INF/classes/servletB.class META-INF/MANIFEST.MF webC.wab WEB-INF/classes/servletC.class META-INF/MANIFEST.MF webC.wab WEB-INF/classes/servletC.class META-INF/MANIFEST.MF
Import-Package
March12, 2010 QCon London 2010 Ian Robinson 29
WebSphere Administrative Console
March12, 2010 QCon London 2010 Ian Robinson 30
An “OSGi Application”.
application content is the set of bundles contained by-value plus any
repository-hosted dependencies identified during deployment.
Application Manifest Enumerates constituent bundles Declares Application “externals”
blog.eba
blog-persistence.jar blog.jar blog-servlet.jar
Bundle Repository Bundle Repository
json4j.jar
March12, 2010 QCon London 2010 Ian Robinson 31
Application Manifest Enumerates constituent bundles Declares Application “externals”
blog.eba
blog-persistence.jar blog.jar blog-servlet.jar
Bundle Repository Bundle Repository
json4j.jar
Manifest-Version: 1.0 Application-ManifestVersion: 1.0 Application-Name: Blog Application Application-SymbolicName: aries.sample.blog Application-Version: 1.0 Application-Content: aries.sample.blog; version="[1.0.0,1.1.0)", aries.sample.blog-api; version=1.0.0, aries.sample.blog-persistence; version=1.0.0, aries.sample.blog-servlet; version="[1.0.0,1.0.0]"
Application Manifest (developer/assembler authored artefact) Enumerates constituent bundles and allowable version ranges Declares Application “externals” Deployment Manifest (generated during createApplication) Transitively closed description of all bundles resolved at specific versions to “freeze-dry” the application.
Manifest-Version: 1.0 Deployment-ManifestVersion: 1.0 Application-Name: Blog Application Application-SymbolicName: aries.sample.blog Application-Version: 1.0 Deployed-Content: aries.sample.blog; deployed-version=1.0.0, aries.sample.blog-api; deployed-version=1.0.0, aries.sample.blog-persistence; deployed-version=1.0.0, aries.sample.blog-servlet; deployed-version=1.0.0, com.ibm.json.java; deployed-version=1.0.0
Install ( via Admin Console / wsadmin) Deployed Result
March12, 2010 QCon London 2010 Ian Robinson 32
WebSphere Administrative Console
March12, 2010 QCon London 2010 Ian Robinson 33
Blogging Service Blog Persistence Service
blog-servlet
Web application bundle OSGI-INF/ persistence.xml WEB-INF/ web.xml OSGI-INF/blueprint/ blueprint.xml OSGI-INF/blueprint/ blueprint.xml
JNDI EM
blog blog-persistence blog-api
March12, 2010 QCon London 2010 Ian Robinson 34
March12, 2010 QCon London 2010 Ian Robinson 35