
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@998924 13f79535-47bb-0310-9956-ffa450edef68
196 lines
8.8 KiB
Text
196 lines
8.8 KiB
Text
Distributed OSGi Calculator Sample
|
||
==================================
|
||
This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA.
|
||
|
||
The README in the <distribution-unpack-dir>/samples directory provides
|
||
general instructions about building and running samples. (where
|
||
distribution-unpack-dir is the directory in which you unpacked the tuscany
|
||
binary distribution archive). Take a look there first (noting at you read it that this sample
|
||
is not a new style sample).
|
||
|
||
On Windows, run
|
||
java -jar ..\..\modules\osgi-3.5.0-v20090520.jar -configuration ..\..\features\configuration -clean -console
|
||
|
||
On *Unix, run
|
||
java -jar ../../modules/osgi-3.5.0-v20090520.jar -configuration ../../features/configuration -clean -console
|
||
|
||
You should see the osgi console:
|
||
|
||
osgi>
|
||
|
||
You can run "ss" command under the osgi> to see the status of the bundles.
|
||
osgi> ss
|
||
|
||
Then you can install and start the calculator.dosgi bundle:
|
||
|
||
osgi> install file:./target/sample-dosgi-dynamic-calculator-operations.jar
|
||
Bundle id is 198
|
||
|
||
osgi> start 198
|
||
Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star
|
||
t
|
||
INFO: Starting calculator.dosgi.dynamic.operations_1.0.0 [198]
|
||
Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star
|
||
t
|
||
INFO: Registering calculator.dosgi.operations.AddService
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.node.impl.NodeImpl start
|
||
INFO: Starting node: urn:osgi.service.d3cadb93-e9b9-4486-87eb-07ece11888f6 domai
|
||
n: tuscany.apache.org
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe
|
||
rvice
|
||
INFO: RMI service registered: rmi://localhost:8085/AddService
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr
|
||
yImpl addEndpoint
|
||
INFO: Add endpoint - (@8144744)Endpoint: URI = osgi.service.d3cadb93-e9b9-4486-
|
||
87eb-07ece11888f6#service-binding(AddService/Add)
|
||
Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star
|
||
t
|
||
INFO: Registering calculator.dosgi.operations.SubtractService
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.node.impl.NodeImpl start
|
||
INFO: Starting node: urn:osgi.service.b6259ccc-6ae4-41f0-b61b-c5a8c7f42b35 domai
|
||
n: tuscany.apache.org
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe
|
||
rvice
|
||
INFO: RMI service registered: rmi://localhost:8085/SubtractService
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr
|
||
yImpl addEndpoint
|
||
INFO: Add endpoint - (@30229114)Endpoint: URI = osgi.service.b6259ccc-6ae4-41f0
|
||
-b61b-c5a8c7f42b35#service-binding(SubtractService/Subtract)
|
||
Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star
|
||
t
|
||
INFO: Registering calculator.dosgi.operations.MultiplyService
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.node.impl.NodeImpl start
|
||
INFO: Starting node: urn:osgi.service.8469c64c-9a28-47b3-bc4a-c5fa8d471057 domai
|
||
n: tuscany.apache.org
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe
|
||
rvice
|
||
INFO: RMI service registered: rmi://localhost:8085/MultiplyService
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr
|
||
yImpl addEndpoint
|
||
INFO: Add endpoint - (@3312704)Endpoint: URI = osgi.service.8469c64c-9a28-47b3-
|
||
bc4a-c5fa8d471057#service-binding(MultiplyService/Multiply)
|
||
Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star
|
||
t
|
||
INFO: Registering calculator.dosgi.operations.DivideService
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.node.impl.NodeImpl start
|
||
INFO: Starting node: urn:osgi.service.b43555f0-9509-444e-b22a-06d347ab7e98 domai
|
||
n: tuscany.apache.org
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe
|
||
rvice
|
||
INFO: RMI service registered: rmi://localhost:8085/DivideService
|
||
Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr
|
||
yImpl addEndpoint
|
||
INFO: Add endpoint - (@8010288)Endpoint: URI = osgi.service.b43555f0-9509-444e-
|
||
b22a-06d347ab7e98#service-binding(DivideService/Divide)
|
||
Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator getB
|
||
undle
|
||
INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos
|
||
gi.dynamic.operations
|
||
|
||
osgi>
|
||
|
||
To stop the bundle:
|
||
|
||
osgi> stop 198
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop
|
||
INFO: Stopping node: urn:osgi.service.b43555f0-9509-444e-b22a-06d347ab7e98
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr
|
||
yImpl endpointRemoved
|
||
INFO: Remove endpoint - (@8010288)Endpoint: URI = osgi.service.b43555f0-9509-44
|
||
4e-b22a-06d347ab7e98#service-binding(DivideService/Divide)
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister
|
||
Service
|
||
INFO: RMI service unregistered: rmi://localhost:8085/DivideService
|
||
Nov 4, 2009 5:18:43 PM calculator.dosgi.operations.impl.OperationsActivator stop
|
||
|
||
INFO: Stopping calculator.dosgi.dynamic.operations_1.0.0 [198]
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop
|
||
INFO: Stopping node: urn:osgi.service.d3cadb93-e9b9-4486-87eb-07ece11888f6
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr
|
||
yImpl endpointRemoved
|
||
INFO: Remove endpoint - (@8144744)Endpoint: URI = osgi.service.d3cadb93-e9b9-44
|
||
86-87eb-07ece11888f6#service-binding(AddService/Add)
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister
|
||
Service
|
||
INFO: RMI service unregistered: rmi://localhost:8085/AddService
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop
|
||
INFO: Stopping node: urn:osgi.service.b6259ccc-6ae4-41f0-b61b-c5a8c7f42b35
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr
|
||
yImpl endpointRemoved
|
||
INFO: Remove endpoint - (@30229114)Endpoint: URI = osgi.service.b6259ccc-6ae4-4
|
||
1f0-b61b-c5a8c7f42b35#service-binding(SubtractService/Subtract)
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister
|
||
Service
|
||
INFO: RMI service unregistered: rmi://localhost:8085/SubtractService
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop
|
||
INFO: Stopping node: urn:osgi.service.8469c64c-9a28-47b3-bc4a-c5fa8d471057
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr
|
||
yImpl endpointRemoved
|
||
INFO: Remove endpoint - (@3312704)Endpoint: URI = osgi.service.8469c64c-9a28-47
|
||
b3-bc4a-c5fa8d471057#service-binding(MultiplyService/Multiply)
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister
|
||
Service
|
||
INFO: RMI service unregistered: rmi://localhost:8085/MultiplyService
|
||
Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop
|
||
INFO: Stopping node: urn:osgi.service.b43555f0-9509-444e-b22a-06d347ab7e98
|
||
|
||
osgi>
|
||
|
||
To exit the console, run:
|
||
osgi> exit
|
||
|
||
Sample Overview
|
||
---------------
|
||
The application consists of two OSGi bundles:
|
||
* The calculator bundle: It provides the calculator service. The service is implemented by a java class that
|
||
consumes other services to perform the <20>add<64>, <20>subtract<63>, <20>multiply<6C> and <20>divide<64> operations.
|
||
* The operations bundle: It provides the add/subtract/multiply/divide services.
|
||
(See ../samples/dosgi-dynamic-calculator-operations)
|
||
|
||
|
||
dosgi-dynamic-calculator-operations/
|
||
src/
|
||
main/
|
||
java/
|
||
calculator/
|
||
dosgi/
|
||
operations/
|
||
AddService.java - Interface for Add
|
||
SubtractService.java - Interface for Subtract
|
||
MultiplyService.java - Interface for Multiply
|
||
DivideService.java - Interface for Divide
|
||
impl/
|
||
OperationsActivator.java - OSGi bundle activator
|
||
AddServiceImpl.java - Implementation for Add
|
||
SubtractServiceImpl.java - Implementation for Subtract
|
||
MultiplyServiceImpl.java - Implementation for Multiply
|
||
DivideServiceImpl.java - Implementation for Divide
|
||
resources/
|
||
META-INF/
|
||
sca-contribution.xml
|
||
OSGI-INF/
|
||
sca-config/
|
||
operations-config.xml - The SCA configuration file for OSGi remote services
|
||
test/
|
||
java/
|
||
src/
|
||
calculator/
|
||
dosgi/
|
||
operations/
|
||
test/
|
||
OperationsOSGiNodeTestCase.java - The JUNIT test case that tests this bundle using a RMI client
|
||
|
||
META-INF/
|
||
MANIFEST.MF - The OSGi manifest for this bundle
|
||
pom.xml - the Maven build file
|
||
|
||
|
||
|
||
Building And Running The Test Case Using Maven
|
||
-------------------------------------------
|
||
With either the binary or source distributions the sample can be built and run
|
||
using Maven as follows.
|
||
|
||
cd dosgi-dynamic-calculator-operations
|
||
mvn
|
||
|