From
this example you will learn about:
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:
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.
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:
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.
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:
Before you register a server with the same name again, or
terminate the orbixd daemon, you should get rid of
the server:
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.