CORBA Example
Purpose
From this example you will learn about:
- Basic Client/Server programming with
- Simple experiment for concurrency control
Description
You will develop a client/server application with CORBA and Java. The server acts like a bank: it maintains two accounts X and Y, both having some nonzero initial values. The client may read X and Y from the server, and perform a transfer between the two accounts. The server is registered in the Implementation Repository for an Orbix daemon, and the client is supposed to be able to communicate with the server wherever the client is running.
The client should be implemented as an Java applet. It should have at least four text fields for displaying X, Y, their sum, and the amount for transfer. It should have labels indicating what each textfield is displaying. It should have at least three buttons: one is to read X and Y from the server, calculate their sum, and display them in the corresponding textfields; one is to send a request to the server for transferring the specified amount from account X to Y; the third one is for transferring from account Y to X. You are free to add more items, like the button for 'Quit', textfields and button letting the user specify the server name and its host name before making connections, etc.
The server should maintain two data items X and Y. Just to be simple, X, Y and the transfer amount can be always integer. It should provide methods which can be called remotely by the client to read X and Y and perform transfers. However, we want to introduce concurrency control problems into transfers, each of which is regarded as a transaction. In the server's method(s) for transfer, the server should not perform the transfer directly, instead, it must create a thread which handles the transfer as a transaction. The thread should get the amount to transfer from its parent when it is created, then it should perform the following operations on X and Y (if the transfer is from X to Y):
Read(X)
Read(Y)
X = X - transferAmount; Y = Y + transferAmount;
Write(X)
Write(Y)
To allow the user to control the execution of the operations, the thread should generate a window which is a Java frame. In this window, there is a textfield displaying the next operation to be executed, and a button 'Next' for executing the next operation. So the execution of the thread should be as follows:
- Open up a frame
- display 'Read(X)' in the textfield
- wait for the user to click button 'Next'...
- read X from the server
- display 'Read(Y)'
- wait for the user to click button 'Next'...
- read Y from the server
- display 'Write(X)'
- wait for the user to click button 'Next'...
- compute X = X - transferAmount; Y = Y + transferAmount;
- write X to the server
- display 'Write(Y)'
- wait for the user to click button 'Next'...
- write Y to the server
- close the frame and exit
It is not necessary to display the read or written value of X or Y in the window.
The thread and its methods should NOT be synchronized. Clearly, while two clients are running at the same time, the transactions they execute may be interleaved if the user deliberately manages the execution of their operations. Thus inconsistency resulted from various violations of concurrency control may appear, which is reflected by the change of the sum of X and Y when a client performs another read after the execution of the transactions.
On-line Help
- You should go to OrbixWeb Programming Guide, and read its first three chapters very carefully.
- To learn about the software and how to use the related commands, you may want to visit OrbixWeb Reference Guide.
- To learn about Java thread programming, you may visit Doing Two or More Tasks At Once: Threads.
Guidelines
- The CORBA software we will use is OrbixWeb from Iona Technologies. Because the OrbixWeb software we have is only for SUN systems, you can not work on Pentium based Xinu machines. You should work on cybil.cs, a SUN machine chosen particularly for the project. cybil shares the same file system as Xinu machines do, and everyone can login this machine with his or her Xinu account name and password. I recommend you not to work on the SUN machines in your own departments or in ENAD labs, because: it would be your own responsibility to copy the software from our department, which might be disallowed, and to change the configuration.
- Installation of OrbixWeb
In order to avoid the conflicts of different students' work on the same
machine, everyone should run his or her own Orbix
daemon, but on a different port. This means that everyone should install some
part of the software, which can be configured for running Orbix
daemon on different ports. You should follow the following steps exactly in
order:
- Set or update some environment variables:
- To download theOrbixWeb software to your account:
- Configure yourOrbixWeb so that your daemon can be run on a different port:
- Now yourOrbixWeb is ready for use. Try
setenv IT_CONFIG_PATH $HOME/OrbixWeb
setenv CLASSPATH .:$HOME/OrbixWeb/classes
set path = ($path /p/OrbixWeb/bin)
setenv MANPATH /p/OrbixWeb/man:$MANPATH
If your MANPATH
was undefined, you should replace the last line with
setenv MANPATH /$HOME/OrbixWeb/man
It is recommended to put the commands above into your .cshrc file.
tar -xvf /u/u29/cs542/CS542_OrbixWeb.tar
The extracted files will be in directory ~/OrbixWeb/. Do not change the directory name.
Open the file ${ORBIXWEB}/Orbix.cfg and change the
values of IT_IIOP_PORT, IT_DAEMON_PORT, IT_DAEMON_SERVER_BASE to some unique
numbers, which should be larger than 1024, of course.
Also, change the corresponding port numbers in ${ORBIXWEB}/java/Configure.java.
Also, change this particular linein the same file
'_CORBA.IT_BIND_USING_IIOP = true;' to '_CORBA.IT_BIND_USING_IIOP = false'.
Type make in the same directory.
Change all the path dependencies in the examples
and Makefiles.
Change /.eros-8/p5/OrbixWeb2.0.1 to ${HOME}/OrbixWeb whereever it is
necessary.
orbixd &
to run the Orbix daemon and see if it works.
- I highly recommend you to read on-line document very carefully and try the demo programs it provides before you write your own programs.
You should go to OrbixWeb Programming Guide, and read its first three chapters very carefully.
The demo for Chapter 2: Getting Started with Java
Applications is now in your directory ~/OrbixWeb/demos/grid
The demo for Chapter 3: Getting Started with Java
Applets is now in your directory ~/OrbixWeb/demos/gridApplets
To try the demos, you just need to change your current directory to the
corresponding demo directory, type
make
The demo programs will be compiled, and at the end it will tell you how to use it. Basically, you should:
- runorbixd & if you have not.
- Register the server in the implementation repository with command putit
- usechmodit to allow other users to access the server
- Run the client from the command line if it is a application, or typeappletviewer index.html if it is an applet.
Before you register a server with the same name again, or terminate the orbixd daemon, you should get rid of the server:
- Kill the activated server with command
- remove its registration entry from the implementation repository with command
killit servername
rmit servername
You may use commands lsit, catit, and psit to know more about the server and the implementation repository. To learn more about these commands, you may visit OrbixWeb Reference Guide, or simply check its manual by typing man putit, for instance.
I recommend you to study the demo gridApplet thoroughly, take it as the basis for your project, and use similar directory structures and almost the same Makefile. The only things you may want to change in the Makefile are the server name and the package name.