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
1. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
Q&A
Powered by
These slides are powered by Open Source softwares :
Debian GNU Linux
Beamer LaTeX mode
LaTeX
Emacs
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
2. Context
Last night OSGi saved my application
Back to the Future
Lessons 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 - jerome@javaxpert.com Last night OSGi saved my life
3. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
Q&A
Summary I
1 Context
the application
Original architecture
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
4. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
Q&A
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 - jerome@javaxpert.com Last night OSGi saved my life
5. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
Q&A
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 - jerome@javaxpert.com Last night OSGi saved my life
6. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
Q&A
Business constraints
The application must ensure to manage the following constraints :
quick to optimize productivity of employees (handling scanning
of numerous packets in a small time),
robust, the only application visible to end users on the
handheld device (a kiosk shadowing the Operating System and
all other applications)...
network aware while synchronizing data from the master node
and while sending data to this node.
in fact this application is part from a larger group of
applications and synchronization between layers is one the key
objectives.
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
7. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
Q&A
Technical constraints
Customers bought the handheld devices (7000 ! ! !) :
1 HHP Dolphin 9900,
2 powered by a Windows 6.1 Mobile Edition,
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
8. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
Q&A
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 of
RAM,
can't manage properly processus heavier than 32Mb...
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
9. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
Q&A
Initial architecture : overview
Figure: Initial architecture
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
10. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
Q&A
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 (all
Spring stu and more)
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
11. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
QA
Development infrastructure
1 development on Windows under Eclipse generating JDK 1.5
bytecode,
2 retro translation of this bytecode for the handheld device part
from the project to be compatible with JRE 1.4.
part from the whole project code is common to handheld and
station ...
for these 2 parts, dierent constraints (hardware, OS, JRE ..)
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
12. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
QA
Initial architecture : summary
Using such architecture on the HHP device resulted in :
heavyweight application,
failures in dierent application's features (memory intensive
ones inducing GC errors) ,
modularity concerns because of the number of runtime
dependencies,
OSGi enrolled in the long list from technologies but not
implemented in the good way...
Spring-DM entropy resulted in a bootsrapping phase for the
application not fully mastered (numerous hacks in this portion
of code).
Problems with the customers.....
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
13. Context
Last night OSGi saved my application the application
Back to the Future Original architecture
Lessons learned
QA
And Zorro comes to the rescue
Next section explains how OSGi saved the application....
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
14. Context
Last night OSGi saved my application Re-engineering the application
Back to the Future OSGi shells
Lessons learned
QA
Summary I
2 Last night OSGi saved my application
Re-engineering the application
OSGi shells
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
15. Context
Last night OSGi saved my application Re-engineering the application
Back to the Future OSGi shells
Lessons learned
QA
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 - jerome@javaxpert.com Last night OSGi saved my life
16. Context
Last night OSGi saved my application Re-engineering the application
Back to the Future OSGi shells
Lessons learned
QA
Strategy in action
Main steps for this re-engineering :
1 cut Spring dependencies (done - success),
2 cut eRCP dependencies (and drop JFace from code) (done
easily),
3 master code injection (done - success but temporary solution),
4 introduce Dependencies Service (done in certain infrastructure
bundles),
5 refactor applications to use standard OSGi services everywhere
(not implemented yet)
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
17. Context
Last night OSGi saved my application Re-engineering the application
Back to the Future OSGi shells
Lessons learned
QA
New architecture used
Fully based on OSGi...Uses major OSGi services..
Figure: Current architecture
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
18. Context
Last night OSGi saved my application Re-engineering the application
Back to the Future OSGi shells
Lessons learned
QA
New architecture used...
Major OSGi services used into the application
Log Service,
CongAdmin Service,
Service Component References aka Declarative Services,
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
19. Context
Last night OSGi saved my application Re-engineering the application
Back to the Future OSGi shells
Lessons learned
QA
First results
Fact Before After
Scanning several packages in a row failure after 200 scans no problem after 800 scans.
Memory footprint after bootstrap 70Mb 11Mb
Startup time for the application 2 minutes more than 1 minute
Bootstrap hack with thread before stating injection fully controlled
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
20. Context
Last night OSGi saved my application Re-engineering the application
Back to the Future OSGi shells
Lessons learned
QA
One shell to rule them all..
Surf-Ng is developed on Windows and runs on the handheld
device...
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 plain
standard OSGi
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
21. Context
Last night OSGi saved my application Re-engineering the application
Back to the Future OSGi shells
Lessons learned
QA
Testing inside OSGi runtimes
Testing inside OSGi context ? one reex : 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 developed
into 2 contexts ?
testing only made into the Felix context for major bundles...
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
22. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Summary I
3 Back to the Future
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
23. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
What's next Doctor ?
Next releases will add :
GPS, localization of the current employee
relies on low level API as oered by HHP, same case as
barcode reader handling in the current architecture..
a bundle will isolate handling of the dialog with the .dll using
JNI or JNA.
GPRS, for larger bandwidth
same implication in the architecture (no problem)
improve customers relationship enabling Colipost to send new
commands to employees in a real time mode
UPnP maybe...
Use Service Component References in the whole application.
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
24. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
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 congurations to be used
by 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 stages
releases
OSGi provides integrated UPnp services
UPnp uses the same kind of approach than SLP
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
25. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Generalize Declarative Services usage
Declarative Services is used but :
not used in all bundles (too much to refactor the whole
bundles set),
reserved to technical infrastructure bundles,
eciency and impact on architecture highlighted now
remove the current aw of the architecture with the boot
sequence being quite fragile
enable a better OSGi shell independance while removing the
dependencies related to run levels conguration.
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
26. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Summary I
4 Lessons learned
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
27. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
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 ecient 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 - jerome@javaxpert.com Last night OSGi saved my life
28. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Lesson 2 : avoid using PDE to develop
not suited for OSGi development (mainly oriented to old
Eclipse plugin architecture),
huge refactoring to migrate all MANIFEST.MF les to proper
OSGi style (easy but boring with BndTools when you have 300
plugins to migrate),
use BndTools instead ...
fast,
elegant,
powerful (thanks to bnd Peter ! !)
nice Eclipse integration
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
29. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Lesson 3 : modularity has a cost
Dierent technical concerns are not evaluated as they should be
when dealing with OSGi. XML serialization, Web Services
consuming or scheduler are good samples...
all raise problems of Class loading instantiations through
dierent bundles
small infrastructure solution required...
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
30. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
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 part
from their objects
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
31. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Lesson 4 : modularity is the key
OSGi services do a great job when implementations may change...
1 we faced dierent problems with libraries incompatible with
our Virtual Machine
2 having code relying on special implementations would have
been a disaster , with OSGi who cares ?
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
32. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Lesson 5 : when hardware software matters
this item is not OSGi centric but :
beware of the JVM to be used,
beware of side eects for hardware which does not provide PC
emulator,
use documented open systems whenever you can ..
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
33. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
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 dierent runtimes until the
upcoming OSGi r4.3 release ! ! !
Equinox as integrated into Eclipse on development machines,
Felix on Dolphin device, Equinox is too heavy for our
environment..
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
34. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Lesson 7 : Declarative Services eciency
It's one of the major surprises...
quite no impact on I/O and global performance,
far more ecient than Spring XML injection,
no coupling with annotation during runtime phase, only
constraint 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 - jerome@javaxpert.com Last night OSGi saved my life
35. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Lesson 8 : Debuging OSGi conicts
What can you do when your bundles seem to deploy but the
application does not work ?
use the Felix Web Console bundle,
this bundle requires to embed a small Jetty server to deliver
this 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 oer the infrastructure to
deliver this kind of diagnostics .
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
36. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Lesson 9 : Beware of evidence
This item is not OSGi specic but beware as any Java veteran
programmer on such context (such hardware) all that you know
may 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 - jerome@javaxpert.com Last night OSGi saved my life
37. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Lesson 10 : Modularity is the key - revisited
A good OSGi usage enables applications to benet of the following
aspects :
no need of complex infrastructure (Spring D-M),
high degree of freedom oered by contexts where developpers
master the underlying architecture (no hidden monster),
extreme eciency ,
very quick team adoption,
best architectural approach , please refer to B.Meyer objects
introduction , how to design a microcosm without deep
knowledge of the relations between entities (what they oer
what they require).
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
38. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Summary I
5 QA
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life
39. Context
Last night OSGi saved my application
Back to the Future
Lessons learned
QA
Questions ?
It's up to you ..
Thanks for your attention..
Apologize for my bad english spoken...
J.MOLIÈRE - jerome@javaxpert.com Last night OSGi saved my life