10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
Upcoming SlideShare
Loading in...5
×
 

10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere

on

  • 3,953 views

This presentation aims to show common pitfalls in OSGi architecture and development and how to avoid them. It involves concrete use cases and their solutions. Antipatterns, bad designs , bad tooling ...

This presentation aims to show common pitfalls in OSGi architecture and development and how to avoid them. It involves concrete use cases and their solutions. Antipatterns, bad designs , bad tooling will be presented during this session... This session is user oriented and aimed to give concrete feedbacks and good practices...

Statistics

Views

Total Views
3,953
Views on SlideShare
3,953
Embed Views
0

Actions

Likes
3
Downloads
130
Comments
2

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • I emphasize one thing: OSGi should be transparent to any business application developer. ---------------------------------------------------------------------------------------------------------------------------- Jeff McAffer : Don't program OSGi -- In my OSGi talks and training courses I like to start off saying 'The best practice for programming OSGi is to not use OSGi'. What I mean by that is, write POJOs and use dependency injection style. (http://java.dzone.com/articles/using-osgi-equinox-effectively). ---------------------------------------------------------------------------------------------------------------------------- Peter Kriens : Anyway, application developers should never see OSGi APIs and tools should take care of the packaging. I use Declarative Services with annotations and for app code rarely have to use OSGi API or write XML. OSGi APIs are reserved for middleware developers, and for them I think it is a wet dream API as it allows them to discover componenents, provide system extensions, and in general make the life of application developers easier without breaking modularity. -- see -- http://www.theserverside.com/discussions/thread.tss?thread_id=62699
    Are you sure you want to
    Your message goes here
    Processing…
  • Hi,
    As software architect, learning is continous.

    Mentor/J has done a huge work of reengineering with OSGi foundations....

    This presentation is like advertising for a set of tools than anything else. Not very convincing. The author is still very vague.

    I emphasize one thing: OSGi should be transparent to any business application developer.

    Anyway, let’s see how to do OSGi in the good manner.

    ....................................................................
    Item 1 - Start levels
    ....................................................................

    - First, read carefully Chapter 11 - Launching OSGi using start levels
    (OSGi in Depth : http://www.manning.com/alves/)

    - Second, if you haven’t understand, then ask your Mentor (http://stackoverflow.com/questions/7462259/how-is-the-osgi-bundle-start-level-defined)
    ’It isn’t practical to use FileInstall in a production application. I recommend you use a more stable and repeatable mechanism for installing bundles, e.g. by reading a configuration file containing a list of bundle locations with start levels. (Even better of course: stop relying on start levels altogether -- the fact that you have to use them usually indicates that you have done something wrong). – Neil Bartlett Sep 18 ’11 at 19:35’

    - Third, still not understand - read this :
    The framework uses settings known as Start Levels to organize the startup of the bundles. The framework exists at a specified level and the bundles are assigned to start at a specific level. The framework begins at level 0 with no bundle started. Next, the Framework will move to start level 1. All bundles assigned to start level 1 will then be started in some order. The framework will progress through each of the levels until it reaches the designated framework start level. The designated framework start level is determined by the osgi.startLevel property. The bundles that are started during the start level processing are those which have had a start level specifically assigned, and which have been marked to persistently start.

    ....................................................................
    Item 2 - Bad logging usage
    ....................................................................

    - First, read (http://blog.kornr.net/index.php/2008/12/09/understanding-the-osgi-logging-service) to understand what is OSGi Log Service.
    --> the logging service is often seen as a unusable toy-like API.

    - Second, use the out-of-the box Equinox ExtendedLogService (http://eclipsesource.com/blogs/2009/03/24/tip-osgi-log-service/)

    ....................................................................
    Item 3 - Required-Bundle
    ....................................................................

    Read carefully : 5.5 Working with dependencies (http://static.springsource.com/projects/dm-server/1.0.x/programmer-guide/html/ch05s05.html)

    Then you have two choices : use Import-Library or Import-Bundle
    Yes, Business Enterprise Applications are not Hello Words examples.

    If you don’t know how to design Enterprise Applications, read the free chapter 6 - OSGi and Spring DM for enterprise applications (http://manning.com/cogoluegnes/samplechapter6.pdf)

    ....................................................................
    Item 4 - Versioning
    ....................................................................
    - It’s an old topic that every OSGi novice already practiced.
    - http://www.osgi.org/blog/2009/12/versions.html

    ....................................................................
    Item 5 - Spring-DM usage
    ....................................................................
    - This is an advanced topic. Before, you must know a minimum of Spring-DM.

    - Regarding OSGi Declarative Service, contrary as you indicated in your book at the end of page 73, the XML files are in the OSGI-INF directory and not in OSGI-OPT (http://www.amazon. fr/OSGi-Conception-dapplications-modulaires-Java/dp/2212133286).

    - How did you do to transform the XML Spring-DM injection files to XML Declarative Services injection files? (http://romjethoughts.blogspot.fr/2010/11/osgi-declarative-services.html)

    - What Declarative Services implementation have you used? (http://romjethoughts.blogspot.fr/2010/11/osgi-declarative-services.html)

    ....................................................................
    Item 6 - Not using Bnd ?
    ....................................................................
    In OSGi land, there are lots of options...PDE, Maven, BND...
    Choice of tooling will be like your choice of religion...Remember emacs vs. vi
    Read : OSGi for Eclipse Developers (http://www.eclipsecon.org/2009/sessions?id=266)

    ....................................................................
    Item 7 - Not using Web Console ?
    ....................................................................
    In OSGi land, there are lots of options....See item 6.
    Explore Eclipse’s OSGi console : http://www.ibm.com/developerworks/library/os-ecl-osgiconsole/index.html
    http://www.knopflerfish.org/releases/3.2.0/docs/bundledoc/httpconsole/index.html

    ....................................................................
    Item 8 - Are you really using modules ?
    ....................................................................
    A modular application is, in essence, one that’s divided into several pieces with the connections between the pieces being controlled and well defined.
    If you don’t know how to design Enterprise Applications, read the free chapter 6 - OSGi and Spring DM for enterprise applications (http://manning.com/cogoluegnes/samplechapter6.pdf)

    ....................................................................
    Item 9 - Are you really using modules ?
    ....................................................................
    Same as item 8. Don’t repeat your self.
    Designing OSGi enterprise applications isn’t so different from developing “standard” enterprise applications: OSGi people don’t pretend that the world was waiting for them in order to write modular applications. Nevertheless, anyone can learn from the strict modular approach of OSGi [p. 180].

    ....................................................................
    Item 10 - Still not understands versioning ?
    ....................................................................
    Same as item 4. Don’t repeat your self.
    Where are the clues.

    ....................................................................
    Item Last - My bonus
    ....................................................................
    Before reengineering applications you :
    - Need more OSGi MasterClass (to go beyond Declarative Services for example and to learn more on Blueprint Services (standardization of Spring-DM))
    - Like SPRING, ’Static, single-version module resolution is usually sufficient — Most applications do not need to add or remove modules dynamically at run time, nor do they need to use multiple versions of the same module simultaneously’ (The future of Java Modularity - http://cr.openjdk.java.net/~mr/jigsaw/notes/jigsaw-big-picture-01)
    - Need more practice in Java IRM tools to be able to measure memory footprint (see my comments at http://www.slideshare.net/mentorj/osgi-con).
    - FUD against SPRING may lead to very bad design decisions.
    ....................................................................

    Happy reengineering with OSGi foundations....
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere 10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere Presentation Transcript

  • PRESENTATION TITLEMOLIERE Jerome1O Things to know you are doing OSGi in the wrong wayMentor/JAugust 2011 OSGi Alliance Marketing © 2008-2010 . 1 Page COPYRIGHT © 2008-2011 OSGi Alliance. All Rights Reserved All Rights Reserved
  • Speakers bio• Reach me at : • jerome@javaxpert.com• Works as freelance/writer for Mentor/J• Architect/Trainer around • Java/J2EE/OSGi technologies• SCJP2 certified• Jboss architect certified (2003)• Works with Java since 1996...
  • Introduction• This talk looks to different problems • Design • Development • Deboging• Brings solutions• Catalog of something like Anti Patterns – Real problems raised in real projects• Using a Pattern like layout • Problem • Solution
  • Item 1 : start levelsosgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.core.jobs@4:start,org.eclipse.equinox.registry@4:start,org.eclipse.core.runtime.compatibility.registry,org.eclipse.equinox.preferences@4,org.eclipse.core.contenttype@4,org.eclipse.core.runtime@4:start,org.eclipse.update.configurator@3:start,
  • Item1 : start levelsIntroduction• Your application starts using start level facility of your shell : • Introducing new bundles is a nightmare • Debuging is tedious • Once again you must fully master all runtime dependencies of your application....• This solution is weak • No robustness • Like sitting on a bomb …
  • Item1 : start levelsSolution• Using any provisioning mechanism • Felix File-Install for simple use cases/ embedded contexts • Apache Ace for larger infrastructures• Delegate dependencies assembly to Declarative Services• Mix start level with File Install is a very efficient solution – Just put this single bundle in your start level configuration – Configure bundles start with File Install
  • Item 2:bad logging usageIntroduction• Context : • Embedding Log4J or Slf4J with Logback • Logging 10 to 20 messages per method call• Effects : • Impact on performance even with isDebugEnabled() calls • Huge log files • ==> I/O may be very inefficient on mobile devices • Who never encountered filesystem full in production ?
  • Item2 :bad logging usageSolution• Use LogService • Implement a LogReader and isolate it into a separate bundle • Activate the bundle into your shell when needed• Use EventService • To provide statistics • user request handled • Data saved • File printed • …. • Consume these events into another bundle• Advantage • Flexible/performance
  • Item3:Require-BundleIntroduction• Require-Bundle should not be supported• Very few use-cases suited to such keyword• Goes against the SOA approach • No dynamism • No way to change the implementation of the required service • Very static way to declare dependencies • You are tied to one specific version of this bundle...• Seems to be a hack regarding the whole approach
  • Item3:Require-BundleSolution• Import-Package is your friend...• Declarative Services enables a very flexible and dynamic way to inject dependencies at runtime• Please think in a services oriented way...• Dont forget dynamism – Just diamonds are for ever !!
  • Item 4:VersioningIntroduction• Import-Package specifying : • no version clauses • Or coupling against trunk versions (Maven side effects)• Implies : • What works now wont work in the next weeks • Did you test your application with the new behaviour of the foobaz() method ? • How to deal with methods removal while APIs change ? • How to do unitary & integration testing in such context? • Beware of red buttons and cloudy weather in your Hudson reports …
  • Item 4:VersioningSolution• Use strict versioning • Prefer ranges to strict version number : e.g [1.0,1.1) rather than 1.0 • Use and understand OSGi RFC proposal • Version is a 4 digits string • Major.minor.sub.discriminant • 1.0.0.1 • Enables you (an engine!!!) to really compare versions • Far from stupid Maven strings • What can you do (as an engine) with a 1.2.5.FINAL version number ? • No natural (and easy to implement) order relationship
  • Item 5:Spring-DM usageIntroduction• Spring-Dm enables to do OSGi like programming with POJOs • Relies on ApplicationContext & BeanFactory standard Spring patterns • Code showing OSGi services as Spring beans • May use XML / annotation• Implies • No easy way to do natural OSGi stuff (how to get a BundleContext instance?) • Application bootstrapping becomes tricky • Because of threads launched by Spring D-M • Spring XML has a very strong impact • I/O • Memory footprint of the beans context
  • Item 5 : Spring D-MSolution• Use standard OSGi facilities & patterns • Declarative Services • Provisioning • Library wrapping  Implies :  Dont just run an OSGi shell but use a design well suited to OSGi SOA approach....
  • Item 6:Not using bnd ?Introduction• Developement made using any mechanism (PDE on Eclipse) without control of the MANIFEST.MF file ? • Application is out of control • Maintenance will be very hard • Beware of shortcuts used by some developers (COPY/PASTE our best enemy)
  • Item 6:Not using bnd ?Solution• Use it !!! • Integration with Maven/ANT/Eclipse/intelliJ Idea • Directly or through a layer like the excellent BndTools for Eclipse• Why ? • The only tool reflecting the OSGi norm spirit • Provides quick & standard answer to the most common problems
  • Item 6 : Not using bnd ?Bndtools runtime view
  • Item 6 : Not using bnd ?BndTools components view
  • Item 7:Not using Web-Console ?Introduction• How to diagnose weird problems at runtime ? • Unmet dependencies • Receivers listening on bad topics (typo in the name spelling)• Logging ? • Performance impact • What to do with many traces not appearing (because of code not invoked) ? • Debuging may be useful when possible.....
  • Item 7:Not using Web-Console ?Solution• Use it !!!• How ? • Add a few bundles • Type in an url into your web browser and thats it !!!• Moreover... • Its an open system (plugins like architecture) • Its free • Very low footprint and weak requirements • You get an easy way to monitor your system • CPU • memory• But • Beware on mobile devices , the NIO stack used by Jetty (default Http server ) may not be available on your JVM so for such contexts please refer to the Http server from makewave.
  • Item 7 : Web-Consolebundles list & states
  • Item 7 : Web-Consoledisplaying components
  • Item 7 : Web-Consolegetting system info
  • Item 8:Are you really using modules ?introduction• Do you separate API bundles from implementation ones ?• Can you pick off any implementation bundle and put another one in place without breaking the whole system ? • Major benefit from the SOA approach • Enables early testing and suits well with Agile methods • Mocking is so easy in the OSGi world...
  • Item 8:Are you really using modules ?Solution• Isolate API (interfaces) from implementation• Inject dependency over the API with any implementation• As usual Declarative Services is your friend – Free – Powerful – dynamic
  • Item 9:Are you really usingmodules(2)• Can you put your bundle into another shell without pulling the whole Java constellation of libraries as dependencies ? • Too much dependencies implies a very particular context • Beware of the never ending stories • A requires B requires C and D , C requires F and D requires..... • Headache warranty • May be sign for not reusable components
  • Item 9 : Are you really usingmodules(2) ?• Unproper control over dependencies is the heart of this problem• Different solutions • Rewrite some routines • Wrap some portions of libraries into dedicated bundles • All theses solutions are related to the design phase
  • Item 10 : Still dont understandversioning ?Problem :You think that 2.5.6.PRE-FINAL is a nice version number for your component or 3.1.2.20120223 is correct....
  • Item 10 : Still Dont understandversioning ?Solution Read the excellent doc : semantic versioning Use the numbering scheme as purposed by OSGi Alliance : Major.minor.subminor.modifier All four fields as plain numbers....Benefits :Natural ordering is so easy ….Or use part of this scheme :Major.minor.subminor is nice in practice ….
  • Bonus Item :How do you solve yourproblems ?• Alone ? • Can be sufficient for most code related problems...• With newsgroups/forums ? • Pragmatic way but not well suited for design/philosphical problems• Best solution : • Have some OSGi lunches please refer to Peter Kriens blog • Share a beer/glass of wine/ best french fries in the world (only in Lansargues – Herault - France)
  • Thanks !!!!Any question at this point ? It s up to you now...Apologize for my poor english spoken...