Lab 4 - Get started with CORBA.
Resources:
Lab assignment: (graded, 2p): Implement a simple calculator using
CORBA. Since CORBA is about communication between distributed objects, you'll
need to implement a server and a client. The server should know how to add,
subtract, multiply and divide two numbers. The client will get two numbers and
an operator (specified through a character: '+', '-', '*', or '/') as command
line arguments, send them to the server, and print the result returned by
server. (Note: to pass '*' as a command line argument you need
to use quotes to prevent the shell to use it for filename substitution.)
Due date: April 25, 11:59pm
Hand in to: the TA's (ta-51024@cs.uchicago.edu) via gzipped
tarball, to include:
- Server.java
- Client.java
- Calculator.idl
- CalcInterfaceImpl.java
- Makefile
(You can call these files whatever you like: the above are suggestions.)
To complete this assignment, you might find these steps useful:
- Do the following in your home directory:
cd visibroker/examples/basic/bank_agent
- Look at the example. Compile it using the Makefile provided (run 'make java'). Observe which files are generated automatically by the IDL compiler. Run the example.
- Write the IDL file for your program. (Hint: you may wish to organize this
lab in a new sub-directory rather than in examples. Consider creating one in
a bank_agent folder.) Look here
for the Bank example.
You probably need only one interface (let's name it
CalcInterface) with only one method (let's say calc) which takes
as arguments 2 numbers (the operands) and a character (the operator) in
{'+', '-', '*', '/'}.
- Generate client stub and server skeleton using the IDL compiler
(idl2java).
- Implement the server. This means writing two files: Server.java (to
start the server and instantiate the ORB) and CalcInterfaceImpl.java
(if you named the interface CalcInterface in the IDL file, to actually
implement the server's services).
- Implement the client. The client should read the operands and the operator
from the input, ask the server to compute the result and print the result.
- Compile. You might want to look on this Makefile
for the Bank example, understand it and adapt it.
- Time now for more conflicts ... To make sure that the service you call is
yours (perfectly working, obviously) and not the buggy service of one of your
colleagues, make sure the instance name of the service provided by your server
is unique. For example, in Server.java and Client.java you can
personalize your POA name using your name or other information which is
unlikely to be used by others:
POA myPOA = rootPOA.create_POA(
"Matei_bank_agent_poa", rootPOA.the_POAManager(), policies
);
- Check if there is an osagent running on your machine. You do this
with:
ps aux | grep
osagent
To find osagent running in the same local network you can use VisiBroker's
console:
console.sh
If you do not find any osagent running on the local machine or on the local
network you might start one with:
osagent -v &
(-v stands for
verbose, you'll see diagnostic info that might be helpful).
Also, osagent can be specified to run on a particular port instead of the
default. That can be done setting the environment variable OSAGENT_PORT
(default is 14000) and the -DOSAgentPortAddr flag I think passed to each
server and client at runtime.
Make sure you understand what is the purpose of the OSAGENT_PORT
variable from your environment and why you shouldn't need to start an
osagent on your local host (IF there is one running on the local
network).
- To run the server:
vbj Server
- Run the client with:
vbj Client
ta-51024@cs.uchicago.edu