OSGi Remote Services with SCA using Apache Tuscany Raymond Feng
Agenda What are OSGi remote services? A sample scenario: Distributed Calculator Representing OSGi entities using SCA Predefined mapping from OSGi to SCA On-demand mapping from OSGi to SCA Discovery of OSGi remote services Demo of distributed calculator Q&A
What are OSGi remote services?
OSGi local services The OSGi framework decouples service providers and consumers via a local service registry, where a service is an object that one bundle registers and another bundle gets. The services are only be accessed locally by bundles within the same framework instance. It would be nice to make them remote without significant changes of the programming model?
OSGi Remote Services The OSGi core framework specifies a model where bundles can use distributed services. (R4.2) The basic model for OSGi remote services is that a bundle can: –register services that are exported to a communication endpoint –use services that are imported from a communication endpoint (registering a proxy in local service registry)
OSGi Remote Services NOTE: The diagram is copied from OSGi Service Platform Service Compendium R4.2 spec
Related OSGi specs OSGi Service Platform Release 4 Version 4.2 Compendium Specification –Chapter 13: Remote Services (PM, concepts and properties) – Early Access draft of the OSGi 4.2 Enterprise Release –SCA Configuration Type (SCA specific properties) –Remote Service Admin (runtime architecture, SPIs) – early-draft4.pdfhttp:// early-draft4.pdf
SCA Configuration Type SCA Configuration Type for Remote Services –This chapter provides a standard mechanism to configure Remote Services and provide qualities of service or intents, through SCA configuration metadata and WS-Policy. Remote Service implementations that also implement the SCA config type provide a portable way to configuration.
Remote Service Admin –This specification adds an extra layer on top of the existing Remote Services spec (chapter 13 in the 4.2 Compendium).4.2 Compendium –The Distribution Provider registers a RemoteServiceAdmin service that exports and imports services when asked. –The Discovery System API (EndpointListener) provides a standard view over any Discovery System, regardless of how it's realized or what protocol it uses. –The Topology Manager provides a Policy over these things. It decides what services will be exported and for when to look for services in a Discovery System.
OSGi remote services - A sample scenario
An OSGi based Calculator Add Service Operations Bundle Subtract Service Multiply Service Divide Service Calculator bundle Calculator Service OSGi service OSGi service reference Calculator Service OSGi service interface OSGi service implementation
Making the Calculator Distributed Run the calculator bundle and the operations bundle on two OSGi framework instances. –The calculator bundle registers the CalculatorService and it looks up the Add/Subtract/Multiply/Divide services (which are remote over RMI) from the service registry. The CalculatorService is exported as a Web Service. –The operations bundle registers four remote services (Add/Subtract/Multiply/Divide). These services are exported over RMI.
OSGi Remote Services enabled Calculator Add Service Operations Bundle Subtract Service Multiply Service Divide Service Calculator bundle Calculator Service RMIWeb Service RMI OSGi runtime #1 OSGi runtime #2
Modeling OSGi entities using SCA
SCA environment Add Service The Calculator Scenario: OSGi Remote Services with SCA runtime as the distribution software OSGi bundle SCA Component implementation.osgi SCA Component implementation.osgi Subtract Service Multiply Service Divide Service Calculator Service binding.rmi or binding.ws
OperationsCalculator binding.rmi binding.ws OSGI-INF/sca/bundle.composite Add Service Operations Bundle Subtract Service Multiply Service Divide Service Calculator bundle Calculator Service SCA bundle Defining the SCA composite for OSGi bundles
SCA view of OSGi services and references RMI Calculator Service Web Service Web Service SCA proxies Local Service Local OSGi Service Implementation OSGi Service Registry Add Service Subtract Service Multiply Service Divide Service SCA Service SCA References
SCA implementation.osgi The SCA implementation.osgi component will be used to encapsulate one or more OSGi bundles. –OSGi View: implementation.osgi provides the metadata and infrastructure to enable the distribution of OSGi services –SCA View: implementation.osgi allows OSGi bundles to participate in the SCA assembly. The references for an SCA OSGi component represents the OSGi services to be consumed by the bundles The services for an SCA OSgi component represents the OSGi services to be provided by the bundles
Predefined mapping from OSGi to SCA
Mapping an OSGi bundle to an SCA componentType <componentType xmlns=" xmlns:t="
SCA composite for the OSGi bundle <composite xmlns=" xmlns:tuscany=" targetNamespace= name="CalculatorComposite">
On-demand mapping from OSGi to SCA
Remote Service Admin NOTE: The diagram is copied from OSGi Remote Service Admin spec (to be published)
Remote Services with SCA NOTE: The diagram is copied from OSGi Remote Service SCA Configuration Type spec (to be published)
Publish remote services public void start(BundleContext context) throws Exception { Dictionary props = new Hashtable (); props.put("sca.service", "CalculatorComponent#service- name(Calculator)"); props.put("calculator", "Calculator"); props.put("service.exported.configs", new String[] {"org.osgi.sca"}); props.put("org.osgi.sca.bindings", new String[] {"{ props.put("service.exported.interfaces", new String[] {"*"}); CalculatorService calculator = new CalculatorServiceImpl(context); context.registerService(CalculatorService.class.getName(), calculator, props); }
Look up remote services (ServiceTracker) Filter remoteFilter = null; try { remoteFilter = context.createFilter("(&(" + OBJECTCLASS + "=calculator.dosgi.operations.*) (service.imported=*))"); } catch (InvalidSyntaxException e) { … } this.remoteServices = new ServiceTracker(context, remoteFilter, null); remoteServices.open(); … Object[] remoteObjects = remoteServices.getServices();
MANIFEST.MF Manifest-Version: 1.0 Export-Package: calculator.dosgi;version="1.0.1", calculator.dosgi.operations;version="1.0.1" Bundle-Version: Bundle-Name: calculator.dosgi.dynamic Bundle-Activator: calculator.dosgi.impl.CalculatorActivator Bundle-ManifestVersion: 2 Import-Package: org.oasisopen.sca.annotation;version="2.0.0", org.osgi.framework, org.osgi.service.component;resolution:=optional, org.osgi.service.packageadmin, org.osgi.util.tracker Bundle-SymbolicName: calculator.dosgi.dynamic Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 SCA-Configuration: OSGI-INF/sca-config/calculator-config.xml Remote-Service: OSGI-INF/remote-service/*.xml
SCA Configuration <scact:sca-config targetNamespace=" xmlns:scact=" xmlns:sca=" xmlns:tuscany="
Local endpoint descriptions <service-descriptions xmlns=" xmlns:sca=" xmlns:tuscany=" org.osgi.sca { …
SCA Domain based service discovery
Domain Registry for OSGi discovery