Tuscany HelloWorld - RMI Reference Sample

Overview

The RMI Reference sample demonstrates how the Tuscany Runtime provides RMI client bindings for service components that would like to refer RMI Servcies.

Location

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

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

Building & Running the HelloWorldRMIReference 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 HelloWorldRMIReference 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\helloworldRMIReference. In this directory execute the following command
> mvn
This will build the helloworldRMIReference sample, package a JAR file for the composite and make this available in sub-directory samples\standalone\helloworldRMIReference\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\helloworldRMIReference 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\helloworldRMIReference
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\helloworldRMIReference 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 HelloWorldRMIReference Sample

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

i) First ensure that the HelloWorldRMIService Sample is up and running.
ii) Switch to the samples\standalone\helloworldRMIReference\target\distribution sub-directory and execute the following command:
> java -jar bin\launcher.jar ..\sample-helloworld-rmiReference.jar
iii) Running this sample will send a 'sayHello' request to the HelloWorldRMIService (that must be running) with the argument 'name' set to the string "SCA RMI Client"
iii) 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
***********************************************************
Hello SCA RMI Client - from the SCA RMI Service
***********************************************************
iv) This message indicates that the HelloWorldRMIReference sample has successfuly invoked the HelloWorldRMIService and obtained the string value "Hello SCA RMI Client - from the SCA RMI Service"
v) Meanwhile, on the console where you have started the HelloworldRMIService sample you will see a message "Saying Hello to - SCA RMI Client" that is displayed (implying that its service method was invoked)

Note : You may also try the HelloWorldRMIReference Sample by creating your own RMI Server with the following attributes

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 HelloWorldRMIReference sample and then running this sample.

Code Overview

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


RMI Reference Sample

default.scdl Defines the assembly of the Helloworld Application with the HelloWorldImpl component referring the a HelloWorld RMI Service
HelloWorldService.java Defines a HelloWorld service interface
HelloWorldImpl.java Implements the HelloWorldService interface. This implementation inturn calls out to the RMI Service under the covers of the SCA Runtime - i.e. you will never notice any APIs in java.rmi.* used in this application
HelloWorldRmiClient.java Launches the Standalone Tuscany Runtime with the RMI Client SCA Application loaded and run.