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.
Service Oriented Web Development with OSGi 
Carsten Ziegeler | cziegeler@apache.org 
1 
OSGi Community Event 2014
About 
cziegeler@apache.org @cziegeler 
• RnD Team at Adobe Research Switzerland 
• Member of the Apache Software Foundati...
OSGi Preconceptions 
No tooling ?!? 
3 
No POJOs 
Too slow 
Not suitable for 
the enterprise 
No dependency injection
4
The Next Big Thing 
5
Building Blocks 
§ Module aka Bundle 
§ Services 
§ Components 
6
Game Design 
public enum Level { 
EASY, 
MEDIUM, 
HARD 
} 
public interface GameController { 
Game startGame(final String ...
Implementation 
@Component 
public class GameControllerImpl implements GameController { 
8 
...
Configuration 
public @interface Config { 
int easy_max() default 10; 
int medium_max() default 50; 
int hard_max() defaul...
private Config configuration; 
@Activate 
protected void activate(final Config config) { 
this.configuration = config; 
10...
public int getMax(final Level level) { 
11 
int max = 0; 
switch (level) { 
case EASY : max = configuration.easy_max(); br...
Web? 
@Component( service = Servlet.class , 
property="osgi.http.whiteboard.servlet.pattern=/game") 
public class GameServ...
public class GameServlet extends HttpServlet { 
@FieldReference 
private GameController controller; 
13
14
15 
No POJOs 
Too slow 
Not suitable for 
the enterprise 
No dependency injection 
No tooling 
✔
Recipe 
§ OSGi Declarative Services (Compendium Chapter 112) 
§ + RFC 190 Declarative Services Enhancements (OSGi R6) 
§...
Management 
17
Metatype 
18 
@ObjectClassDefinition( 
name = "Game Configuration", 
description = "The configuration for the guessing gam...
Metatype 
@Component 
@Designate( ocd = Config.class ) 
public class GameControllerImpl 
implements GameController { 
19
Component Container Interaction 
OSGi Service Registry 
Declarative 
Services Blueprint 
20 
iPojo, 
Dependency 
Manager, ...
Service Scopes 
• Singleton 
• Bundle 
• Prototype 
21
Servlets 
@Component( service = Servlet.class , 
scope=ServiceScope.PROTOTYPE, 
property="osgi.http.whiteboard.servlet.pat...
Dynamics 
§ Lazy instantiation 
§ Reference policy and cardinality 
§ Reconfiguration 
23
Unary References 
@FieldReference 
private GameController controller; 
@FieldReference( 
cardinality=ReferenceCardinality....
Multiple References 
@FieldReference( 
cardinality=ReferenceCardinality.MULTIPLE) 
private volatile List<Highscore> highsc...
Multiple References 
@FieldReference 
private final Set<Highscore> highscores = 
new ConcurrentSkipListSet<Highscore>(); 
...
Reconfiguration 
private volatile Config configuration; 
@Activate 
@Modified 
protected void activate(final Config config...
Web Contexts 
28 
Servlet Context 
/play 
Authentication 
Servlet B 
/foo 
Servlet A 
/game 
Servlet C 
/bar 
Servlet Filt...
Web Contexts 
@Component( service = Servlet.class , 
property={"osgi.http.whiteboard.servlet.pattern=/foo", 
"osgi.http.wh...
Try it out today! 
§ HTTP Whiteboard Service 
§ Servlet contexts (grouping, authentication) 
§ Servlets 
§ Filters 
§...
Try it out today! 
§ Declarative Services 
§ Easy too use 
§ Pojos 
§ DI with handling dynamics 
§ Tooling 
§ Open S...
QnA 
32
Upcoming SlideShare
Loading in …5
×

Service Oriented Web Development with OSGi - C Ziegeler

727 views

Published on

OSGi Community Event 2014

Abstract:
OSGi is complicated, complex and requires too much coding? Whether you think that's true or whether you are interested in seeing live how easy it is to develop a web application with OSGi, this session is the place to go to.

During the talk a web application based on OSGi services will be developed leveraging the latest OSGi specifications, the Http Whiteboard Service (RFC 189) and updates to Declarative Services (RFC 190, RFC 208 and RFC 212). The used implementations are well known projects from The Apache Software Foundation. Learn how to leverage the annotation based development which is very easy to use but also very powerful. Apart from developing the application, open source tooling based on the Eclipse IDE will be demonstrated making the life of a developer much easier. Of course, important topics like configuration and management of the web application are covered as well.

Speaker Bio:
Carsten Ziegeler is senior developer at Adobe Research Switzerland and spends most of his time on architectural and infrastructure topics. Working for over 25 years in open source projects, Carsten is a member of the Apache Software Foundation and heavily participates in several Apache communities including Sling, Felix and ACE. He is a frequent speaker on technology and open source conferences and participates in the OSGi Core Platform and Enterprise expert groups.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Service Oriented Web Development with OSGi - C Ziegeler

  1. 1. Service Oriented Web Development with OSGi Carsten Ziegeler | cziegeler@apache.org 1 OSGi Community Event 2014
  2. 2. About cziegeler@apache.org @cziegeler • RnD Team at Adobe Research Switzerland • Member of the Apache Software Foundation • Apache Felix and Apache Sling (PMC and committer) • And other Apache projects • OSGi Core Platform and Enterprise Expert Groups • Member of the OSGi Board • Book / article author, technical reviewer, conference speaker 2
  3. 3. OSGi Preconceptions No tooling ?!? 3 No POJOs Too slow Not suitable for the enterprise No dependency injection
  4. 4. 4
  5. 5. The Next Big Thing 5
  6. 6. Building Blocks § Module aka Bundle § Services § Components 6
  7. 7. Game Design 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); 7 }
  8. 8. Implementation @Component public class GameControllerImpl implements GameController { 8 ...
  9. 9. Configuration public @interface Config { int easy_max() default 10; int medium_max() default 50; int hard_max() default 100; } 9
  10. 10. private Config configuration; @Activate protected void activate(final Config config) { this.configuration = config; 10 }
  11. 11. public int getMax(final Level level) { 11 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; }
  12. 12. Web? @Component( service = Servlet.class , property="osgi.http.whiteboard.servlet.pattern=/game") public class GameServlet extends HttpServlet { 12
  13. 13. public class GameServlet extends HttpServlet { @FieldReference private GameController controller; 13
  14. 14. 14
  15. 15. 15 No POJOs Too slow Not suitable for the enterprise No dependency injection No tooling ✔
  16. 16. Recipe § OSGi Declarative Services (Compendium Chapter 112) § + RFC 190 Declarative Services Enhancements (OSGi R6) § + RFC 212 Field Injection for Declarative Services (OSGi R6) § OSGi Whiteboard Service § + RFC 189 (OSGi R6) § OSGi Configuration Admin (Compendium Chapter 104) § OSGi Metatype Service (Compendium Chapter 105) § + RFC 208 Metatype Annotations 16
  17. 17. Management 17
  18. 18. Metatype 18 @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;
  19. 19. Metatype @Component @Designate( ocd = Config.class ) public class GameControllerImpl implements GameController { 19
  20. 20. Component Container Interaction OSGi Service Registry Declarative Services Blueprint 20 iPojo, Dependency Manager, …. Framework API
  21. 21. Service Scopes • Singleton • Bundle • Prototype 21
  22. 22. Servlets @Component( service = Servlet.class , scope=ServiceScope.PROTOTYPE, property="osgi.http.whiteboard.servlet.pattern=/game") public class GameServlet extends HttpServlet { public void init() {...} public void destroy() {...} 22
  23. 23. Dynamics § Lazy instantiation § Reference policy and cardinality § Reconfiguration 23
  24. 24. Unary References @FieldReference private GameController controller; @FieldReference( cardinality=ReferenceCardinality.OPTIONAL policy=ReferencePolicy.DYNAMIC) private volatile GameStatistics stats; 24
  25. 25. Multiple References @FieldReference( cardinality=ReferenceCardinality.MULTIPLE) private volatile List<Highscore> highscores; 25
  26. 26. Multiple References @FieldReference private final Set<Highscore> highscores = new ConcurrentSkipListSet<Highscore>(); 26
  27. 27. Reconfiguration private volatile Config configuration; @Activate @Modified protected void activate(final Config config) { this.configuration = config; } 27
  28. 28. Web Contexts 28 Servlet Context /play Authentication Servlet B /foo Servlet A /game Servlet C /bar Servlet Filter Servlet Context /fooapp Authentication Servlet X /foo
  29. 29. Web Contexts @Component( service = Servlet.class , property={"osgi.http.whiteboard.servlet.pattern=/foo", "osgi.http.whiteboard.context.select=mygame"} public class ServletB extends HttpServlet { @Component( service = Servlet.class , property={"osgi.http.whiteboard.servlet.pattern=/bar", "osgi.http.whiteboard.context.select=game"} public class ServletC extends HttpServlet { 29
  30. 30. Try it out today! § HTTP Whiteboard Service § Servlet contexts (grouping, authentication) § Servlets § Filters § Listeners 30
  31. 31. Try it out today! § Declarative Services § Easy too use § Pojos § DI with handling dynamics § Tooling § Open Source Solutions § Building large scale enterprise apps 31
  32. 32. QnA 32

×