Presentation is loading. Please wait.

Presentation is loading. Please wait.

Enterprise OSGi Applications with Apache Aries Zoe Slattery, Jeremy Hughes ApacheCon Atlanta November 2010.

Similar presentations


Presentation on theme: "Enterprise OSGi Applications with Apache Aries Zoe Slattery, Jeremy Hughes ApacheCon Atlanta November 2010."— Presentation transcript:

1 Enterprise OSGi Applications with Apache Aries Zoe Slattery, Jeremy Hughes ApacheCon Atlanta November 2010

2 Holly Cummins QCon London 2010 Ian Robinson2 A (very) brief history of programming In the beginning, there were bits... 0101011101001001010010010011011101101101101

3 Holly Cummins QCon London 2010 Ian Robinson3 A (very) brief history of programming Then came words... mov ah,9 mov dx,offset hello_message int 21h mov ah,9 mov dx,offset hello_message int 21h

4 Holly Cummins QCon London 2010 Ian Robinson4 A (very) brief history of programming... functions and libraries... #include main() { printf ("Hello World!\n"); } #include main() { printf ("Hello World!\n"); }

5 Holly Cummins QCon London 2010 Ian Robinson5 A (very) brief history of programming... objects... public class HelloWorldSayer { public void sayHello() { System.out.println("Hello, world!\n"); } public class HelloWorldSayer { public void sayHello() { System.out.println("Hello, world!\n"); }

6 Holly Cummins QCon London 2010 Ian Robinson6 A (very) brief history of programming... and now - Enterprise OSGi public class HelloWorldClient { HelloWorldService service = null; public void startUp() { service.hello(); } public class HelloWorldClient { HelloWorldService service = null; public void startUp() { service.hello(); }

7 Holly Cummins QCon London 2010 Ian Robinson7 What was wrong with where we were? “ The number of lines of code written doubles every 7 years “ Between now and 2017 we'll produce more code than the total amount of code ever written! “ 50% of devt time is spent understanding existing code “ 90% of software cost is legacy maintenance and evolution Burton Group’s Kirk Knoernschild, Feb 2010: http://techdistrict.kirkk.com/2010/02/17/osgi-devcon-preview/ Application developers need help Application deployers need help Java needs help

8 Holly Cummins QCon London 2010 Ian Robinson8 IDLJDBCJNDIJAXPJAASJMXRMI-IIOP Enterprise APIs in Java SE (Required for Java EE) Servlet JSP Web Container JavaMail JAF JAX-RPCJAX-WSWeb ServicesWS MetadataJMSJTAJACCJAXRManagementJPAEJB SAAJ HTTP/SSL Direct dependency Optional dependencies JSTLJSF JAXB JCA Debug Common Annotations Java EE Web technologies StAX Indirect (soft) dependency JAX-RS JASPIC CDI & DI

9 Holly Cummins QCon London 2010 Ian Robinson9 (capability == bloat)? HTTP Session ReplicationConnection ManagementPersistence Providers User RegistriesEvent Mgmt Logging and Tracing MBean Server Admin Console and scripting DataSourcesMessaging EnginesSecurity Transport Channels Workload Management HTTP Serving and routing High Availability Management Transaction Logging and Recovery Thread management ClassloadingProvisioning Monitoring Policy and SLA mgmt Configuration …

10 Holly Cummins QCon London 2010 Ian Robinson10 Beyond Java EE… HTTP Session ReplicationConnection ManagementPersistence Providers User RegistriesEvent Mgmt Logging and Tracing MBean Server Admin Console and scripting DataSourcesMessaging EnginesSecurity Transport Channels Workload Management HTTP Serving and routing High Availability Management Transaction Logging and Recovery Thread management ClassloadingProvisioning Monitoring Policy and SLA mgmt Configuration … Batch Telephony BPM Dynamic Scripting SCA Business Rules Complex Event Processing …

11 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 oagis order ebay content datafile ecommerce entity googlebase ofbiz widget minilang party pos. product workeffort workflow … sunjce_prov. plugin jsse jce rt dnsns.. … Class Not Found Exception BeginHere The Global Classpath

12 Holly Cummins QCon London 2010 Ian Robinson12 12 Java Platform Modularity Classes encapsulate data Packages contain classes Jars contain packages Class visibility: private, package private, protected, public No “jar scoped” access modifiers. No means for a jar to declare its dependencies. No versioning. Jars have no modularization characteristics At runtime there is just a collection of classes on a global classpath Jar Package Class Package Class Package Class Problems with JARs

13 Holly Cummins QCon London 2010 Ian Robinson13 Problems with EARs/WARs Enterprise Apps have isolated classpaths but… Across apps - each archive typically contains all the libraries required by the application Common libraries/frameworks get installed with each application Multiple copies of libraries in memory Within apps - 3 rd party libraries consume other 3 rd party libraries leading to version conflicts 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

14 Holly Cummins QCon London 2010 Ian Robinson14 How does OSGi help reduce cost?

15 Holly Cummins QCon London 2010 Ian Robinson15 Unit of modularity – 'Bundle' 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: org.apache.commons.logging;version="1.0.4" Export-Package: com.sample.myservice.api;version="1.0.0"

16 Holly Cummins QCon London 2010 Ian Robinson16 Bundles have lifecycles INSTALLED RESOLVED UNINSTALLED ACTIVE STOPPING STARTING start stop

17 Holly Cummins QCon London 2010 Ian Robinson17 Bundles communicate - OSGi Services Bundle A Bundle B Service Register Listen

18 Holly Cummins QCon London 2010 Ian Robinson18 Modularity inside Enterprise platforms OSGi inside IBM WebSphere Oracle WebLogic Red Hat Jboss Oracle GlassFish SpringSource dm Server Paremus Service Fabric Eclipse Platform Apache Geronimo Why do you think we did that?

19 Holly Cummins QCon London 2010 Ian Robinson19 What about the Applications? Java EE defines an enterprise application programming model and container contracts to honour it OSGi has typically defined platform specifications and services for those platforms. It hasn’t had much to say on application concerns such as  What's the component model?  What's the persistence architecture?  How are qualities of service configured?  Remoting This has changed in OSGi v4.2.

20 Holly Cummins QCon London 2010 Ian Robinson20 OSGi Enterprise Specification Released 22 March 2010 Brings Enterprise technologies and OSGi together Using existing Java SE/EE specifications: JTA, JPA, JNDI, JMX, WebApps… Adds Spring-derived Blueprint component model and dependency injection (DI) container

21 Holly Cummins QCon London 2010 Ian Robinson21 New Open Source Activities Apache “Aries” created as a new Apache incubator project in Sep 2009: to provide enterprise OSGi spec implementations to provide an environment for collaboration and innovation about the standards to build a broad development community Version 0.2-incubating released in Sept 2010 Eclipse Enterprise Modules (“Gemini”) Sub-projects provide EEG spec implementations http://www.eclipse.org/gemini/

22 Holly Cummins 22 Aries Content includes… Blueprint container JPA integration JTA integration JMX JNDI integration Application assembly and deployment META-INF/services handler Samples, documentation, integrator’s guide

23 Holly Cummins 23 Samples HelloWorld – RAD Free tools and EBA Blog – Using JNDI – Container managed JPA Twitter – Resolving application dependencies

24 Holly Cummins 24 Aries Applications Groups of bundles with additional meta data *.eba APPLICATION-MANIFEST Can be references to bundles – don't actually need to include bundle – can be pulled in from a repository – unlike EAR Aries runtime parses application manifest and installs bundles

25 Holly Cummins 25 Aries Blueprint Container Managed beans publishes service consumes service Blueprint bundle OSGI-INF/blueprint/ blueprint.xml A static assembly and configuration of components (POJOs)‏

26 Holly Cummins 26 Hello world sample - demo Use Eclipse to talk around app – ecl_osgi – Workspace timw Very simple 3 bundles Blue print service The API – just defines a service Hwserver implements the service HW client uses the service Export as EBA

27 Holly Cummins 27 Samples HelloWorld – RAD Free tools and EBA Blog – Using JNDI – Container managed JPA – Web application Twitter – Resolving application dependencies

28 Holly Cummins 28 The Blog sample Blogging Service Blog Persistence Service blog-web Web application bundle MetaPersitstence WEB-INF/ web.xml OSGI-INF/blueprint/ blueprint.xml OSGI-INF/blueprint/ blueprint.xml JNDI META-INF/ persistence.xml blog.eba blog-biz blog-persistence blog-api

29 Holly Cummins 29 Run the Blog Sample EBA j ava -jar etc Create an author – make sure we touch the DB Bring up GOAT Look at bundles Start the framework with Blog already in Point to bundles Navigate to Blog sample and click on it Navigate to GOAT screen

30 Holly Cummins 30 Blog sample – Web and Business logic Blogging Service Blog Persistence Service blog-web Web application bundle MetaPersitstence WEB-INF/ web.xml OSGI-INF/blueprint/ blueprint.xml OSGI-INF/blueprint/ blueprint.xml META-INF/ persistence.xml JNDI blog.eba blog-biz blog-persistence blog-api

31 Holly Cummins 31 Blog-biz - blueprint.xml.....

32 Holly Cummins 32 Aries JNDI integration Provides JNDI-based access to OSGi Service Registry... registerService InitialContext ic = new InitialContext(); BloggingService blog= ic.lookup("osgi:services/" + BloggingService.class.getName()); getService A way for a Web component to access a Blueprint component OSGi Service Registry JNDI Context

33 Holly Cummins 33 Blog Sample Blogging Service Blog Persistence Service blog-web Web application bundle MetaPersitstence WEB-INF/ web.xml OSGI-INF/blueprint/ blueprint.xml OSGI-INF/blueprint/ blueprint.xml META-INF/ persistence.xml JNDI blog.eba blog-biz blog-persistence blog-api

34 Holly Cummins 34 Blog Sample - persistence.xml Persistence unit for the example blogging application org.apache.openjpa.persistence.PersistenceProviderImpl osgi:services/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/blogdb) osgi:services/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/blogdbnojta) org.apache.aries.samples.blog.persistence.jpa.entity.AuthorImpl org.apache.aries.samples.blog.persistence.jpa.entity.EntryImpl true OpenJPA

35 Holly Cummins 35 Aries JPA Container – Blueprint Integration <bean id="persistenceImpl" class="org.apache.aries.samples.blog.persistence.jpa.BlogPersistenceServiceImpl"> <service ref="persistenceImpl" interface="org.apache.aries.samples.blog.api.persistence.BlogPersistenceService"> Example blueprint with JPA resource injection and container-managed transactions

36 Holly Cummins 36 Example “Blog” JPA persistence bundle MetaPersistence OSGI-INF/blueprint/ blueprint.xml META-INF/ persistence.xml blog-persistence Blog Persistence Service Entity Manager Factory Service The Aries JPA container uses the MetaPersistence and the persistence.xml to register the EM Factory service The JPA container finds jpa:context and injects a managed persistence context. The declarative transactions runtime locates the transaction metadata and enforces the defined transaction behaviour

37 Holly Cummins 37 JDBC vs JPA comparison

38 Holly Cummins 38 Samples HelloWorld – RAD Free tools and EBA Blog – Using JNDI – Container managed JPA Twitter – Resolving application dependencies

39 Holly Cummins 39 Twitter sample Twitter Application OSGi Runtime Bundle Repository

40 Holly Cummins 40 The twitter sample Drop EBA into load directory java - Dobr.repository.url=file:///Users/zoe/ApacheConRun ner/twittertest/localrepo.xml -jar osgi- 3.5.0.v20090520.jar -console in two cp *.eba runtime/load

41 Holly Cummins 41 Current Aries Consumers Latest release 0.2-incubating Graduation to TLP in process Aries components are currently used by: Apache Geronimo Apache Karaf JBossOSGi WebSphere Application Server ????

42 42 In the near future… all major Java enterprise runtimes will support Apps deployed as bundles

43 Holly Cummins QCon London 2010 Ian Robinson43 Resources Apache Aries http://incubator.apache.org/aries/ RAD free tools http://marketplace.eclipse.org/content/ibm-rational-development- tools-osgi-applications

44 Holly Cummins QCon London 2010 Ian Robinson44 Any questions?

45 Holly Cummins 45 public void createAuthor(String email, Date dob, String name, String displayName, String bio) { try { Connection connection = dataSource.getConnection(); String sql = "INSERT INTO AUTHOR VALUES (?,?,?,?,?)"; PreparedStatement ppsm = connection.prepareStatement(sql); ppsm.setString(1, email); ppsm.setString(2, bio); ppsm.setString(3, displayName); if (dob != null) ppsm.setDate(4, new java.sql.Date(dob.getTime())); else ppsm.setDate(4, null); ppsm.setString(5, name); int insertRows = ppsm.executeUpdate(); ppsm.close(); connection.close(); if (insertRows != 1) throw new IllegalArgumentException("The Author " + email + " cannot be inserted."); } catch (SQLException e) { e.printStackTrace(); throw new IllegalArgumentException(e.getMessage()); } } createAuthor() method in JDBC persistence service implementation

46 Holly Cummins 46 public void createAuthor(String email, Date dob, String name, String displayName, String bio) { AuthorImpl a = new AuthorImpl(); a.setEmail(email); a.setName(name); a.setDisplayName(displayName); a.setBio(bio); a.setDob(dob); em.persist(a); } Example: createAuthor() method in JPA persistence service implementation


Download ppt "Enterprise OSGi Applications with Apache Aries Zoe Slattery, Jeremy Hughes ApacheCon Atlanta November 2010."

Similar presentations


Ads by Google