This sample is an assembly of Calculator functions implemented in Java and exposed as RMI Services. The primary objective of developing this sample is to support the Calculator-Combo sample. To test this sample you might have to either run the Calculator-Combo sample after running this sample or you might write your won SCA Application that references the services of this sample |
The source for this sample is located in the paths - samples\standalone\calculatorRMIService
of the source
distribution.
If there is binary distribution available for these samples, then you may find these samples packaged as sample-calculator-rmiService.jar.
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.
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\calcualtorRMIService. Within this directory execute the following command
|
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\calculatorRMIService
execute the following command
|
||
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\calculatorRMIService sub-directory:
-
|
Now that the sample source has been built and the Tuscany Standalone Runtime setup, you may run the CalculatorRMIService sample as follows: -
i) | Switch to the samples\standalone\calculatorRMIService\target\distribution
sub-directory and execute the following command:
|
||
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 ********************************************** Calculator Rmi Service Started and Running... *********************************************** Hit ENTER to exit |
||
iii) | This message indicates that the CalculatorRMIServer has been successfully started and is running. | ||
iv) | Whenever a client invokes this RMI Service, the console displays a message about the service method invoked. | ||
v) | Pressing the 'Enter' key will stop the RMI Server and the Tuscany
Standalone Runtime, ending this sample with the following message *********************************************************** Calculator RMI Service Stopped! *********************************************************** |
With the CalculatorRMIService started up and running you may try it out by writing your own RMI Client that can invoke the CalculatorRMIService. The details of the hostname, port and server name which your client should look up is as follows: -
host = | "localhost" |
port = | "9999" |
server name = | "rmiCalculator" |
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 CalculatorRMIService sample and then running this sample.
Note : You may also try the CalculatorRMIService Sample by running the Calculator-Combo sample after running this sample. For details on setting up and running the Calculator-Combo sample look at the readme.html under that sample.
The source files are physically organized as shown below:
Calculator RMI Service +---main |
Calculator RMI Service Sample (Standalone Deployment)
default.scdl | Defines an assembly of calculator funtions implemented in Java and exposed as an RMI Service. |
AddService.java AddServiceImpl.java DivideService.java DivideServiceImpl.java MathService.java MathServiceImpl.java MultiplyService.java MultiplyServiceImpl.java SubtractService.java SubtractServiceImpl.java |
Java Interfaces and Java Implementations for various calculator functions.. |
CalculatorService.java CalculatorServiceImpl.java |
Defines the coarse grained Calculator Interface and Implementation. This calculator implementation delegates function requests to other granular implemenations listed above. |
CalculatorRMIServer | The main method of the RMI Server sample that keeps the runtime up and exits the appplication after the user presses 'Enter' key. |