Tuscany HelloWorld - RMI Service Sample

Overview

The RMI Service sample demonstrates how the Tuscany Runtime can be used to host service components as RMI Services without the need to make any modifications to the service interfaces.

Location

The source for this sample is located  in the paths - samples\standalone\helloworldRMIService of the source distribution.

If there is binary distribution available for these samples, then you may find these samples packaged as sample-helloworld-rmiService.jar.

Building & Running the HelloWorldRMIService Sample Source

If you are working with a source distribution, then you must first build the source of this sample.
- Ensure that you have Java 5 installed on your system.
- Next, you must have Maven 2.0.4 installed on your system. Look up http://maven.apache.org/download.html for downloading and installing Maven.

Building the HelloWorldRMIService Sample

Having installed Maven, open a command line console and switch over to the directory on your local system, where you have extracted the source.
- Now switch futher into the subdirectory samples\standalone\helloworldRMIService. Within this directory execute the following command
> mvn
This will build the helloworldRMIService sample, package a JAR file for the composite and make it available in the sub-directory samples\standalone\helloworldRMIService/target

Setting up Tuscany Standalone Runtime

To run these samples you need the Tuscany Standalone Runtime. This is available as a distribution that can be conveniently unpacked and setup in the samples directory itself. For this, do the following: -

i) From the directory samples\standalone\helloworldRMIService execute the following command
> mvn dependency:unpack
This will unpack the Tuscany Standalone Runtime Distribution to the target\distribution sub-directory within the present working directory - samples\standalone\helloworldRMIService
ii) Since this sample would require the RMI Binding Extension of Tuscany you must copy the RMI Extension JAR from the contrib sub-directory into the extensions directory of the distribution. ie. execute the following from the samples\standalone\helloworldRMIService sub-directory: -
> copy target\distribution\contrib\rmi-1.0-incubator-M2.jar target\distribution\extensions\rmi-1.0-incubator-M2.jar
Note : If you are working with SNAPSHOTs versions of Tuscany Extensions then the file rmi-1.0-incubator-M2.jar in the above command must be substituted with rmi-1.0-incubator-M2-SNAPSHOT.jar


Running the HelloWorldRMIService Sample

Now that the sample source has been built and the Tuscany Standalone Runtime setup, you may run the HelloWorldRMIService sample as follows: -

i) Switch to the samples\standalone\helloworldRMIService\target\distribution sub-directory and execute the following command:
> java -jar bin\launcher.jar ..\sample-helloworld-rmiService.jar
ii) You will initially observe messages that relate to resolution of dependencies required to run this sample and finlly see the following message on your console
***********************************************************
Helloworld RMI Service Started and Running...
***********************************************************
Hit ENTER to exit
iii) This message indicates that the HelloWorldRMIServer has been successfully started and is running.
iv) For every client invocation, you will see a message "Saying Hello to - <name>" that is displayed
v) Pressing the 'Enter' key will stop the RMI Server and the Tuscany Standalone Runtime, ending this sample with the following message
***********************************************************
Server Stopped!
***********************************************************


Trying the HelloWorldRMIService Sample

With the HelloWorldRMIService started up and running you may try it out by writing your own RMI Client that can invoke the HelloWorldRMIService. The details of the hostname, port and server name which your client should look up is as follows: -

host = "localhost"
port = "1099"
server name = "HelloWorldRemoteService"

Note: You are free to modify any of the above (host, port, server name) by making corresponding modifications to the default.scdl file of the HelloWorldRMIService sample and then running this sample.

Note : You may also try the HelloWorldRMIService Sample by running the HelloWorldRMIReference Sample.

Code Overview

The source files are physically organized as shown below:
RMI Service Sample
+---main
+---java
| +---helloworld HelloWorldService.java HelloWorldImpl.java HelloWorldRmiServer.java +---resources +----META-INF +----sca default.scdl


RMI Service Sample

default.scdl Defines the assembly of the Helloworld Server Application with the HelloWorldImpl component defined to be hosted as an RMI Service under the covers of the SCA Runtime. You will never notice any APIs in java.rmi.*
HelloWorldService.java Defines a HelloWorld service interface
HelloWorldImpl.java Implements the HelloWorldService interface
HelloWorldRmiServer.java Launches the Standalone Tuscany Runtime with the RMI Server SCA Application loaded and running