0
Distributed Eventing in OSGi
Carsten Ziegeler | Adobe Research Switzerland

1
About
cziegeler@apache.org

@cziegeler

§ 

RnD Team at Adobe Research Switzerland

§ 

OSGi Core Platform and Enterpris...
Topics
§ 

OSGi Event Admin

§ 

RFP 158 – Distributed Eventing

§ 

Apache Sling Eventing Part I

§ 

Apache Sling To...
OSGi Event Admin

4
OSGi Event Admin
Publish Subscribe Model

Component Y
Component
A

publish
OSGi Event Admin

deliver
Component X

5
OSGi Event Admin
Publish Subscribe Model
§ 

OSGi event is a data object with
§ 
§ 

§ 

Topic (hierarchical namespace...
OSGi Event Admin
Publish Subscribe Model
§ 

Publisher creates event object
§ 

Sends event through EventAdmin service

...
OSGi Event Admin
Publish Subscribe Model
§ 

Publisher creates event object
§ 

Sends event through EventAdmin service

...
OSGi Event Admin
Publish Subscribe Model
§ 

Subscriber is an OSGi service (EventHandler)
§ 

Whiteboard pattern

§ 

S...
OSGi Event Admin
Publish Subscribe Model
§ 

Subscriber is an OSGi service (EventHandler)
§ 

Whiteboard pattern

§ 

S...
OSGi Event Admin
Publish Subscribe Model

§ 

Immediate delivery to available subscribers

§ 

No guarantee of delivery
...
OSGi Event Admin
Publish Subscribe Model
Apache Sling
Discovery
Distributed Eventing
Job Handling

OSGi
RFP 158

§ 

Imme...
RFP 158 – Distributed Eventing

13
RFP 158 – Distributed Eventing
§ 

Asynchronous remote eventing
§ 

One-to-one, one-to-many

§ 

Messages with replies
...
Apache Sling
Distributed Event Admin

15
Distributed OSGi Events
§ 

Apache Sling Eventing leverages OSGi Event Admin

§ 

Listener for all OSGi events with
§ 
...
Distributed OSGi Events
§ 

Apache Sling Eventing leverages OSGi Event Admin

@Component	
public class EventSender {	
	
@...
Distributed OSGi Events
§ 

Apache Sling Eventing leverages OSGi Event Admin

@Component	
@Service(value=EventHandler.cla...
Distributed OSGi Events
§ 

Apache Sling Eventing leverages OSGi Event Admin

§ 

Sender controls distribution

§ 

Apa...
Apache Sling - Discovery
Topologies

20
Installation Scenarios

Single
Instance

Instance
1

21

Instance
2

Instance
3
Topologies I
Apache Sling Discovery
§ 

Instance: Unique Id (Sling ID)

Single
Instance
ID : 1

Instance
1
ID : A

22

In...
Topologies I
Apache Sling Discovery
§ 

Instance: Unique Id (Sling ID)

§ 

Cluster: Unique Id and leader

Single
Instan...
Topologies I
Apache Sling Discovery

Topology: Set of clusters

§ 

Topology

Topology

Single
Instance

Instance
1

Inst...
Topologies I
Apache Sling Discovery

§ 

Topology: Set of clusters
Topology

Single
Instance

Instance
1

Instance
2

Ins...
Topologies II
Apache Sling Discovery
§ 

Instance
§ 

Sling ID

§ 

Topology

Optional:
Name and description

§ 

Lead...
Topologies II
Apache Sling Discovery
§ 

Cluster
§ 

Elects (stable) leader

§ 

Topology

Stable instance ordering

In...
Topologies II
Apache Sling Discovery
§ 

TopologyEventListener

Topology

§ 

Whiteboard pattern

§ 

Receives events o...
RFC 183 – Cloud Ecosystems
§ 

“Distributed” FrameworkNodeStatus services
§ 

Information about each cloud node

§ 

De...
RFC 183 – Cloud Ecosystems
§ 

“Distributed” FrameworkNodeStatus services
§ 

Information about each cloud node

§ 

De...
From Events to Jobs

31
Job Handling I
Apache Sling Job Handling
§ 

Job : Guaranteed processing, exactly once
§ 

§ 

Exactly one job consumer...
Starting / Processing a Job I
Apache Sling Job Handling
Starting a job
public interface JobManager {	
	
Job addJob(String ...
Starting / Processing a Job I
Apache Sling Job Handling

Processing a job
public interface JobConsumer {	
	
String PROPERT...
Job Handling I
Apache Sling Job Handling
§ 

Sling Job Manager handles and distributes jobs
§ 
§ 

…and waits for respo...
Starting / Processing a Job II
Apache Sling Job Handling

@Component	
@Service(value={JobConsumer.class})	
@Property(name=...
Job Handling
Apache Sling Job Handling
§ 

Distributed job processing within a topology
§ 

Instances might have differe...
Topics
§ 

OSGi Event Admin

§ 

RFP 158 – Distributed Eventing

§ 

Apache Sling Eventing Part I

§ 

Apache Sling To...
Upcoming SlideShare
Loading in...5
×

Distributed Eventing in OSGi

602

Published on

Presentation from OSGi Community Event / EclipseCon Europe 2013
One of the major topics the OSGi alliance is working on is a proposal for distributed eventing especially in the cloud. This session starts with an overview of the current state in the alliance and then shows already available solutions from the Apache Sling open source project. This includes distributing events through event admin and controlled processing of events by exactly one processor in distributed installations. The current implementations will be set in context to the ongoing activations in the alliance.

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
602
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Distributed Eventing in OSGi"

  1. 1. Distributed Eventing in OSGi Carsten Ziegeler | Adobe Research Switzerland 1
  2. 2. About cziegeler@apache.org @cziegeler §  RnD Team at Adobe Research Switzerland §  OSGi Core Platform and Enterprise Expert Groups §  Member of the ASF §  Most active in Apache Sling, Felix, ACE §  Conference Speaker §  Technical Reviewer §  Article/Book Author 2
  3. 3. Topics §  OSGi Event Admin §  RFP 158 – Distributed Eventing §  Apache Sling Eventing Part I §  Apache Sling Topology §  RFC 183 – Cloud Ecosystems §  Apache Sling Eventing Part II 3
  4. 4. OSGi Event Admin 4
  5. 5. OSGi Event Admin Publish Subscribe Model Component Y Component A publish OSGi Event Admin deliver Component X 5
  6. 6. OSGi Event Admin Publish Subscribe Model §  OSGi event is a data object with §  §  §  Topic (hierarchical namespace) Properties (key-value-pairs) Resource Event §  Topic: org/apache/sling/api/resource/Resource/ADDED §  Properties: path, resource type etc. 6
  7. 7. OSGi Event Admin Publish Subscribe Model §  Publisher creates event object §  Sends event through EventAdmin service §  Either synchronous or asynchronous delivery 7
  8. 8. OSGi Event Admin Publish Subscribe Model §  Publisher creates event object §  Sends event through EventAdmin service §  Either synchronous or asynchronous delivery @Component public class EventSender { @Reference private EventAdmin eventAdmin; public void run() { while ( true ) { final Map<String, Object> properties = new HashMap<String, Object>(); properties.put("timestamp", System.currentTimeMillis()); final Event event = new Event("i/am/still/alive", properties); eventAdmin.sendEvent(event); // eventAdmin.postEvent(event); Thread.sleep(2000); } } } 8
  9. 9. OSGi Event Admin Publish Subscribe Model §  Subscriber is an OSGi service (EventHandler) §  Whiteboard pattern §  Service registration properties §  Interested topic(s) §  §  org/apache/sling/api/resource/Resource/* Additional filters (optional) §  (path=/libs/*) 9
  10. 10. OSGi Event Admin Publish Subscribe Model §  Subscriber is an OSGi service (EventHandler) §  Whiteboard pattern §  Service registration properties @Component @Service(value=EventHandler.class) @Properties({ @Property(name=EventConstants.EVENT_TOPIC, value="i/am/still/alive") }) public class EventReceiver implements EventHandler { public void handleEvent(final Event event) { System.out.println("Still alive at " + event.getProperty("timestamp")); } } 10
  11. 11. OSGi Event Admin Publish Subscribe Model §  Immediate delivery to available subscribers §  No guarantee of delivery §  No distributed delivery 11
  12. 12. OSGi Event Admin Publish Subscribe Model Apache Sling Discovery Distributed Eventing Job Handling OSGi RFP 158 §  Immediate delivery to available subscribers §  No guarantee of delivery §  No distributed delivery 12
  13. 13. RFP 158 – Distributed Eventing 13
  14. 14. RFP 158 – Distributed Eventing §  Asynchronous remote eventing §  One-to-one, one-to-many §  Messages with replies §  Advertising and selection of Quality of Service §  Sender identification §  Language agnostic 14
  15. 15. Apache Sling Distributed Event Admin 15
  16. 16. Distributed OSGi Events §  Apache Sling Eventing leverages OSGi Event Admin §  Listener for all OSGi events with §  §  event property "event.distribute=true” Events are distributed §  Event property "event.application” contains the origin 16
  17. 17. Distributed OSGi Events §  Apache Sling Eventing leverages OSGi Event Admin @Component public class EventSender { @Reference private EventAdmin eventAdmin; public void send() { final Map<String, Object> properties = new HashMap<String, Object>(); properties.put("event.distribute", Boolean.TRUE); properties.put("timestamp", System.currentTimeMillis()); final Event event = new Event("i/am/still/alive", properties); eventAdmin.sendEvent(event); } } 17
  18. 18. Distributed OSGi Events §  Apache Sling Eventing leverages OSGi Event Admin @Component @Service(value=EventHandler.class) @Properties({ @Property(name=EventConstants.EVENT_TOPIC, value="i/am/still/alive") }) public class EventReceiver implements EventHandler { public void handleEvent(final Event event) { System.out.println("Still alive " + event.getProperty("event.application") + " : " + event.getProperty("timestamp")); } } 18
  19. 19. Distributed OSGi Events §  Apache Sling Eventing leverages OSGi Event Admin §  Sender controls distribution §  Apache Sling used for distribution §  §  (through JCR content repository, Apache Jackrabbit) API is independent from implementation 19
  20. 20. Apache Sling - Discovery Topologies 20
  21. 21. Installation Scenarios Single Instance Instance 1 21 Instance 2 Instance 3
  22. 22. Topologies I Apache Sling Discovery §  Instance: Unique Id (Sling ID) Single Instance ID : 1 Instance 1 ID : A 22 Instance 2 ID : X Instance 3 ID : 42
  23. 23. Topologies I Apache Sling Discovery §  Instance: Unique Id (Sling ID) §  Cluster: Unique Id and leader Single Instance Instance 1 Instance 2 Instance 3 Leader ID : 1 Leader ID : A Cluster 35 ID : X Cluster 99 23 ID : 42
  24. 24. Topologies I Apache Sling Discovery Topology: Set of clusters §  Topology Topology Single Instance Instance 1 Instance 2 Instance 3 Leader ID : 1 Leader ID : A Cluster 35 ID : X Cluster 99 24 ID : 42
  25. 25. Topologies I Apache Sling Discovery §  Topology: Set of clusters Topology Single Instance Instance 1 Instance 2 Instance 3 Leader ID : 1 Cluster 35 Leader ID : A Cluster 99 25 ID : X ID : 42
  26. 26. Topologies II Apache Sling Discovery §  Instance §  Sling ID §  Topology Optional: Name and description §  Lead er ID : 42 Belongs to a cluster §  §  Instance 3 Might be the cluster leader Additional distributed properties §  Extensible through own services (PropertyProvider) §  E.g. data center, region or enabled job topics 26 Cluster 99
  27. 27. Topologies II Apache Sling Discovery §  Cluster §  Elects (stable) leader §  Topology Stable instance ordering Instance 3 Lead er ID : 42 Cluster 99 27
  28. 28. Topologies II Apache Sling Discovery §  TopologyEventListener Topology §  Whiteboard pattern §  Receives events on topology changes §  Topology is changing §  Lead er ID : 42 Topology changed §  Instance 3 Properties changed Cluster 99 28
  29. 29. RFC 183 – Cloud Ecosystems §  “Distributed” FrameworkNodeStatus services §  Information about each cloud node §  Defined instance properties §  Extensible 29
  30. 30. RFC 183 – Cloud Ecosystems §  “Distributed” FrameworkNodeStatus services §  Information about each cloud node §  Defined instance properties §  Extensible §  Similar to Apache Sling’s topology §  Well defined services vs. listener and data objects §  One can implement the other J 30
  31. 31. From Events to Jobs 31
  32. 32. Job Handling I Apache Sling Job Handling §  Job : Guaranteed processing, exactly once §  §  Exactly one job consumer Started by client code §  §  §  Job topic Payload is a serializable map API is similar to OSGi Event Admin 32
  33. 33. Starting / Processing a Job I Apache Sling Job Handling Starting a job public interface JobManager { Job addJob(String topic, Map<String, Object> properties); … } 33
  34. 34. Starting / Processing a Job I Apache Sling Job Handling Processing a job public interface JobConsumer { String PROPERTY_TOPICS = "job.topics"; enum JobResult { OK, FAILED, CANCEL, ASYNC } JobResult process(Job job); } 34
  35. 35. Job Handling I Apache Sling Job Handling §  Sling Job Manager handles and distributes jobs §  §  …and waits for response §  §  Delivers job to a job consumer… Retry and failover Notification listeners (fail, retry, success) 35
  36. 36. Starting / Processing a Job II Apache Sling Job Handling @Component @Service(value={JobConsumer.class}) @Property(name=JobConsumer.PROPERTY_TOPICS, value="org/apache/sling/jobs/backup") public class BackupJobConsumer implements JobConsumer { @Override public JobResult process(final Job job) { // do backup return JobResult.OK; } } 36
  37. 37. Job Handling Apache Sling Job Handling §  Distributed job processing within a topology §  Instances might have different capabilities §  Offloading of heavy jobs §  Various queue configurations §  Failover handling §  Topology changes §  Progress tracking §  History of jobs 37
  38. 38. Topics §  OSGi Event Admin §  RFP 158 – Distributed Eventing §  Apache Sling Eventing Part I §  Apache Sling Topology §  RFC 183 – Cloud Ecosystems §  Apache Sling Eventing Part II 38
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×