third party libraries and osgi - a complicated relationship

38
Third-Party Libraries and OSGi a complicated relationship

Upload: sascha-brinkmann

Post on 13-Aug-2015

47 views

Category:

Internet


2 download

TRANSCRIPT

Page 1: Third party libraries and OSGi - a complicated relationship

Third-Party Libraries and OSGia complicated relationship

Page 2: Third party libraries and OSGi - a complicated relationship

Senior Solution Arch

itect

6 years of WCMS expe

rience

Loves working with J

ava

(script)

Sascha Brinkmann

Hobbies: Biking, Hik

ing, Travelling

Contact: [email protected]

@sasusu

About Me

Page 3: Third party libraries and OSGi - a complicated relationship

About Us

Page 4: Third party libraries and OSGi - a complicated relationship

About Us

1984 Foundation year2004 Adobe Business Partner2005 Adobe Authorized Training Center2010 Winner of Siemens top+ Award2014 100% Adobe focussed for 10 years

Employees: 45Located: Munich, GermanyHappy Adobe customers: +40

Page 5: Third party libraries and OSGi - a complicated relationship

➢ Motivation➢ Challenge➢ Analysis Possible Strategies➢ Tips & Tricks➢ Conclusion

➢ OSGi Basics

Table of Content

Page 6: Third party libraries and OSGi - a complicated relationship

Integration of AEM into a heterogeneous IT systems landscape with interfaces to various subsystems.

AEM

LDAP / Active Directory

Microsoft SharePoint

Microsoft Enterprise Search (FAST)

IBM Lotus Notes Domino

SAP / Hybris

SQL Database

Rest- and Webservices

Amazon S3

Facbook

Twitter

YouTube

Brightcove

Email

FTP

Google Search Appliance

Motivation

InternalExternal

Page 7: Third party libraries and OSGi - a complicated relationship

Our work is all about solving business problems. Solutions for almost every technical challenge are provided by third party libraries from the central maven repository.

Motivation

Page 8: Third party libraries and OSGi - a complicated relationship

How can I use various types of third party libraries and frameworks within my projects?

Challenge

Page 9: Third party libraries and OSGi - a complicated relationship

OSGi Basics

All rights reserved Gosainkunda, Nepal

Page 10: Third party libraries and OSGi - a complicated relationship

OSGi Basics - Apache Felix

Apache Felix is a fundamental element of the technology stack of the Adobe Experience Manager (AEM). It provides the environment for all Java written components.

Java Content Repository (CRX)

Apache Sling

Adobe Experience Manager (WCMS)

OSGi Runtime (Apache Felix)

Page 11: Third party libraries and OSGi - a complicated relationship

one Classloader for the whole Java application

one Classloader per OSGi bundle

Bundle B

Bundle A

Bundle C

Bundle D

Library A

Library C

Library B

Library D

OSGi Basics - Classloading

Key difference between traditional Java Applications and Applications running within OSGi.

Page 12: Third party libraries and OSGi - a complicated relationship

BundleManifest

Consumes Provides

OSGi Basics - Bundle Structure

Page 13: Third party libraries and OSGi - a complicated relationship

Bundle Plugin

Bundle Identifier

Packages provided to other bundles

Packages Consumed from other bundles

Is created by the during the build process.

OSGi Basics - Bundle Manifest

The manifest file is a set of OSGi specific headers. It defines how to deploy and run the OSGi bundle.

Page 14: Third party libraries and OSGi - a complicated relationship

Apache Felix Bundle Plugin

Dependency toother Bundle

OSGi Basics - Maven POM Config

The Apache Felix Bundle Plugin for Maven enhances artifacts with the bundle manifest.

Page 15: Third party libraries and OSGi - a complicated relationship

Strategies to use third party libraries

First Option

Embedding LibrariesSecond Option

Libraries as Bundles

Page 16: Third party libraries and OSGi - a complicated relationship

First Option Embedding Libraries

All rights reserved Nanuku, Fiji

Page 17: Third party libraries and OSGi - a complicated relationship

BundleManifest

First Option - Embedding Libraries

Same classloader for external libraries and bundle classes.

Page 18: Third party libraries and OSGi - a complicated relationship

Libraries embeddedwithin the bundle

First Option - Embedding Libraries

Bundle Manifest

Page 19: Third party libraries and OSGi - a complicated relationship

Dependency to be embedded with implicit scope ‘compile’

Instruction to embed all dependencies with scope

compile & runtime

First Option - Embedding Libraries

Maven POM snippet

Page 20: Third party libraries and OSGi - a complicated relationship

Apache Felix needs to resolve all dependencies prior to start the bundle.

First Option - Embedding Libraries

Page 21: Third party libraries and OSGi - a complicated relationship

Transitive dependencies are not embedded

automatically!

First Option - Embedding Libraries

Maven Artifact Dependency Tree

