last night osgi saved my life

39

Upload: osgi-user-group-france

Post on 27-Jun-2015

382 views

Category:

Technology


1 download

DESCRIPTION

This session is a real story , it tells how OSGi saved an heavy project (more thean 5000 days one) and will give you some concrete feedbacks (Design Patterns or Anti Patterns). The project targets a small device (HHP 9900 Dolphin) running Windows Mobile 6.1, it's a very constrained environment : - small process size - 128Mb of RAM available for the whole system - I/O very slow And moreover no recent JVM available in this context, IBM 9 1.4 is the most stable found... Refactoring the previous architecture using eRCP/Spring and much libraries to a plain OSGi one .... For which result: - reduced memory footprint - reduced I/O access and for user experience, a nice & robust application

TRANSCRIPT

Page 1: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Powered by

These slides are powered by Open Source softwares :

Debian GNU Linux

Beamer LaTeX mode

LaTeX

Emacs

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 2: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Course menu...

1 Context

2 Last night OSGi saved my application

3 Back to the Future

4 Lessons learned

5 Q&A

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 3: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Summary I

1 Contextthe applicationOriginal architecture

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 4: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Business context

packets delivery,

tracking of each parcel shipped,

reducing

costs , while optimizing employees delivery schedule,customers constesting with improved parcels tracking,

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 5: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Application features

1 packets tracking,

2 scanning packets with Doplhin's barcodes reader,

3 Geolocation with GPS Dolphin's module,

4 GPRS

5 synchronization with central (up/down streams),

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 6: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Business constraints

The application must ensure to manage the following constraints :

quick to optimize productivity of employees (handling scanningof numerous packets in a small time),

robust, the only application visible to end users on thehandheld device (a kiosk shadowing the Operating System andall other applications)...

network aware while synchronizing data from the master nodeand while sending data to this node.

in fact this application is part from a larger group ofapplications and synchronization between layers is one the keyobjectives.

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 7: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Technical constraints

Customers bought the handheld devices (7000 ! ! !) :

1 HHP Dolphin 9900,

2 powered by a Windows 6.1 Mobile Edition,

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 8: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Technical constraints - II

Digression about Windows Mobile :

not clearly designed to power Java applications,

can't manage (use as an addresses space) more than 128Mb ofRAM,

can't manage properly processus heavier than 32Mb...

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 9: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Initial architecture : overview

Figure: Initial architecture

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 10: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Initial architecture in a few numbers

100 , as the number of bundles on the client side,

200, as the number of bundles on the server side,

100000 lines of code,

40 as the number of libraries embedded on client side (allSpring stu� and more)

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 11: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Development infrastructure

1 development on Windows under Eclipse generating JDK 1.5bytecode,

2 retro translation of this bytecode for the handheld device partfrom the project to be compatible with JRE 1.4.

part from the whole project code is common to handheld andstation ...for these 2 parts, di�erent constraints (hardware, OS, JRE ..)

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 12: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

Initial architecture : summary

Using such architecture on the HHP device resulted in :

heavyweight application,

failures in di�erent application's features (memory intensiveones inducing GC errors) ,

modularity concerns because of the number of runtimedependencies,

OSGi enrolled in the long list from technologies but notimplemented in the good way...

Spring-DM entropy resulted in a bootsrapping phase for theapplication not fully mastered (numerous hacks in this portionof code).

Problems with the customers.....

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 13: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

the applicationOriginal architecture

And Zorro comes to the rescue

Next section explains how OSGi saved the application....

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 14: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Re-engineering the applicationOSGi & shells

Summary I

2 Last night OSGi saved my applicationRe-engineering the applicationOSGi & shells

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 15: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Re-engineering the applicationOSGi & shells

Strategy

Key points , strategy used to redesign the application :

mastering dependencies & reducing volume of byte code loaded

reduce I/O as much as possible,

use as much as possible OSGi features,

don't rely on isolated technologies but use well known &standard technologies

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 16: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Re-engineering the applicationOSGi & shells

Strategy in action

Main steps for this re-engineering :

1 cut Spring dependencies (done - success),

2 cut eRCP dependencies (and drop JFace from code) (doneeasily),

3 master code injection (done - success but temporary solution),

4 introduce Dependencies Service (done in certain infrastructurebundles),

5 refactor applications to use standard OSGi services everywhere(not implemented yet)

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 17: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Re-engineering the applicationOSGi & shells

New architecture used

Fully based on OSGi...Uses major OSGi services..

Figure: Current architecture

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 18: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Re-engineering the applicationOSGi & shells

New architecture used...

Major OSGi services used into the application

Log Service,

Con�gAdmin Service,

Service Component References aka Declarative Services,

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 19: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Re-engineering the applicationOSGi & shells

First results

Fact Before AfterScanning several packages in a row failure after 200 scans no problem after 800 scans..Memory footprint after bootstrap 70Mb 11MbStartup time for the application 2 minutes more than 1 minute

Bootstrap hack with thread before stating injection fully controlled

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 20: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Re-engineering the applicationOSGi & shells

One shell to rule them all..

Surf-Ng is developed on Windows and runs on the handhelddevice...

Equinox is used on the Windows machines inside Eclipse,

Felix runs the application on the handheld device

Equinox is quite heavyweight,using Felix and Equinox is a good way to conform to plainstandard OSGi

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 21: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Re-engineering the applicationOSGi & shells

Testing inside OSGi runtimes

Testing inside OSGi context ? one re�ex : use commands..

