Your SlideShare is downloading. ×
Apache Aries Blog Sample
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Apache Aries Blog Sample

2,746
views

Published on

Zoe Slattery

Zoe Slattery

Published in: Technology

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,746
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Aries is one of 36 Apache Incubator projects
  • The Aries JPA container context bundle provides a blueprint namespace for dependency injection of managed JPA resources. 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.
  • NamespaceHandlers registered with a property whose value is the target nameapce: props.put("osgi.service.blueprint.namespace", "http://aries.apache.org/xmlns/transactions/v1.0.0"); A DI container standardizing established Spring conventions XML Blueprint definition describes component configuration and scope Optionally publish and consume components to/from OSGi service registry. Simplifies unit test outside either Java EE or OSGi r/t. The Aries BP container implementation is highly extensible: Namespace handlers supported to extend the Blueprint definitions Bean interceptors can be registered by handlers Other Aries components contribute handlers – “jpa” and “jta” handlers. Some other Aries components are implemented as Blueprint bundles themselves e.g. JPA container
  • jndi-url bundle registers a JNDI ObjectFactory for “osgi:services” Contexts in the service registry (“OsgiURLContextFactory“) jndi-core bundle registers an InitialContextFactoryBuilder and ObjectFactoryBuilder with JVM. The ICFB creates a Context which looks in the SR for an ObjectFactories which can process the URI scheme. If it delegates to the osgi:services ObjectFactory then this returns the service in the SR.
  • The Aries JPA container context bundle provides a blueprint namespace for dependency injection of managed JPA resources. 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.
  • The Aries JPA container context bundle provides a blueprint namespace for dependency injection of managed JPA resources. 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.
  • Application managed JPA Need Java code to look up the EMF service From that, create EM object Surround with try...finally, need to close. Container managed BP container – uses JPA context NS handler Injects EM object into Bean, all the Programmer does is call em.persist JTA – again BP container understands the Tx and ensures that changes to the DB are Managed as transactions
  • Application managed JPA Need Java code to look up the EMF service From that, create EM object Surround with try...finally, need to close. Container managed BP container – uses JPA context NS handler Injects EM object into Bean, all the Programmer does is call em.persist JTA – again BP container understands the Tx and ensures that changes to the DB are Managed as transactions
  • Provides support for “Application managed” JPA . 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 EMF service lifecyce follows the persistence bundle lifecycle JPA Provider gets persistence bundle classloader from PUInfo.
  • Provides support for “Application managed” JPA . 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 EMF service lifecyce follows the persistence bundle lifecycle JPA Provider gets persistence bundle classloader from PUInfo.
  • Provides support for “Application managed” JPA . 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 EMF service lifecyce follows the persistence bundle lifecycle JPA Provider gets persistence bundle classloader from PUInfo.
  • Transcript

    • 1.
        Apache Aries An Open Source project for Enterprise OSGi Applications
    • 2.
        Apache Aries An Open Source project for Enterprise OSGi Applications
    • 3.
        Agenda
    • 8.
        History
      • “ Aries” created as a new Apache incubator project in Sep 2009
      • Independent of OSGi framework provider and integration/server runtime
      • Initial contribution included the Blueprint container implementation developed originally by the Apache Geronimo community.
      • Web Site for all resources and documentation: http://incubator.apache.org/aries/
    • 9.
        Community
      • Currently 43 committers, contributors from Ericsson, IBM, JBoss, LinkedIn, Progress, ProSyst, SAP and individuals
        • http://incubator.apache.org/aries/people.html
      • Creation of community is one of the primary goals of the Apache Incubator
    • 10.
        Aries Content includes…
        http://svn.apache.org/repos/asf/incubator/aries/trunk/
    • 18.
        Aries Samples
      • AriesTrader – Apache Geronimo DayTrader Java EE benchmark application converted to OSGi Application using web and blueprint components
        • Objective is to demonstrate best practices
        • 19. Performance benchmarking
      • Blog Sample – New application to demonstrate Aries features
      • 20. The Samples illustrate how to run Aries applications on a standard OSGi f/w (e.g. Equinox) + Aries + dependencies (Derby DB, PaxWeb servlet container).
      • 21. http://incubator.apache.org/aries/samples.html
    • 22.
        Example “Blog” Application Architecture
        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
    • 23. Run the Blog Sample EBA
    • 24.
        Aries Application Assembly and Deploy
      • Pluggable BundleConverters
      • 25. - WabConverterService
        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-biz; 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-web; version="[1.0.0,1.0.0]”
        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-biz; version= 1.0.0 , aries.sample.blog-api; version= 1.0.0 , aries.sample.blog-persistence; version= 1.0.0 ,
      • aries.sample.blog-web; version=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.
      Felix File Install
      • org.apache.aries.application.management
        Pluggable ApplicationResolver - NoOpResolver - OBRAriesResolver
    • 26.
        Example “Blog” Application Architecture
        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
    • 27.
        Blog-biz - blueprint.xml
        .....
      • <bean id=&quot;blogEntryManager&quot; class=&quot;org.apache.aries.samples.blog.biz.BlogEntryManagerImpl&quot;>
      • 28. <property name=&quot;persistenceService&quot; ref=&quot;persistenceManager&quot;/>
      • 29. </bean>
      • 30. <bean id=&quot;bloggingServiceComponent&quot; class=&quot;org.apache.aries.samples.blog.biz.BloggingServiceImpl&quot;>
      • 31. <property name=&quot;blogEntryManager&quot; ref=&quot;blogEntryManager&quot;/>
      • 32. <property name=&quot;blogAuthorManager&quot; ref=&quot;blogAuthorManager&quot;/>
      • 33. </bean>
      • 34. <service ref=&quot;bloggingServiceComponent&quot; interface=&quot;org.apache.aries.samples.blog.api.BloggingService&quot;/>
      • 35. <reference id=&quot;persistenceManager&quot; interface=&quot;org.apache.aries.samples.blog.api.persistence.BlogPersistenceService&quot;/>
    • 36.
        Aries Blueprint Container
      A static assembly and configuration of components (POJOs) ‏
        Managed beans
        publishes service
        consumes service
        Blueprint bundle
        OSGI-INF/blueprint/ blueprint.xml
    • 37.
        Aries JNDI integration
      • Provides JNDI-based access to OSGi Service Registry
        < blueprint xmlns =... > < bean id = &quot;bloggingServiceComponent&quot; class = &quot;org.apache.aries.samples.blog.biz.BloggingServiceImpl&quot; > </ bean > < service ref = &quot;bloggingServiceComponent&quot; interface = &quot;org.apache.aries.samples.blog.api.BloggingService&quot; /> ... </ blueprint >
        registerService
        InitialContext ic = new InitialContext(); BloggingService blog= ic.lookup( &quot;osgi:services/&quot; + BloggingService. class .getName());
        getService
      • A way for a Web component to access a Blueprint component
        OSGi Service Registry
        JNDI Context
    • 38.
        Example “Blog” Application Architecture
        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
    • 39.
        Blog Sample - persistence.xml
      <persistence-unit name=&quot;blogExample&quot; transaction-type=&quot;JTA&quot;> <description>Persistence unit for the example blogging application</description> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <jta-data-source>osgi:services/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/blogdb) </jta-data-source> <non-jta-data-source>osgi:services/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/blogdbnojta) </non-jta-data-source> <class>org.apache.aries.samples.blog.persistence.jpa.entity.AuthorImpl</class> <class>org.apache.aries.samples.blog.persistence.jpa.entity.EntryImpl</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> </persistence-unit> OpenJPA
    • 40.
        Aries JPA Container – Blueprint Integration
      Example blueprint with JPA resource injection and container-managed transactions
        <bean id=&quot;persistenceImpl&quot;
      • class=&quot;org.apache.aries.samples.blog.persistence.jpa.BlogPersistenceServiceImpl&quot;>
      • 41. <tx:transaction method=&quot;*&quot; value=&quot;Required&quot; />
      • 42. <jpa:context property=&quot;entityManager&quot; unitname=&quot;blogExample&quot; />
      • 43. </bean>
      • 44. <service ref=&quot;persistenceImpl&quot;
      • 45. interface=&quot;org.apache.aries.samples.blog.api.persistence.BlogPersistenceService&quot;>
      • 46. </service>
    • 47.
        Example “Blog” JPA persistence bundle
      • MetaPersistence
        OSGI-INF/blueprint/ blueprint.xml
        META-INF/ persistence.xml
        blog-persistence
        Blog Persistence 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
        Entity Manager
      • Factory Service
      The Aries JPA container uses the MetaPersistence and the persistence.xml to register the EM Factory service
    • 48.
        Example “Blog” JPA persistence bundle
      Queue
        Blog Persistence Service
      • MetaPersistence
        OSGI-INF/blueprint/ blueprint.xml
        META-INF/ persistence.xml
        blog-persistence
        Entity Manager
      • Factory Service
    • 49. JDBC vs JPA comparison JDBC persistence JPA persistence Number of ';' in Java source 238 86 Number of bundles used by platform 18 34
    • 50. public void createAuthor(String email, Date dob, String name, String displayName, String bio) { try { Connection connection = dataSource.getConnection(); String sql = &quot;INSERT INTO AUTHOR VALUES (?,?,?,?,?)&quot;; 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(&quot;The Author &quot; + email + &quot; cannot be inserted.&quot;); } catch (SQLException e) { e.printStackTrace(); throw new IllegalArgumentException(e.getMessage()); } } createAuthor() method in JDBC persistence service implementation
    • 51. 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
    • 52.
        Current Aries Consumers
      • Aries SNAPSHOT builds available right now
      • 53. Aries 0.1 Release will be available soon.
      • 54. Aries components are currently used by:
        • Apache Geronimo
        • 55. Apache Felix Karaf
        • 56. JBossOSGi
        • 57. WebSphere Application Server
    • 58.
        Futures
      • There are many new application-centric features that Aries may develop including:
        • message-driven blueprint components and services
        • 59. declarative role-based security for blueprint components
        • 60. annotation-based alternative to XML configuration
        • 61. resource-reference metadata and bindings
        (Original Proposal: http://wiki.apache.org/incubator/AriesProposal)
      • Interested in getting involved?
        • http://incubator.apache.org/aries/gettinginvolved.html
    • 62.
        The end........
    • 63.
        Aries JPA Container – Application Managed PUs
      • Persistence bundle
      • Bundle Manifest
      • 64.
      • 65. Meta-Persistence:
      • 66. META-INF/persistence.xml
      • META-INF/
      • 67. persistence.xml
      • OSGI-INF/blueprint/
      • 68. blueprint.xml
      JPA container looks for MetaData persistence Headers. Locates descriptions and registers an EM Factory Service using data from - persistence.xml - JPA provider - DataSource
      • JPA provider (Open JPA)
      DataSource (blogDB) JNDI Implementation of PersistenceProvider
      • org.apache.aries.jpa.container
    • 69.
        Aries JPA Container – Container Managed PUs
      • Persistence bundle
        Bundle Manifest … Meta-Persistence: OSGI-INF/persistence.xml
        META-INF/
      • persistence.xml
        OSGI-INF/blueprint/ blueprint.xml
      BP container calls service if it encounters a jpa namespace element Calls the container service to let It know there is a new client Registers EM factory shadow Against the persistence service
      • org.apache.aries.jpa.blueprint.aries
      • org.apache.aries.jpa.container.context
    • 70.
        Aries JTA transactions
      • Persistence bundle
        Bundle Manifest … Meta-Persistence: OSGI-INF/persistence.xml
        META-INF/
      • persistence.xml
        OSGI-INF/blueprint/ blueprint.xml
      BP container calls Namespace Manager service if it encounters a jta namespace element Transaction Manager service called by interceptor to start and end transactions.
      • org.apache.aries.transaction.blueprint
      org.apache.aries.transaction.manager
      • JTA provider (Geronimo)