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 User Forum Germany 2015
About
cziegeler@apache.org @cziegeler
• RnD Team at Adobe Research Switzerland
• Memberof the Apache Software Foundation
•...
OSGi Preconceptions
3
?!
4
The Next Big Thing
5
Building Blocks
§ Module aka Bundle
§ Services
§ Components
6
Game Design
7
public enum Level {
EASY,
MEDIUM,
HARD
}
public interface GameController {
Game startGame(final String name,...
Implementation
8
@Component
public class GameControllerImpl implements GameController {
...
Configuration
9
public @interface Config {
int easy_max() default 10;
int medium_max() default 50;
int hard_max() default ...
10
private Config configuration;
@Activate
protected void activate(final Config config) {
this.configuration = config;
}
11
public int getMax(final Level level) {
int max = 0;
switch (level) {
case EASY : max = configuration.easy_max(); break;...
Web?
12
@Component( service = Servlet.class ,
property="osgi.http.whiteboard.servlet.pattern=/game")
public class GameServ...
13
public class GameServlet extends HttpServlet {
@Reference
private GameController controller;
14
15
✔
Recipe
§ OSGi Declarative Services (Compendium Chapter112)
§ + RFC 190 Declarative Services Enhancements (OSGi R6)
§ + RFC...
Management
17
Metatype
18
@ObjectClassDefinition(
name = "Game Configuration",
description = "The configuration for the guessing game.")...
Metatype
19
@Component
@Designate( ocd = Config.class )
public class GameControllerImpl
implements GameController {
Component Container Interaction
20
OSGi Service Registry
Declarative
Services
Blueprint
iPojo,
Dependency
Manager,
….
Fram...
Service Scopes
• Singleton
• Bundle
• Prototype
21
Servlets
22
@Component( service = Servlet.class ,
scope=ServiceScope.PROTOTYPE,
property="osgi.http.whiteboard.servlet.pat...
Dynamics
§ Lazy instantiation
§ Reconfiguration
§ Reference policyand cardinality
23
Unary References
24
@Reference
private GameController controller;
@Reference(
cardinality=ReferenceCardinality.OPTIONAL
po...
Multiple References
25
@Reference(
cardinality=ReferenceCardinality.MULTIPLE)
private volatile List<Highscore> highscores;
Multiple References
26
@Reference
private final Set<Highscore> highscores =
new ConcurrentSkipListSet<Highscore>();
Reconfiguration
27
private volatile Config configuration;
@Activate
@Modified
protected void activate(final Config config)...
Granularity
§ Components
§ Services
§ Bundles
§ Servlet/Filter/Listener
§ Web app
28
Web Contexts
29
Servlet B
/score
Servlet A
/game
Servlet Filter
Servlet Context
/play
Authentication
Servlet X
/foo
Servle...
Web Contexts
30
@Component( service = Servlet.class ,
property={"osgi.http.whiteboard.servlet.pattern=/game",
"osgi.http.w...
Try it out today!
§ HTTP Whiteboard Service
§ Servlet contexts (grouping, authentication)
§ Servlets
§ Filters
§ Listeners...
Try it out today!
§ Declarative Services
§ Easy too use
§ Pojos
§ DI with handling dynamics
32
Try it out today!
§ Tooling
§ Open Source Solutions
§ Building large scale enterprise apps
33
QnA
34
Upcoming SlideShare
Loading in …5
×

Service oriented web development with OSGi

Introduction into service oriented web development using OSGi, includes latest Declarative Services (DS) and the Http Whiteboard Specification.

  • Be the first to comment

  • Be the first to like this

Service oriented web development with OSGi

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

×