of course it's the natural way

but how to deal with 2 shells ?

no standard API for commands yet (until the upcoming r4.3),double the number of classes with the same feature developedinto 2 contexts ?testing only made into the Felix context for major bundles...

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 22: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Summary I

3 Back to the Future

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 23: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

What's next Doctor ?

Next releases will add :

GPS, localization of the current employee

relies on low level API as o�ered by HHP, same case asbarcode reader handling in the current architecture..a bundle will isolate handling of the dialog with the .dll usingJNI or JNA.

GPRS, for larger bandwidth

same implication in the architecture (no problem)improve customers relationship enabling Colipost to send newcommands to employees in a real time mode

UPnP maybe...

Use Service Component References in the whole application.

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 24: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

UPnP usage

What about UPnp in this business context ?

devices have to be deployed into sub centralized environments(local agencies),

how to �nd the 2 special PCs storing con�gurations to be usedby the application deployed on the devices ?

�rst attempts made with JSLP

JSLP does not work into the J9 custom JVM...JSLP is not maintained anymore and provides alpha stagesreleases

OSGi provides integrated UPnp services

UPnp uses the same kind of approach than SLP

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 25: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Generalize Declarative Services usage

Declarative Services is used but :

not used in all bundles (too much to refactor the wholebundles set),

reserved to technical infrastructure bundles,

e�ciency and impact on architecture highlighted now

remove the current �aw of the architecture with the bootsequence being quite fragileenable a better OSGi shell independance while removing thedependencies related to run levels con�guration.

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 26: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Summary I

4 Lessons learned

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 27: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 1 :Use OSGi native injection

Dependencies Service turns out to be :

powerful (dynamic and not static as Spring Core),

easy to use (fun with BndTools),

much more e�cient than Spring on an embedded context

XML verbosity (impact on I/O),Objects tree managed,does not grab hundred of unused dependencies ...

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 28: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 2 : avoid using PDE to develop

not suited for OSGi development (mainly oriented to oldEclipse plugin architecture),

huge refactoring to migrate all MANIFEST.MF �les to properOSGi style (easy but boring with BndTools when you have 300plugins to migrate),

use BndTools instead ...

fast,elegant,powerful (thanks to bnd & Peter ! !)nice Eclipse integration

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 29: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 3 : modularity has a cost

Di�erent technical concerns are not evaluated as they should bewhen dealing with OSGi. XML serialization, Web Servicesconsuming or scheduler are good samples...

all raise problems of Class loading & instantiations throughdi�erent bundles

small infrastructure solution required...

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 30: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 3 : continued

Don't use the classic whiteboard pattern,I avoid to create polling objects when possible,I like the fact of forcing bundles (& developers) to export partfrom their objects

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 31: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 4 : modularity is the key

OSGi services do a great job when implementations may change...

1 we faced di�erent problems with libraries incompatible withour Virtual Machine

2 having code relying on special implementations would havebeen a disaster , with OSGi who cares ?

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 32: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 5 : when hardware & software matters

this item is not OSGi centric but :

beware of the JVM to be used,

beware of side e�ects for hardware which does not provide PCemulator,

use documented & open systems whenever you can ..

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 33: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 6 : handling tests

Many bundles are tested using Command classes

it's the most natural way to test code into an OSGi runtime,

very easy to code and deploy (a few lines of code only required)

no standard way to test into our 2 di�erent runtimes until theupcoming OSGi r4.3 release ! ! !

Equinox as integrated into Eclipse on development machines,Felix on Dolphin device, Equinox is too heavy for ourenvironment..

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 34: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 7 : Declarative Services e�ciency

It's one of the major surprises...

quite no impact on I/O and global performance,

far more e�cient than Spring XML injection,

no coupling with annotation during runtime phase, onlyconstraint is to have a JDK 1.6 inside Eclipse..

more powerful than Spring injection with the dynamic aspect(Spring does static injection ..),

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 35: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 8 : Debuging OSGi con�icts

What can you do when your bundles seem to deploy but theapplication does not work ?

use the Felix Web Console bundle,

this bundle requires to embed a small Jetty server to deliverthis webapp,

not usable on any environment (we don't have a JRE 1.5+with a complete NIO stack on our J9 JVM)

any Linux/Windows machine may o�er the infrastructure todeliver this kind of diagnostics .

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 36: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 9 : Beware of evidence

This item is not OSGi speci�c but beware as any Java veteranprogrammer on such context (such hardware) all that you knowmay be false :

standard classes may not be included in your JVM,

standard algorithms may be unsuitable for your context,

reusing general libraries may be the worth choice..

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 37: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Lesson 10 : Modularity is the key - revisited

A good OSGi usage enables applications to bene�t of the followingaspects :

no need of complex infrastructure (Spring D-M),

high degree of freedom o�ered by contexts where developpersmaster the underlying architecture (no hidden monster),

extreme e�ciency ,

very quick team adoption,

best architectural approach , please refer to B.Meyer objectsintroduction , how to design a microcosm without deepknowledge of the relations between entities (what they o�er &what they require).

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 38: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Summary I

5 Q&A

J.MOLIÈRE - [email protected] Last night OSGi saved my life

Page 39: Last night OSGi saved my life

ContextLast night OSGi saved my application

Back to the FutureLessons learned

Q&A

Questions ?

It's up to you ..Thanks for your attention..Apologize for my bad english spoken...

J.MOLIÈRE - [email protected] Last night OSGi saved my life