In the first part of this talk David Bosschaert will explain the Distributed OSGi specification, which is new in OSGi 4.2. The talk will outline the design principles and also show how to distribute OSGi services in practise by a short demo. In the second part of this talk Marc Schaaf will present some preliminary results regarding research on how asynchronous messaging could be integrated into OSGi. The talk will discuss some possible integration approaches and will outline the current approach taken in this research project. A short demo is included showing how developers could use it.
Distributed Services - OSGi 4.2 and possible future enhancements
1. Distributed OSGi and Possible
Future Enhancements
David Bosschaert Marc Schaaf
david.bosschaert@gmail.com marc@marc-schaaf.de
OSGi DevCon Europe 2009 - Zürich
2. About Us
● David Bosschaert
● Works at Progress Software in Dublin (previously IONA
Technologies)
● Member of the OSGi Enterprise Expert Group
● Coding Open Source projects
● Marc Schaaf
● Student of computer science at the University of Applied Science
in Hannover, Germany
● Currently writing his masters thesis on a possible integration of
asynchronous messaging into OSGi
4. Remote Services
New OSGi Specifications, based on the Distributed OSGi RFC 119.
1. Remote Services, which specifies the standardized properties for
service remoting.
Will be released this summer as part of OSGi 4.2
2. Distribution Service Admin API’s. Contains standard API’s for
interacting with the Distribution Provider and Discovery Providers.
Will be released before the end of the year.
5. Demo of Remote Services
Client Side OSGi container Server Side OSGi container
(Felix) (Equinox)
Core OSGi Bundles Core OSGi Bundles
Library Bundles Library Bundles
DOSGi Bundles DOSGi Bundles
(Apache CXF) (Apache CXF)
My App Interfaces Bundle My App Interfaces Bundle
ook
My App Consumer Bundle My App Service Bundle
egistry H
Service R red by
invokes creates
provides
trigge
publishes
svc OSGi
proxy svc
remote
service
metadata
remote remote endpoint
publishes
Discovery invocation
service
8. The OSGi EventAdmin
● EventAdmin
● OSGi internal mechanism for (asynchronous) event based
communication with topic semantic
EventAdmin
Service
Push Events
SendingBundle
EventAdmin Impl.
Receive Events Deliver Events
ReceivingBundle
EventHandler
Service
● Events consist of a topic and an arbitrary number of key:value
pairs
● An EventHandler can provide a filter to select the events he
wants to receive
9. EventAdmin Based Integration
Idea: Introduce an “Event Distribution System” (EDS)
which mediates between the EventAdmin and the MoM
OSGi Container
OSGi Container
Events Messages
EventHandling
Service
EventAdmin Configuration
Receiving Bundle Service
EventAdmin EDS MoM
Sending Bundle
EventAdmin EventHandling
Service Service
Events Messages
10. EventAdmin Based Integration
● Basic messaging functionality with existing API
● Seamless integration
● Usage of MoM without any knowledge about it
●
Drawbacks
● No guaranteed delivery → No reliability
● No error handling, .....
●
Possible solutions
● Use another (new) API
● Extend the existing API (next slide)
11. “Extended” EventAdmin
● Idea: Introduce an extended EventAdmin API
● The additional API could provide guaranteed delivery and could
be implemented directly by the EDS
● The old API still enables legacy bundles to use messaging with
limited features
OSGi Container
OSGi Container Extended EventAdmin
Service
EventHandling
Service
EventAdmin
Service
Receiving Bundle
EventAdmin EDS MoM
Sending Bundle
EventAdmin EventHandling
Service Service
13. How to Send Messages
ServiceTracker
st = new ServiceTracker(bctx, EventAdmin.class.getName(), null) {
@Override
public Object addingService(ServiceReference reference) {
eventAdmin = (EventAdmin) bctx.getService(reference);
jbSend.setEnabled(true);
return super.addingService(reference);
}
};
Sending an Event
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("message", jtMessage.getText());
Event ev = new Event("demo", props);
eventAdmin.sendEvent(ev);
Configuration
org.fusesource.lightsabre.name=DemoActiveMqForwarding
org.fusesource.lightsabre.direction=send
org.fusesource.lightsabre.event.topic=demo
org.fusesource.lightsabre.messaging.binding=org.apache.activemq
org.fusesource.lightsabre.messaging.url=tcp://localhost:61616
org.fusesource.lightsabre.messaging.subject=DemoActivemqTopic
[...]
14. How to Receive Messages
Bundle Activator
public void start(BundleContext context) throws Exception {
Dictionary props = new Hashtable();
props.put(EventConstants.EVENT_TOPIC, "demo");
context.registerService(EventHandler.class.getName(),new DemoMessageReceiver(),
props);
}
Event Handler
public class DemoMessageReceiver implements EventHandler {
public void handleEvent(Event event) {
System.out.println("DemoMessageReceiver: " + event.getProperty("message"));
}
}
Configuration
org.fusesource.lightsabre.name=DemoActiveMqForwarding
org.fusesource.lightsabre.direction=receive
org.fusesource.lightsabre.messaging.binding=org.apache.activemq
org.fusesource.lightsabre.messaging.url=tcp://localhost:61616
org.fusesource.lightsabre.messaging.subject=DemoActivemqTopic
[...]
15. Conclusion
● Distributed OSGi
● A standardized way to use the OSGi Services model with Remote
Service Distribution
● Asynchronous Messaging
● Promising approach as a basis for further research found
● Lightsabre provides a first implementation
16. Thank you for your kind attention
OSGi Remote Services Project Lightsabre
OSGi Asynchronous Messaging
OSGi 4.2 Draft
➔ http://www.osgi.org/Specifications/Drafts ➔ http://lightsabre.fusesource.org
Reference Implementation
➔ http://cxf.apache.org/distributed-osgi.html