Distributed OSGi Calculator Sample ================================== This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. The README in the samples directory (the directory above this) provides general instructions about building and running samples. Take a look there first. On Windows, run java -jar ..\..\modules\osgi-3.4.0-v20080605-1900.jar -configuration ..\..\features\configuration -clean -console On *Unix, run java -jar ../../modules/osgi-3.4.0-v20080605-1900.jar -configuration ../../features/configuration -clean -console You should see the osgi console: osgi> osgi> Jun 22, 2009 1:32:27 PM org.apache.tuscany.sca.extensibility.equinox.EquinoxServiceDiscoveryActivator start INFO: Equinox-based service discoverer is now configured. 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-calculator.jar Bundle id is 181 osgi> start 181 Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator start INFO: Starting file:./target/sample-dosgi-calculator.jar [181] Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator start INFO: Registering calculator.dosgi.CalculatorService Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator getBundle INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos gi Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.node.impl.NodeImpl start INFO: Starting node: calculator.dosgi Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.node.impl.NodeFactoryImpl configu reNode INFO: Loading contribution: bundleentry://181/ Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin tRegistry addEndpoint INFO: EndpointRegistry: Add endpoint - Endpoint: URI = CalculatorComponent#serv ice-binding(CalculatorService/CalculatorService) 2009-06-22 13:37:21.953::INFO: jetty-6.1.x 2009-06-22 13:37:21.953::INFO: Started SelectChannelConnector@0.0.0.0:8086 Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.http.jetty.JettyServer addServlet Mapping INFO: Added Servlet mapping: http://rfengt61p:8086/CalculatorService Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin tRegistry addEndpointReference INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc ulatorComponent#reference-binding(addService/addService) Target = Endpoint: Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin tRegistry addEndpointReference INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc ulatorComponent#reference-binding(subtractService/subtractService) Target = Endp oint: Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin tRegistry addEndpointReference INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc ulatorComponent#reference-binding(multiplyService/multiplyService) Target = Endp oint: Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin tRegistry addEndpointReference INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc ulatorComponent#reference-binding(divideService/divideService) Target = Endpoint : osgi> You can point your browser to http://localhost:8086/CalculatorService?wsdl to see the WSDL. You can also use the WebService Explorer from Eclipse WTP to test the Web Service. To stop the bundle: osgi> stop 181 Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.node.impl.NodeImpl stop INFO: Stopping node: calculator.dosgi Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin tRegistry removeEndpoint INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = CalculatorComponent#s ervice-binding(CalculatorService/CalculatorService) Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.http.jetty.JettyServer removeServ letMapping INFO: Removed Servlet mapping: /CalculatorService Jun 22, 2009 1:39:09 PM calculator.dosgi.impl.CalculatorActivator stop INFO: Stopping file:./target/sample-dosgi-calculator.jar [181] 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 “add”, “subtract”, “multiply” and “divide” operations. * The operations bundle: It provides the add/subtract/multiply/divide services. (See ../samples/dosgi-calculator-operations) dosgi-calculator/ src/ main/ java/ calculator/ dosgi/ CalculatorService.java - The interface for Calculator service impl/ CalculatorActivator.java - OSGi bundle activator for Calculator bundle CalculatorServiceDSImpl.java - OSGi declarative service based implementation CalculatorServiceImpl.java - Basic OSGi implementation operations/ AddService.java - Interface for Add SubtractService.java - Interface for Subtract MultiplyService.java - Interface for Multiply DivideService.java - Interface for Divide rmi/ OperationsRemote.java - RMI remote interface for operations OperationsRMIServer_Stub.java - RMI stub OperationsRMIServer.java - RMI server implementation of the operations resources/ META-INF/ sca-contribution.xml OSGI-INF/ sca/ bundle.componentType - The component type for implementation.osgi of this bundle bundle.composite - The composite file test/ java/ src/ calculator/ dosgi/ test/ CalculatorOSGiNodeTestCase.java - The JUNIT test case that tests this bundle against a RMI service META-INF/ MANIFEST.MF - The OSGi manifest for this bundle dosig-calculator.png - a pictorial representation of the sample 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-calculator mvn