Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Maximise the Power of OSGi - Carsten Ziegeler & David Bosschaert

522 views

Published on

OSGi Community Event 2015

This talk outlines the ease of use of OSGi in application code and shows how to master development tasks by using the right APIs and tools. Learn about the latest in component development, asynchronous processing, configuration management and deploying your application code in larger modules, so-called subsystems. A subsystem allows to package a set of bundles and configurations. The subsystem can run isolated from other bundles or other applications.</p>
Learn how to leverage the latest OSGi tech for your own projects. All of the functionality discussed is available as open source.

Published in: Technology
  • Be the first to comment

Maximise the Power of OSGi - Carsten Ziegeler & David Bosschaert

  1. 1. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Maximize the power of OSGi Carsten Ziegeler | David Bosschaert | Adobe R&D
  2. 2. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. About David Bosschaert davidb@apache.org @davidbosschaert •  R&D Adobe Ireland •  Co-chair OSGi Enterprise Expert Group •  ISO/IEC JTC1 SC38 Cloud Computing committee member for Ireland •  Apache Felix, Aries PMC member and committer •  … other opensource projects •  Cloud and embedded computing enthusiast 2
  3. 3. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. About Carsten Ziegeler cziegeler@apache.org @cziegeler •  RnD Adobe Research Switzerland •  Member of the Apache Software Foundation •  VP of Apache Felix and Apache Sling •  OSGi Core Platform, OSGi Enterprise, OSGi IoT Expert Groups •  Member on the board of the OSGi Alliance •  Book / article author, technical reviewer, conference speaker 3
  4. 4. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Today’s contents §  Declarative Services §  with Configuration Admin §  HTTP Whiteboard §  Coordinator §  Subsystems 4 Image by Joadl: Lyme_Regis_harbour_02b on wikipedia
  5. 5. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Declarative Services
  6. 6. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Component Container Interaction 6 OSGi Service Registry Declarative Services Blueprint iPojo, Dependency Manager, …. Framework API
  7. 7. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 7 No POJOs Too slow Dynamics not manageable No dependency injection Not suitable forthe enterprise Notooling OSGi Preconceptions ✔?!
  8. 8. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. The Next Big Thing 8
  9. 9. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Building Blocks §  Components §  Services §  Module aka Bundle 9
  10. 10. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Game Design 10 Game Servlet GET POST HTML Game Controller Game Bundle
  11. 11. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Game Design - API 11 public enum Level { EASY, MEDIUM, HARD } public interface GameController { Game startGame(final String name, final Level level); int nextGuess(final Game status, final int guess); int getMax(final Level level); } public class Game { // game status }
  12. 12. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Implementation 12 @Component public class GameControllerImpl implements GameController { ... import org.osgi.service.component.annotations.Component;
  13. 13. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Configuration 13 public @interface Config { int easy_max() default 10; int medium_max() default 50; int hard_max() default 100; } Range from 1 to a configurable max value per level Configuration (Dictionary) easy.max = "8" medium.max = 40L
  14. 14. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 14 private Config configuration; @Activate protected void activate(final Config config) { this.configuration = config; } public @interface Config { int easy_max() default 10; int medium_max() default 50; int hard_max() default 100; }
  15. 15. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 15 public int getMax(final Level level) { int max = 0; switch (level) { case EASY : max = configuration.easy_max(); break; case MEDIUM : max = configuration.medium_max(); break; case HARD : max = configuration.hard_max(); break; } return max; }
  16. 16. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Game Design 16 Game Servlet GET POST HTML Game Controller Game Bundle
  17. 17. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Web? 17 @Component( service = Servlet.class , property="osgi.http.whiteboard.servlet.pattern=/game") public class GameServlet extends HttpServlet { @Reference private GameController controller;
  18. 18. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Unary References 18 @Reference private GameController controller; @Reference(cardinality=ReferenceCardinality.OPTIONAL policy=ReferencePolicy.DYNAMIC) private volatile GameStatistics stats;
  19. 19. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Multiple References 19 @Reference(cardinality=ReferenceCardinality.MULTIPLE) private volatile List<Highscore> highscores; @Reference private final Set<Highscore> highscores = new ConcurrentSkipListSet<Highscore>();
  20. 20. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Game Design 20 Game Servlet GET POST HTML Game Controller Game Bundle
  21. 21. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Management 21
  22. 22. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Component Management 22
  23. 23. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Metatype I 23 @ObjectClassDefinition( name = "Game Configuration", description = "The configuration for the guessing game.") public @interface Config { @AttributeDefinition(name="Easy", description="Maximum value for easy") int easy_max() default 10;
  24. 24. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Metatype II 24 @Component @Designate( ocd = Config.class ) public class GameControllerImpl implements GameController {
  25. 25. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Declarative Services §  Easy too use §  Pojos §  DI with handling dynamics §  Integrates with Configuration Admin and Metatype 25
  26. 26. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Try it out TODAY §  Tooling *is* available §  Official open source implementations available 26
  27. 27. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. OSGi Coordinator
  28. 28. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. OSGi Coordinator §  Sometimes you want to group things together §  set multiple configuration values -> afterwards apply §  multiple database access calls -> then close the connection §  perform related operations -> then flush the cache §  Combining these is better §  Use the OSGi Coordinator Service (Chapter 130 of OSGi Enterprise specs) 28 “Red arrows in apollo formation cotswoldairshow 2010 arp” by Arpingstone from wikipedia.org
  29. 29. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Coordinator Service §  Coordination Initiator §  Start a coordination implicit/explicit §  Knows the ‘higher level’ task §  Normally ends the coordination too §  Participants §  don’t have the bigger picture §  but can add themselves as ‘interested’ §  and get notified on completion or failure §  Both the initiator and participants can fail the coordination §  Similar to transactions §  but then light 29 For implementations see: https://en.wikipedia.org/wiki/OSGi_Specification_Implementations
  30. 30. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Optimization using Coordinator Service – without API change 30 public void setConfigurations() { for (int i=0; i<10; i++) { setConfig(i); } } private void setConfig(int i) { System.out.println("Setting config data " + i); System.out.println("Flush configuration"); } setConfigurationsWithCoordinator() Setting config data 0 Setting config data 1 Setting config data 2 Setting config data 3 Setting config data 4 Setting config data 5 Setting config data 6 Setting config data 7 Setting config data 8 Setting config data 9 Flush configuration setConfigurations() Setting config data 0 Flush configuration Setting config data 1 Flush configuration Setting config data 2 Flush configuration Setting config data 3 Flush configuration Setting config data 4 Flush configuration Setting config data 5 Flush configuration Setting config data 6 Flush configuration Setting config data 7 Flush configuration Setting config data 8 Flush configuration Setting config data 9 Flush configuration private Coordinator coordinator = ... // From Service Registry
 public void setConfigurationsWithCoordinator() { Coordination c = coordinator.begin("coord.name", 0); try { setConfigurations(); } catch (Exception ex) { c.fail(ex); } finally { c.end(); } } 
 public void setConfigurations() { for (int i=0; i<10; i++) { setConfig(i); } } private void setConfig(int i) { System.out.println("Setting config data " + i); if (!coordinator.addParticipant(this)) System.out.println("Flush configuration"); } @Override public void ended(Coordination c) throws Exception { System.out.println("Flush configuration"); } @Override public void failed(Coordination c) throws Exception {}
  31. 31. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.© 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. OSGi Subsystems
  32. 32. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Package your app for deployment §  Most applications are composed of multiple bundles §  Need a neat deployment package §  Previously: proprietary solutions 32 "Airdrop pallets" by Senior Airman Ricky J. Best - defenselink.mil (search for "airdrop"). Licensed under Public Domain via Wikimedia Commons
  33. 33. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. OSGi Subsystems §  Chapter 134 of Enterprise spec §  Packaging of multi-bundle deployments §  in .esa file (a zip file) §  Optional isolation models §  Bundles either in: §  .esa file §  OSGi Repository 33 Jack Kennard TSA 3-1-1 rule https://www.flickr.com/photos/javajoba/4013349543
  34. 34. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Subsystem types §  Features – everything shared §  Applications – isolated §  for ‘friendly’ multi-tenancy – keeps bundles from interfering with each other §  Composites – configurable isolation §  generally useful for larger infrastructure components 34 Chiot's Run A Few Evenings of Work flickr.com
  35. 35. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Feature Subsystems Deployment artifacts 35 Feature api bundle svc bundle use bundle feature bundle Feature 2 api bundle svc bundle use bundle feature bundle2 Runtime Framework feature bundle svc bundle feature bundle2 use bundle api bundle
  36. 36. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Application Subsystems Deployment artifacts 36 Top-level Application Application api bundle svc bundle use bundle Application 2 api bundle svc bundle use bundle Runtime Framework svc bundle svc bundle2 api bundle use bundle api bundle use bundle
  37. 37. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Build a subsystem §  Use maven: <project> <artifactId>mysubsystem</artifactId> <packaging>esa</packaging> <dependencies> <!– the bundles you want in your subsystem --> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.aries</groupId> <artifactId>esa-maven-plugin</artifactId> <extensions>true</extensions> <configuration> <generateManifest>true</generateManifest> <instructions> <Subsystem-Type>osgi.subsystem.feature </Subsystem-Type> </instructions> </configuration> </plugin> to produce mysubsystem.esa 37 "Sausage making-H-1" by László Szalai (Beyond silence) - Own work. Licensed under Public Domain via Wikimedia Commons
  38. 38. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Deploy 38 https://svn.apache.org/repos/asf/felix/trunk/webconsole-plugins/subsystems https://svn.apache.org/repos/asf/aries/trunk/subsystem/subsystem-gogo-command …or use the Subsystem Gogo Command g! subsystem:list 0 ACTIVE org.osgi.service.subsystem.root 1.0.0 g! subsystem:install …/feature1.esa ... Subsystem successfully installed: feature1; id: 1
  39. 39. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. More info on creating a subsystem §  OSGi Enterprise R6 spec: http://www.osgi.org/Download/Release6 §  Apache Aries website http://aries.apache.org/modules/subsystems.html §  esa-maven-plugin http://aries.apache.org/modules/esamavenpluginproject.html §  For examples see: https://github.com/coderthoughts/subsystem-examples 39
  40. 40. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Recipe – OSGi R6 Compendium 40 §  OSGi Declarative Services (Chapter 112) §  OSGi Http Whiteboard Service (Chapter 140) §  OSGi Configuration Admin (Chapter 104) §  OSGi Metatype Service (Chapter 105) §  OSGi Coordinator (Chapter 130) §  OSGi Subsystems (Chapter 134)
  41. 41. © 2015 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 41 Q&(A)

×