OSGi Community Event 2013 (http://www.osgi.org/CommunityEvent2013/Schedule)
ABSTRACT
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.
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.
2. About
cziegeler@adobe.com
@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. 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
5. OSGi Event Admin
Publish Subscribe Model
Component Y
Component
A
publish
OSGi Event Admin
deliver
Component X
5
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. OSGi Event Admin
Publish Subscribe Model
§
Publisher creates event object
§
Sends event through EventAdmin service
§
Either synchronous or asynchronous delivery
7
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. 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. 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. OSGi Event Admin
Publish Subscribe Model
§
Immediate delivery to available subscribers
§
No guarantee of delivery
§
No distributed delivery
11
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
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. 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. 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. 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. 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. Topologies II
Apache Sling Discovery
§
Cluster
§
Elects (stable) leader
§
Topology
Stable instance ordering
Instance
3
Lead
er
ID : 42
Cluster 99
27
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. RFC 183 – Cloud Ecosystems
§
“Distributed” FrameworkNodeStatus services
§
Information about each cloud node
§
Defined instance properties
§
Extensible
29
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
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. 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. 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. 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. 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. 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. 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