Title: OSGi Remote Services with SCA using Apache Tuscany
1OSGi Remote Services with SCA using Apache Tuscany
- Raymond Feng
- rfeng_at_apache.org
2Agenda
- 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
- QA
3What are OSGi remote services?
4OSGi 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?
5OSGi 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)
6OSGi Remote Services
NOTE The diagram is copied from OSGi Service
Platform Service Compendium R4.2 spec
7Related OSGi specs
- OSGi Service Platform Release 4 Version 4.2
Compendium Specification - Chapter 13 Remote Services (PM, concepts and
properties) - http//www.osgi.org/download/r4v42/r4.cmpn.pdf
- Early Access draft of the OSGi 4.2 Enterprise
Release - SCA Configuration Type (SCA specific properties)
- Remote Service Admin (runtime architecture, SPIs)
- http//www.osgi.org/download/osgi-4.2-enterprise-e
arly-draft4.pdf
8SCA 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.
9Remote Service Admin
- Remote Service Admin
- This specification adds an extra layer on top of
the existing Remote Services spec (chapter 13 in
the 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.
10OSGi remote services- A sample scenario
11An OSGi based Calculator
Add Service
Subtract Service
Calculator Service
Multiply Service
Divide Service
Calculator bundle
Operations Bundle
Calculator Service
OSGi service
OSGi service interface
OSGi service reference
OSGi service implementation
12Making 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.
13OSGi Remote Services enabled Calculator
14Modeling OSGi entities using SCA
15The Calculator Scenario OSGi Remote
Services with SCA runtime as the distribution
software
SCA Component implementation.osgi
binding.rmi or binding.ws
SCA Component implementation.osgi
Add Service
Subtract Service
Multiply Service
Calculator Service
Divide Service
OSGi bundle
OSGi bundle
SCA environment
16Defining the SCA composite for OSGi bundles
OSGI-INF/sca/bundle.composite
SCA bundle
binding.rmi
binding.ws
Operations
Calculator
Add Service
Subtract Service
Calculator Service
Multiply Service
Divide Service
Calculator bundle
Operations Bundle
17SCA view of OSGi services and references
Local Service
OSGi Service Registry
Local OSGi Service Implementation
SCA Service
Calculator Service
Web Service
Add Service
RMI
Subtract Service
RMI
Multiply Service
RMI
RMI
Divide Service
SCA References
SCA proxies
18SCA 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
19Predefined mapping from OSGi to
SCAhttp//svn.apache.org/repos/asf/tuscany/java/
sca/samples/dosgi-calculator/http//svn.apache.or
g/repos/asf/tuscany/java/sca/samples/dosgi-calcula
tor-operations/
20Mapping an OSGi bundle to an SCA componentType
- ltcomponentType xmlns"http//docs.oasis-open.org/n
s/opencsa/sca/200903" - xmlnst"http//tuscany.apache.org/xmlns/sca/1.1"
gt - lt!-- The service elment defines an SCA view
of the OSGi service --gt - ltservice name"CalculatorService"gt
- lt!-- The interface will be mapped into
the OSGi service class --gt - ltinterface.java interface"calculator.dosg
i.CalculatorService"/gt - lt/servicegt
- lt!-- The reference elment defines an SCA
proxy to a remote OSGi service --gt - ltreference name"addService"gt
- ltinterface.java interface"calculator.dosg
i.operations.AddService"/gt - lt/referencegt
- ltreference name"subtractService"gt
- ltinterface.java interface"calculator.dosg
i.operations.SubtractService"/gt - lt/referencegt
- ltreference name"multiplyService"gt
- ltinterface.java interface"calculator.dosg
i.operations.MultiplyService"/gt - lt/referencegt
- ltreference name"divideService"gt
- ltinterface.java interface"calculator.dosg
i.operations.DivideService"/gt
21SCA composite for the OSGi bundle
- ltcomposite xmlns"http//docs.oasis-open.org/ns/op
encsa/sca/200903 - xmlnstuscany"http//tuscany.apache.org/xmlns
/sca/1.1 - targetNamespacehttp//calculator.dosgi
name"CalculatorComposite"gt - ltcomponent name"CalculatorComponent"gt
- lttuscanyimplementation.osgi
bundleSymbolicName"calculator.dosgi"
bundleVersion"1.0.0" /gt - ltservice name"CalculatorService"gt
- ltbinding.ws uri"http//localhost8086
/CalculatorService"/gt - lt/servicegt
- ltreference name"addService"gt
- lttuscanybinding.rmi
uri"rmi//localhost8085/AddService"/gt - lt/referencegt
- ltreference name"subtractService"gt
- lttuscanybinding.rmi
uri"rmi//localhost8085/SubtractService"/gt - lt/referencegt
- ltreference name"multiplyService"gt
- lttuscanybinding.rmi
uri"rmi//localhost8085/MultiplyService"/gt - lt/referencegt
- ltreference name"divideService"gt
- lttuscanybinding.rmi
uri"rmi//localhost8085/DivideService"/gt
22On-demand mapping from OSGi to SCAhttp//svn.apa
che.org/repos/asf/tuscany/java/sca/samples/dosgi-d
ynamic-calculator/http//svn.apache.org/repos/asf
/tuscany/java/sca/samples/dosgi-dynamic-calculator
-operations/
23Remote Service Admin
NOTE The diagram is copied from OSGi Remote
Service Admin spec (to be published)
24Remote Services with SCA
NOTE The diagram is copied from OSGi Remote
Service SCA Configuration Type spec (to be
published)
25Publish remote services
- public void start(BundleContext context) throws
Exception - DictionaryltString, Objectgt props new
HashtableltString, Objectgt() - props.put("sca.service",
"CalculatorComponentservice-name(Calculator)") - props.put("calculator", "Calculator")
- props.put("service.exported.configs", new
String "org.osgi.sca") - props.put("org.osgi.sca.bindings", new
String "http//sampleCalculator") - props.put("service.exported.interfaces",
new String "") - CalculatorService calculator new
CalculatorServiceImpl(context) - context.registerService(CalculatorService.
class.getName(), calculator, props)
26Look 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.getService
s()
27MANIFEST.MF
- Manifest-Version 1.0
- Export-Package calculator.dosgiversion"1.0.1",
- calculator.dosgi.operationsversion"1.0.1"
- Bundle-Version 1.0.0
- Bundle-Name calculator.dosgi.dynamic
- Bundle-Activator calculator.dosgi.impl.Calculator
Activator - Bundle-ManifestVersion 2
- Import-Package org.oasisopen.sca.annotationversi
on"2.0.0", - org.osgi.framework,
- org.osgi.service.componentresolutionoptional,
- 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
28SCA Configuration
- ltscactsca-config targetNamespace"http//sample"
- xmlnsscact"http//www.osgi.org/xmlns/scact/v
1.0.0" - xmlnssca"http//docs.oasis-open.org/ns/openc
sa/sca/200903" - xmlnstuscany"http//tuscany.apache.org/xmlns
/sca/1.1"gt - ltscabinding.ws name"Calculator"
uri"http//localhost8086/CalculatorService"/gt -
- lt!-- bindings for the remote services --gt
- lttuscanybinding.rmi name"Add"
uri"rmi//localhost8085/AddService"/gt - lttuscanybinding.rmi name"Divide"
uri"rmi//localhost8085/DivideService"/gt - lttuscanybinding.rmi name"Subtract"
uri"rmi//localhost8085/SubtractService"/gt - lttuscanybinding.rmi name"Multiply"
uri"rmi//localhost8085/MultiplyService"/gt - lt/scactsca-configgt
29Local endpoint descriptions
- ltservice-descriptions xmlns"http//www.osgi.org/x
mlns/sd/v1.0.0" - xmlnssca"http//docs.oasis-open.org/ns/openc
sa/sca/200903" - xmlnstuscany"http//tuscany.apache.org/xmlns
/sca/1.1"gt - lt!-- Describe a remote OSGi service --gt
- ltservice-descriptiongt
- ltprovide interface"calculator.dosgi.opera
tions.AddService" /gt - ltproperty name"remote.exported.intents"gtlt
/propertygt - ltproperty name"remote.configs.supported"gt
org.osgi.scalt/propertygt - ltproperty name"org.osgi.sca.bindings"gtht
tp//sampleAddlt/propertygt - lt/service-descriptiongt
-
- lt/service-descriptionsgt
30SCA Domain based service discovery
31Domain Registry for OSGi discovery