summaryrefslogtreecommitdiffstats
path: root/sandbox/sebastien/java/sca-node/samples/calculator-rmi-service/README
blob: 454cdc0d37508ecbb170b7ad64bc593392037677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Calculator RMI Service Sample
=============================

This sample illustrates the use of Tuscany RMI Binding to expose component 
services as Java RMI Services. It also demonstrates how a simple Java RMI 
Client application invokes the SCA Application's services exposed as RMI 
Services.

The README in the samples directory (the directory above this) provides 
general instructions about building and running samples. Take a look there 
first. 

If you just want to run it to see what happens open a command prompt, navigate
to this sample directory and do:

ant run

OR if you don't have ant, on Windows do

java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-rmi-service.jar calculator.CalculatorServer

and on *nix do

java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator-rmi-service.jar calculator.CalculatorServer

Now you have the server running you need to open another command prompt, navigate
to the calculator-rmi-reference sample directory and do:

ant run

OR if you don't have ant, on Windows do

java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-rmi-reference.jar calculator.CalculatorClient

and on *nix do

java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator-rmi-reference.jar calculator.CalculatorClient


Sample Overview
---------------
This sample extends the calculator sample by replacing the local service 
binding with an RMI binding. SO a java client can call the service exposed
by the SCA application using an RMI client.

This sample adds a number of classes to the basic calculator sample:

calculator-rmi-service/
  src/
    main/
      java/
        calculator/
          CalculatorService.java  - as calculator sample
          CalculatorServiceImpl.java
          AddService.java         - as calculator sample
          AddServiceImpl.java
          SubtractService.java    - as calculator sample
          SubtractServiceImpl.java
          MultiplyService.java    - as calculator sample
          MultiplyServiceImpl.java
          DivideService.java      - as calculator sample
          DivideServiceImpl.java
          CalculatorClient.java   - (Not currently used) Uses the
                                    java naming service to
                                    look up the Calculator RMI service.
                                    It then calls add, subtract, multiple
                                    and divide methods on the service
          CalculatorServer.java   - starts the SCA Runtime and deploys 
                                    the CalculatorRMIServer.composite. 
                                    In doing this the SCA RMI binding
                                    acts to expose the CalculatorService
                                    over RMI.
      resources/
        CalculatorRMIServer.composite - the SCA assembly for this sample
    test/
      java/
        calculator/
          CalculatorRMIServerTestCase.java - JUnit test case
  calculator-rmi-service.png     - a pictorial representation of the 
                                    .composite file
  build.xml                       - the Ant build file for the server
  pom.xml                         - the Maven build file   
  
Note. As this test creates and uses local network connections you may need to 
configure your firewall, if you are running one, to allow the test to run
successfully.         

Building And Running The Sample Using Ant
-----------------------------------------
With the binary distribution the sample can be built and run using Ant. Two 
build files are used to support client and server functions. 

The server starts the SCA runtime and loads the SCA calculator application 
which exposes an RMI service. Start a new console and use the following 
commands.

cd calculator-rmi-service
ant compile
ant run

This will run up the server and display the following.

run:
     [java] Starting of the SCA Calculator Application exposed as RMI Services... 
     [java] ...Press Enter to Exit...
     
The client is very similar to the calculator sample

It locates the RMI service that the SCA runtime is exposing and calls each of 
the calculator operations. Start a new console and use the following commands. 

cd calculator-rmi-reference
ant compile
ant run

You should see the following output from the run target.

run:
     [java] 3 + 2=5.0
     [java] 3 - 2=1.0
     [java] 3 * 2=6.0
     [java] 3 / 2=1.5
     
If you now return to the console window running the server and press enter the 
server should stop.     

Building And Running The Sample Using Maven 
-------------------------------------------
With either the binary or source distributions the sample can be built and run 
using Maven as follows. 

cd calculator-rmi-service
mvn

You should see the following output from the test phase.

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running calculator.CalculatorRMIServerTestCase
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.819 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

This shows that the Junit test cases have run successfully.