Page 22: Third party libraries and OSGi - a complicated relationship

A large number of embedded libraries within your OSGi bundle ...

… can cause an even larger number of unresolveable

packages.

First Option - Embedding Libraries

Page 23: Third party libraries and OSGi - a complicated relationship

Additional dependencies to resolve the missing packages.

Instruction containing a list of packages which should be ignored by Apache Felix.

Instruction to embed transitive dependencies

First Option - Embedding Libraries

Further configuration parameters to adjust the generated manifest.

Page 24: Third party libraries and OSGi - a complicated relationship

First Option - Embedding Libraries

The result has to be that the bundle is deployed with no unresolved packages and activated successfully

Bundle is activated and ready for operation.

Page 25: Third party libraries and OSGi - a complicated relationship

Advantages➢ Easy to archive➢ Usage is encapsulated➢ Same classloader between class-files and library

Disadvantages➢ Usage is limited to bundle➢ No separation of concerns➢ Multiple usage in different bundles increase the memory

consumption and the probability of conflicts when sharing references

First Option - Embedding Libraries

Page 26: Third party libraries and OSGi - a complicated relationship

Second Option Libraries as Bundle

All rights reserved Hollywood, USA

Page 27: Third party libraries and OSGi - a complicated relationship

Transformation or encapsulation of Java libraries to turn them into OSGi bundles

Searching for existing OSGi bundles

End of availability after September 2014 Just kicked off

Successor

Commandline Tool Bundle Plugin

Second Option - Libraries as Bundle

Page 28: Third party libraries and OSGi - a complicated relationship

Second Option - Libraries as Bundle

Advantages➢ Functionality can be shared across multiple bundles➢ Separation of concerns➢ Bundles can be updated independently➢ Class reference conflicts can be avoided, as there is only one

shared source

Disadvantages➢ Most libraries are not available as OSGi bundles➢ Dynamic class resolving via Class.forName() or reflection is

difficult

Page 29: Third party libraries and OSGi - a complicated relationship

OSGi Basics - Bundles vs. Fragments

the bundle where the fragment is attached to

Bundle

FragmentHas its own classloader and lifecycle. Can be referenced by other bundles.

Is part of another Bundle and utilizes its classloader. Extends the imports and exports of the host bundle.

Fragment Manifest

Page 30: Third party libraries and OSGi - a complicated relationship

Hibernate ORM is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database.

Entitiesand DAO

JDBCDriverHibernate

Core Bundle

Consumes

EntityBridge Consumes

Exte

nds

ExtendsOSGi

Fragment

OSGiBundle

Second Option - Libraries as Bundle

Page 31: Third party libraries and OSGi - a complicated relationship

The system bundle is a special bundle that represents the OSGi

framework itself, from within that framework.

Characteristics

➢ Bundle ID 0

➢ It exports packages from the JRE

➢ Only packages which are available in any JVM are provided. All

java* packages for example javax.swing, org.w3c.com etc. are

excluded

➢ Exports the OSGi framework packages such as org.osgi.framework

OSGi Basics - System Bundle

Page 32: Third party libraries and OSGi - a complicated relationship

Apache Axis2 is a Web Services / SOAP / WSDL engine and the successor to the widely used Apache Axis SOAP stack.

System Bundle

Axis 2FragmentExtends

Entitiesand DAO

Consumes

Second Option - Libraries as Bundle

OSGiFragment

OSGiBundle

Page 33: Third party libraries and OSGi - a complicated relationship

Some third party libraries make us of the current thread classloader that definitely runs within another context than the bundle class loader. To allow the third party library to access bundle resources, the current thread classloader has to be replaced for this action.

Dealing with Class Loader Issues

Page 34: Third party libraries and OSGi - a complicated relationship

➢ There is no best practice. Each framework needs its individual solution!

➢ Working with third party libraries is like a box of chocolates - you never know what you're gonna get.

➢ You know it’s working when you see it’s working!

➢ Most frameworks don’t support OSGi or are not properly tested with Apache Felix.

➢ It needs a community with support from Adobe sharing experiences and best practices including the use of third party libraries.

Conclusion

Page 35: Third party libraries and OSGi - a complicated relationship

Your chance for remarks and questions!

All rights reserved Los Angeles, USA

Page 36: Third party libraries and OSGi - a complicated relationship

The End

All rights reserved

Nadi, Fiji

Page 37: Third party libraries and OSGi - a complicated relationship

Presentationhttp://www.eggs.de/connectwebex2014

The AuthorSascha Brinkmann - [email protected]

Sales RepresentativeMartin Brösamle - [email protected]

Get in Touch

Page 38: Third party libraries and OSGi - a complicated relationship

Terms of Use

This work is licensed under a Creative Commons Attribution-NoDerivatives

4.0 International License

All photos copyright © Sascha Brinkmann, all rights reserved.